ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[ROS2] Using sim time parameter, nodes time is always zero

asked 2019-08-25 14:16:50 -0600

madmax gravatar image

I am trying to get the current simulation time, but I always receive zeros..
As soon as I set use_sim_time back to false, I receive current system time.

Sim time should be working, shouldn't it?
I am on Dashing release.

Here is the code:

int main(int argc, char ** argv)
{
   logging::initializeLogger("simTimetest");
   rclcpp::init(argc, argv);

   rclcpp::Node node("timeTest");

   rclcpp::Parameter simTime( "use_sim_time", rclcpp::ParameterValue( true ) );
   node.set_parameter( simTime );
   auto useSimTime = node.get_parameter( "use_sim_time" ).as_bool();


   auto periodic_timer = node.create_wall_timer(
           100ms,
           [&]() {
               log_info( "time {}.{} useSimTime: {}", node.now().seconds(), node.now().nanoseconds(), useSimTime );
            });

   rclcpp::spin(node.get_node_base_interface());

   rclcpp::shutdown();
  return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-12-09 09:18:21 -0600

madmax gravatar image

For the /clock being published, the gazebo plugin "ros_init" is needed.

See: https://github.com/ros2/rclcpp/issues...

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2019-08-25 14:16:50 -0600

Seen: 4,046 times

Last updated: Dec 09 '19