0
$\begingroup$

I've got a Gazebo model defined in a SDF file that I spawn in my world with ros_gz_sim create, with the -name argument. This allows me to spawn several models based on the same SDF file. Now I added a sensor "type='gpu_lidar'", this sensor needs a topic to publish data to.

How can I alter this topic to still be able to spawn several models ?
maybe with the '-param' argument but I didn't find an example of how to use it.

(This is a Ros2 question as I want to implement the answer in my launch file.)

$\endgroup$

2 Answers 2

1
$\begingroup$

What you're describing here can be accomplished with topic remapping. You can find documentation on it here, and another question about this topic here.

The basic concept behind topic remapping is to take two nodes that have the same topic (for example, two LIDAR nodes both publishing to /lidar) and change the name of the topic they operate under (so one goes to /lidar_a and another goes to /lidar_b).

This can be accomplished using launch files. Here's an example provided by the turtlesim launch demos:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])

Note the 'remappings' entry found in the bottom node: this is remapping the '/input/pose' topic to 'turtlesim1/turtle1/pose', etc.

$\endgroup$
2
  • $\begingroup$ If this works I don't known how to. I used the remappings arg, or a remapping bridge file, but there still is only one gazebo topic redirected to several ros2 topic. $\endgroup$
    – SebL
    Sep 25 at 7:32
  • $\begingroup$ @cst0 your answer describes ROS2 remapping. The OP's question is about the topic of a Gazebo Sim System, i.e. a topic for gz-transport. $\endgroup$
    – JRTG
    Sep 25 at 18:31
0
$\begingroup$

The solution I found to fix my pb is to remove the topic tag from the SDF file. This makes gazebo generates topics named /world/{{ WORLD_NAME }}/model/{{ drone_name }}/link/lidar_link/sensor/gpu_lidar/scan/points.

With those unique topics I can remap them with a dynamically generated bridge file.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.