Skip to content

Commit

Permalink
[ros2_control_node] Handle simulation environment clocks (backport #1810
Browse files Browse the repository at this point in the history
) (#1862)
  • Loading branch information
mergify[bot] authored Nov 8, 2024
1 parent a8696f4 commit 246885f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions controller_manager/src/ros2_control_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ int main(int argc, char ** argv)

auto cm = std::make_shared<controller_manager::ControllerManager>(executor, manager_node_name);

const bool use_sim_time = cm->get_parameter_or("use_sim_time", false);

const int cpu_affinity = cm->get_parameter_or<int>("cpu_affinity", -1);
if (cpu_affinity >= 0)
{
Expand All @@ -68,7 +70,7 @@ int main(int argc, char ** argv)
thread_priority);

std::thread cm_thread(
[cm, thread_priority]()
[cm, thread_priority, use_sim_time]()
{
if (realtime_tools::has_realtime_kernel())
{
Expand Down Expand Up @@ -120,7 +122,14 @@ int main(int argc, char ** argv)

// wait until we hit the end of the period
next_iteration_time += period;
std::this_thread::sleep_until(next_iteration_time);
if (use_sim_time)
{
cm->get_clock()->sleep_until(current_time + period);
}
else
{
std::this_thread::sleep_until(next_iteration_time);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ controller_interface
controller_manager
******************

* ``ros2_control_node`` can now handle the sim time used by different simulators, when ``use_sim_time`` is set to true (`#1810 <https://github.com/ros-controls/ros2_control/pull/1810>`_).
* The ``ros2_control_node`` node now accepts the ``thread_priority`` parameter to set the scheduler priority of the controller_manager's RT thread (`#1820 <https://github.com/ros-controls/ros2_control/pull/1820>`_).
* Added support for the wildcard entries for the controller configuration files (`#1724 <https://github.com/ros-controls/ros2_control/pull/1724>`_).
* The ``ros2_control_node`` node has a new ``lock_memory`` parameter to lock memory at startup to physical RAM in order to avoid page faults (`#1822 <https://github.com/ros-controls/ros2_control/pull/1822>`_).
Expand Down

0 comments on commit 246885f

Please sign in to comment.