Webots:如何在Webots中恢复机器人状态?

问题描述

我想恢复状态(包括机器人中每个实体节点的位置和速度)。我尝试使用主管控制器API来获取和设置节点的字段以设置位置,并尝试使用wb_supervisor_node_get_velocity和wb_supervisor_node_set_velocity来设置速度。但是我发现通过上述API将中间状态复制到机器人后,使用控制环和设置转矩之间的结果是不同的。我该怎么做才能纠正这个问题?

解决方法

有许多种方法可以重置模拟状态,您将在这里找到各种可能性的完整介绍: https://cyberbotics.com/doc/guide/using-numerical-optimization-methods#resetting-the-robot

特别是,第一个解决方案看起来与您要执行的操作完全一样:

// get handles to the robot's translation and rotation fields
WbNodeRef robot_node = wb_supervisor_node_get_from_def("MY_ROBOT");
WbFieldRef trans_field = wb_supervisor_node_get_field(robot_node,"translation");
WbFieldRef rot_field = wb_supervisor_node_get_field(robot_node,"rotation");

// reset the robot
const double INITIAL_TRANS[3] = { 0,0.5,0 };
const double INITIAL_ROT[4] = { 0,1,1.5708 };
wb_supervisor_field_set_sf_vec3f(trans_field,INITIAL_TRANS);
wb_supervisor_field_set_sf_rotation(rot_field,INITIAL_ROT);
wb_supervisor_node_reset_physics(robot_node);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...