RobotecAI / ros2cs

A C# (.Net) implementation of ros2 client library (rcl), enabling communication between ros2 ecosystem and C#/.Net applications such as Unity3D
Apache License 2.0
91 stars 22 forks source link

Support use_sim_time (equivalent) in ros2cs #15

Open adamdbrw opened 2 years ago

adamdbrw commented 2 years ago

The implementation should be rather straightforward.

In ros2, point of interest is _timesource.cpp. It involves adding a "/clock" subscription that runs in it's own executor and using it as a time source if the parameter is set (with rcl_set_ros_time_override). This is preceded by resetting clocks and calling rcl_enable_ros_time_override. Since we interface with rcl, we need to replicate the behavior around calling these.

The work is as follows:

  1. Expose API to set use_sim_time (on Ros2cs level)
  2. Make this setting control whether we add a subscriber to "/clock" topic which in callback calls the *ros_time_override api. We would do this internally within Ros2cs. The subscription is best effort, keep last 1.

The current api for getting time should then just work (give system or "/clock" time depending on the parameter).