Rviz中/joint_states不更新,机器人轮子无动作问题求助
你的问题核心是RViz无法获取轮子关节的状态更新,导致轮子无动作且出现滑移,以下是具体修复方案:
1. 移除冲突的joint_state_publisher节点
你同时启动了joint_state_publisher和通过controller_manager加载的joint_state_controller,这两个节点都会发布/joint_states话题,造成冲突。删除launch文件中这段代码:
<!-- Publishing joint state --> <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher" > <remap from="joint_state_publisher" to ="joint_states" /> </node>
joint_state_controller会从Gazebo获取所有关节的状态并发布,不需要额外的joint_state_publisher。
2. 修正robot_state_publisher的时间同步参数
Gazebo仿真使用仿真时间,必须将robot_state_publisher的use_sim_time设为true,否则RViz会因为时间不同步无法正确更新关节状态。修改对应节点配置:
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" > <param name="use_sim_time" value="true"/> </node>
3. 确保URDF中轮子关节的transmission配置
Gazebo的ros_control需要通过transmission标签关联关节和控制器,才能读取关节状态。在URDF中为每个轮子关节添加类似配置:
<transmission name="wheel_j1_trans"> <type>transmission_interface/SimpleTransmission</type> <joint name="wheel_j1"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> </joint> <actuator name="wheel_j1_motor"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission>
重复此配置给wheel_j2、wheel_j3、wheel_j4,确保关节名称和URDF中的一致。
4. 检查URDF中的Gazebo ros_control插件
确保URDF包含Gazebo ros_control插件的加载配置,让Gazebo能和控制器通信:
<gazebo> <plugin name="ros_control" filename="libgazebo_ros_control.so"> <robotNamespace>/my_robot</robotNamespace> </plugin> </gazebo>
5. 验证关节状态话题的订阅
你的joint_state_controller配置在my_robot命名空间下,会发布/my_robot/joint_states话题,需要让robot_state_publisher订阅这个话题。在robot_state_publisher节点中添加重映射:
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" > <param name="use_sim_time" value="true"/> <remap from="joint_states" to="/my_robot/joint_states"/> </node>
6. 重启并验证
修改完成后重启launch文件,执行rostopic echo /my_robot/joint_states,检查wheel_j1到wheel_j4的关节状态是否正常更新。此时RViz中的轮子应该会跟随Gazebo中的动作同步运动,滑移现象也会消失。
内容的提问来源于stack exchange,提问作者Mubashir

