【问题标题】:Webots: How to restore robot state in webots?Webots:如何在 webbots 中恢复机器人状态?
【发布时间】:2020-09-15 01:46:51
【问题描述】:

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

【问题讨论】:

    标签: webots


    【解决方案1】:

    有很多方法可以重置模拟状态,您可以在这里找到这些各种可能性的完整介绍: 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 这样的主管控制器的结果
    • 推出轨迹并使用``` wb_supervisor_field_set_sf_float(ankleField, x0(1)); wb_supervisor_field_set_sf_float(kneeField, x0(2)); wb_supervisor_simulation_reset_physics(); wb_supervisor_node_set_velocity(小牛,X0_absCalfVel); wb_supervisor_node_set_velocity(大腿,X0_absThighVel);对于 i=1:N wb_motor_set_torque(ankle, u(1,i)); wb_motor_set_torque(膝盖,u(2,i)); wb_robot_step(TIME_STEP); x(:, i+1) = get_state(); end ``` 以先设置状态和不恢复状态以推出轨迹不同。
    • 抱歉评论,我对markdown不熟悉
    • 您能否将代码发布到gist.github.compastebin.com 并分享链接。这样会更易读。
    • 是的,link。基本思路
    猜你喜欢
    • 2023-03-17
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多