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

ROS2 launch multiple turtlebots in namespaces dynamically

asked 2022-08-25 08:23:30 -0500

Zeckurbo gravatar image

updated 2022-08-25 09:02:02 -0500

Hello,

I want to simulate many turtlebot3 in Gazebo (ROS2 Foxy). Because the amount could vary, it would be best for me to have an option like the namespace argument of the gazebo spawner. Sadly when I spawn via

ros2 run gazebo_ros spawn_entity.py -entity robot1 -x 0 -y 0 -z 0 -file ~/turtlebot3_ws/install/turtlebot3_gazebo/share/turtlebot3_gazebo/models/turtlebot3_waffle_pi/model.sdf -robot_namespace robot1

I am able to spawn, but when I run slam, I get errors. My first idea was, that maybe the robot_state_publisher is necessary, but so far I was not able to launch it properly afterwards.

This tutorial shows, how to do it with a package, but wants to edit a yaml by hand and is only for the physical robot. Also this answer has a very tideous way do do it by hand for a fixed amount of bots.

On the official website, there is no tutorial for foxy here. The multi robot spawn seems only supported for Kinetic.

Is there a better way, to spawn a turtlebot3 inside a namespace with a single command? So that this command can be executed in a for loop? Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-08-30 16:19:14 -0500

You can do a for loop in the Python launch file, but the amount of robots has to be hard-coded in the launch file. Indeed a launch argument cannot be used by Python as an integer to build a for loop.

The best would be to have a separate launch file that spawns the robot and the SLAM nodes in a given namespace, and a master launch file that includes the first one in a for loop.

To my knowledge the only way to loop with a launch argument is to do it recursively, that is the robot-specific launch file takes an integer argument (e.g. robot number n) to spawn everything in the robot<n> namespace and calls itself with argument n-1 if n > 1.

You still need to have hard-coded values somehow, as the initial poses have to be specified for each robot.

edit flag offensive delete link more

Comments

I have no problems writing a script to input all details about a robot. What I was missing, is a quick and easy way, to spawn a robot in a namespace (like the spawner of gazebo can not put /tf into the ns by itself yet etc.).

It would be nice to have a generic robot spawn launch file (e.g. a turtlebot) and then just calling it. But the default ones from turtle do not do that, so it is hard for a beginner to figure all stuff out, especially with all the yaml and sdf/urdf stuff additional to ROS2)

I think I will try to understand the nav2 gazebo spawner for now, but I hope some robot devs will provide a out of the box fully namespace launch file in the future.

Zeckurbo gravatar image Zeckurbo  ( 2022-08-31 02:13:47 -0500 )edit
0

answered 2022-08-30 04:48:10 -0500

Zeckurbo gravatar image

updated 2022-08-30 09:32:27 -0500

The answer here might be helpful.

Maybe this launch file can be edited, to at least start a simulation dynamically.

Also for advanced users, the nav2 multiple robot launch file can be helpful, to get an idea, what has to be done, but yet it is not really usable as a generic launch file, only an example.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-08-25 08:23:30 -0500

Seen: 524 times

Last updated: Aug 30 '22