Skip to content

Commit 566ffee

Browse files
author
sebastian zarnack
committed
fixed moveit_servo to work with fake_hardware (fixes issue #3040)
The planning scene monitor may use a different clock type (e.g., system clock) than the servo node (ROS clock), causing timestamp comparison failures that prevented servo from starting properly with fake_hardware controllers. --> Add convertClockType() helper function to handle clock type conversions
1 parent 950322e commit 566ffee

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ class ServoNode
103103
std::optional<KinematicState> processTwistCommand(const moveit::core::RobotStatePtr& robot_state);
104104
std::optional<KinematicState> processPoseCommand(const moveit::core::RobotStatePtr& robot_state);
105105

106-
// Variables
106+
rclcpp::Time convertClockType(const rclcpp::Time& time, rcl_clock_type_t new_clock_type)
107+
{
108+
if (time.get_clock_type() != new_clock_type)
109+
{
110+
return rclcpp::Time(time.nanoseconds(), new_clock_type);
111+
}
112+
return time;
113+
}
107114

115+
// Variables
108116
const rclcpp::Node::SharedPtr node_;
109117
std::unique_ptr<Servo> servo_;
110118
servo::Params servo_params_;

moveit_ros/moveit_servo/src/servo_node.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,14 @@ void ServoNode::servoLoop()
325325
std::optional<KinematicState> next_joint_state = std::nullopt;
326326
rclcpp::WallRate servo_frequency(1 / servo_params_.publish_period);
327327

328-
// wait for first robot joint state update
329328
const auto servo_node_start = node_->now();
330-
while (planning_scene_monitor_->getLastUpdateTime().get_clock_type() != node_->get_clock()->get_clock_type() ||
331-
servo_node_start > planning_scene_monitor_->getLastUpdateTime())
329+
330+
while (servo_node_start >
331+
convertClockType(planning_scene_monitor_->getLastUpdateTime(), servo_node_start.get_clock_type()))
332+
{
333+
RCLCPP_INFO(node_->get_logger(), "Waiting for planning scene monitor to receive robot state update.");
334+
rclcpp::sleep_for(std::chrono::seconds(1));
335+
}
332336
{
333337
RCLCPP_INFO(node_->get_logger(), "Waiting to receive robot state update.");
334338
rclcpp::sleep_for(std::chrono::seconds(1));

0 commit comments

Comments
 (0)