Clock (sim time) from Ign-Gazebo to ROS2
I am trying to use sim time in ROS2 with ignition gazebo in order to control joints of a humanoid robot.
To do that, I launch the ignition bridge for /clock
topic and set use_sim_time
true for both of ign-bridge and a node that publishes desire joint angles based on sim time.
The node display the sim time as follows
double SimTime=node().now().nanoseconds();
RCLCPP_INFO(this->get_logger(), "NANOsec: '%f'", SimTime);
However, it is always zero.
Details:
- In both ignition gazebo and ros2,
/clock
topic echos the same sim time -> ignition bridge works properly. - The frequency of desire joint angles became same as the frequency of publisher after setting
use_sim_time
true. - In the case where
use_sim_time
is false, it shows the system time properly.
I know some answers for classic gazebo and ROS2 (this) But, I cannot use them because "ros_init" is not available for ignition-gazebo.
Please let me where I went wrong and solutions. If you also show the code that using sim time in ROS2 from ignition-gazebo, I would appreciate you.
Thanks,