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.