- Failed to fetch current robot state
当在程序中使用move_group.getCurrentJointValues()获取当前机器人的关节值时,程序执行到move_group.getCurrentJointValues()时,就会有如下报警。
Didn't received robot state (joint angles) with recent timestamp within 1 seconds.
Check clock synchronization if your are running ROS across multiple machines!
[ERROR] [1610024438.211652653]: Failed to fetch current robot state
原因分析:
在1s的时间内,没有等到robot state的更新。
通过对报警信息的分析,发现函数调用关系为:move_group.getCurrentJointValues() → move_group_interface.cpp/getCurrentState() /current_state_monitor_->waitForCurrentState() → current_state_monitor.cpp/planning_scene_monitor::CurrentStateMonitor::waitForCurrentState(),报警直接原因是函数waitForCurrentState()中while循环条件一直满足,使得while内部处理满足异常条件,导致报警。
继续分析发现while循环条件中的current_state_time_值始终没有更新,进一步分析发现更新current_state_time_值的回调函数current_state_monitor.cpp/jointStateCallback() 没有被调用到,而该回调函数current_state_monitor.cpp/jointStateCallback()是通过订阅 topic /joint_states (<sensor_msgs::JointState>)实现的,而本人在使用函数move_group.getCurrentJointValues()过程前后,系统并没有发布topic /joint_states。
解决方案:
专门创建一个节点或一个线程来发布topic /joint_states,类似于节点joint_state_publisher的功能,本人是专门创建一个线程定周期发布 /joint_states。
补充:
当时考虑到一个问题,系统为什么需要订阅topic /joint_states?
个人想到一个解释(不一定正确),move_group.getCurrentJointValues()获取的信息属于机器人状态(robot state)。对于机器人系统而言,一切状态源于各关节轴的实际关节值,因此要想获取机器人的某些状态(笛卡尔位姿等),需要先知道关节状态,因此需要订阅topic /joint_states,所以需要有线程和节点来发布该topic。