How to launch Gazebo, RTAB-Map and RViz multiple times from a single file?

asked 2020-06-26 22:12:58 -0500

MalarJN gravatar image

I followed the simulation part of the Mapping and Navigation on Turtlebot tutorial to try SLAM with RTAB-Map. I want to be able to launch Gazebo, rtabmap_ros and RVIZ from a single launch file/script and repeat the process over multiple iterations and pass arguments to RTAB-Map.

  1. I found a somewhat similar question where the person created a python script using roslaunch API. I tried to follow the simple examples in the tutorial to try and launch Gazebo and RTAB-Map to no avail. As I am not familiar with python codes, I seem to be missing something when I try to execute the examples. Has anyone tried this or something similar before? If yes, could you share a sample to launch Gazebo and RTAB-Map?
  2. As suggested in the same question, I also tried a shell script and was successfully able to launch Gazebo, RTAB-Map and Rviz. However, when trying to launch them in a loop, for 3 iterations, Gazebo launches thrice and then RTAB-Map tries to launch thrice, which breaks the code. I am looking for a way to launch the packages in the following sequence for multiple iterations:
$ roslaunch turtlebot_gazebo turtlebot_world.launch
$ roslaunch rtabmap_ros demo_turtlebot_mapping.launch simulation:=true
$ roslaunch rtabmap_ros demo_turtlebot_rviz.launch

Is there another way I could approach this?

PS: I am using ROS Kinetic on an Ubuntu 16.04 VM.

edit retag flag offensive close merge delete


Hi @MalarJN,

Can I ask you why you want three instances of Gazebo and Rviz?. Generally speaking it is normal to have multiple instances of a processing node like RTAB-Map (Configured properly) but there is no reason to have multiple instances of Gazebo and Rviz. First of all because the gz-server of Gazebo binds its address at execution time and will not allow you to generate a second instance, it will throw an error and second of all, because with one Rviz instance you will be able to visualize all that happens in ROS, that includes having multiple robots at the same time with multiple namespaces.

For me, what you are tying to do is performing a multipe robot simulation. If that is the case you will need a launch file with multiple namespaces. It will be sufficient to launch one Rviz instance, one Gazebo instance and load the two ...(more)

Weasfas gravatar image Weasfas  ( 2020-06-27 06:17:15 -0500 )edit

Hi Weasfas,

Currently, I launch Gazebo, rtabmap_ros and RViz by executing the above commands in different terminals. What I want to do now is write a single launch file or script to launch these packages. I also want the script to repeat this multiple times. Meaning, at any given time, these 3 must be running together to generate a map of the simulated world. The map should be saved and then the process repeated N times, with different values passed to RTAB-Map parameters.

For example, consider MaxDepth of 3m, 4m,...., Nm, in the 1st iteration Gazebo should be launched, then RTAB-Map should launch with MaxDepth set to 3m and the script should finally launch RViz. After exploring the simulated world in Gazebo, the map created in RViz should be saved and the 3 processes should be ended. This sequence should repeat N times with different values passed to Maxdepth for ...(more)

MalarJN gravatar image MalarJN  ( 2020-06-27 08:28:25 -0500 )edit

Ok, If i understand you properly you just want to launch Gazebo, RTAB-Map and rviz in a loop N times. To do that, you will need to ensure the last iteration instances propely exited and freed any memory or reserved resources the next intances may use.

So bearing in mind this, it will be usefull to have only one launch file that launchs Gazebo, RTAB-Map and Rviz. You can do this by using the include xml tag. Once you have this unique launcher ready, you can just generate a bash script with a loop, something like:

for n in range (N):
 launch enviroment.launch (this file launchs Gazebo, RTAB-Map and Rviz all together)
 wait (ArbitraryTime)
 kill enviroment.launch process
 wait (ArbitraryTimeToEnsureResourcesAreFree)
Weasfas gravatar image Weasfas  ( 2020-06-27 12:01:02 -0500 )edit

Another approach can be just launch your N robots in the same Gazebo world, each one with its own namespace working at the same time in your enviroment but in different world places. If you want to generate a map of a simulated indoor enviroment you can just copy several times that indoor enviroment and place several copyed model inside the world.

Weasfas gravatar image Weasfas  ( 2020-06-27 12:03:03 -0500 )edit

Hi Weasfas,

I wrote an shell script and called it in a for loop in another shell script However, the kill process doesn't really seem to do anything except for print a terminate in the logs, Gazebo, RTAB-Map and RViz are still open and exploration is still happening. Any suggestions as to how the processes can be shut down before being relaunched?

Best regards, Malar.

MalarJN gravatar image MalarJN  ( 2020-06-29 11:48:19 -0500 )edit

Hi @MalarJN !

Mmm that sounds weird, are you killing each process one by one with the PID or direcly the roslaunch process?

kill -INT PID # Sendt SIGINT to the process.
kill -9 PID # Force kill of the proces.
Weasfas gravatar image Weasfas  ( 2020-06-29 16:49:14 -0500 )edit

Because I launch the various applications from a single shell script using pkill to kill the session seems to work.

MalarJN gravatar image MalarJN  ( 2020-07-03 10:57:03 -0500 )edit