Skip to content

Commit f4e3f5a

Browse files
authored
Fix the initial wrong periodicity reported by controller_manager (#2018)
1 parent d2dd762 commit f4e3f5a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

controller_manager/src/ros2_control_node.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ int main(int argc, char ** argv)
9393
}
9494
}
9595

96+
// wait for the clock to be available
97+
cm->get_clock()->wait_until_started();
98+
cm->get_clock()->sleep_for(rclcpp::Duration::from_seconds(1.0 / cm->get_update_rate()));
99+
96100
RCLCPP_INFO(cm->get_logger(), "update rate is %d Hz", cm->get_update_rate());
97101
const int thread_priority = cm->get_parameter_or<int>("thread_priority", kSchedPriority);
98102
RCLCPP_INFO(
@@ -122,7 +126,7 @@ int main(int argc, char ** argv)
122126
auto const period = std::chrono::nanoseconds(1'000'000'000 / cm->get_update_rate());
123127
auto const cm_now = std::chrono::nanoseconds(cm->now().nanoseconds());
124128
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
125-
next_iteration_time{cm_now};
129+
next_iteration_time{cm_now - period};
126130

127131
// for calculating the measured period of the loop
128132
rclcpp::Time previous_time = cm->now() - period;

0 commit comments

Comments
 (0)