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

Should I manually pass use_sim_time to all nodes in a ROS 2 launchfile ?

asked 2021-02-09 16:42:00 -0500

deb0ch gravatar image

updated 2021-02-10 02:55:46 -0500

Should I always manually transmit the use_sim_time manually to all my nodes in a launchfile in ROS 2, if I want to be able to slow down or accelerate the simulation time or be able to run it on rosbags ?

The only official example I have is from the robot state publisher tutorial, where it is transmitted manually.

But I would expect a way to setting it globally, since it is the entierity of a ROS 2 system that should affected by time when you slow down or accelerate a simulation, or replay a rosbag. And because it is repetitive and add length to the code.

Is there such a way instead ?

edit retag flag offensive close merge delete

Comments

Hi! Did you since find a way to set use_sim_time globally (besides setting it in the launchfile)?

ottojo gravatar image ottojo  ( 2021-04-23 17:57:16 -0500 )edit

It would be convenient to have a global use_sim_time. However its up to each node to implement so i am not sure this is even possible or desirable.

however ever robot i have seen is has to pass it throughout the launch ecosystem because to your point it really does effect everything. I alsot breaks if every node is not on the same use_sim_time param. So de facto there is a global use_sim_time concept.

Therefore i think this is a good feature request and would require updated to rclcpp and rclpy i think. somewhat related and definitly good place for more info on the client library implementations of ros time: https://github.com/ros2/rclcpp/issues...

austin gravatar image austin  ( 2021-04-25 11:39:38 -0500 )edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2021-04-25 20:10:26 -0500

Kenji Miyake gravatar image

Can set_parameter solve this problem? #q368802

edit flag offensive delete link more
3

answered 2021-04-26 08:12:04 -0500

deb0ch gravatar image

Hey ! Nice to see some movement around this question !

Since I posted, we found a neat solution that works great for us : using the /**: syntax in the .yaml params file, where ** matches the names of all the nodes :

params/simulation.yaml

---
/**:
    ros__parameters:
        use_sim_time: true

launch/do_stuff.launch.py

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description():
    """Launch stuff using ROS 2."""
    params = os.path.join(get_package_share_directory('your_package'), 'params', 'simulation.yaml')

    return LaunchDescription([
        Node(
            package='stuff',
            executable='do_stuff_node',
            name='do_stuff',
            parameters=[params],
            output='screen'),
    ])
edit flag offensive delete link more

Comments

1

but how do you use this if your node has it's own parameter file?

NEngelhard gravatar image NEngelhard  ( 2022-01-13 03:33:52 -0500 )edit
1

answered 2022-08-25 10:34:35 -0500

tnajjar gravatar image

updated 2022-08-25 10:35:51 -0500

See this PR for an alternative solution. @NEngelhard

edit flag offensive delete link more
0

answered 2022-08-29 15:15:40 -0500

Hi, I have written a small wrapper around the Python launch syntax: https://github.com/oKermorgant/simple...

Besides other things, it allows to forward a use_sim_timelaunch parameter to all nodes that are run in this launch file https://github.com/oKermorgant/simple...

This wrapper is packaged for foxy, galactic and humble.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-02-09 16:42:00 -0500

Seen: 6,708 times

Last updated: Aug 29 '22