【发布时间】:2020-09-15 01:46:51
【问题描述】:
我想恢复状态(包括机器人中每个实体节点的位置和速度)。我尝试使用主管控制器 API 获取和设置节点的字段来设置位置,并使用 wb_supervisor_node_get_velocity 和 wb_supervisor_node_set_velocity 来设置速度。但是我发现使用控制循环和通过上面的API将中间状态复制到机器人后设置扭矩的结果是不同的。我该怎么做才能纠正这个问题?
【问题讨论】:
标签: webots
我想恢复状态(包括机器人中每个实体节点的位置和速度)。我尝试使用主管控制器 API 获取和设置节点的字段来设置位置,并使用 wb_supervisor_node_get_velocity 和 wb_supervisor_node_set_velocity 来设置速度。但是我发现使用控制循环和通过上面的API将中间状态复制到机器人后设置扭矩的结果是不同的。我该怎么做才能纠正这个问题?
【问题讨论】:
标签: webots
有很多方法可以重置模拟状态,您可以在这里找到这些各种可能性的完整介绍: 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, 0, 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);
【讨论】:
x = zeros(n, N); x = zeros(n ,N); x(:,1) = x0; for i=1:N wb_supervisor_field_set_sf_float(ankleField, x(1,i)); wb_supervisor_field_set_sf_float(kneeField, x(2,i)); wb_supervisor_simulation_reset_physics(); wb_supervisor_node_set_velocity(calf, absCalfVel); wb_supervisor_node_set_velocity(thigh, absThighVel); wb_motor_set_torque(ankle, u(1,i)); wb_motor_set_torque(knee, u(2,i)); wb_robot_step(TIME_STEP); x(:, i+1) = get_state(); end % get_state() is some function to get the current x 这样的主管控制器的结果