multi-robot-infrastructure.md
How to namespace multiple robots and have them on the same roscore
To have multiple robots on the same ROS core and each of them listen to a separate node, namespacing would be an easy and efficient way to help.
Set namespace on robots' onboard computers with environment variable
Boot up the robot and ssh into it
On the robot's onboard computer, open the terminal and type in
Then add the following line to the end of the file, using the robots name as the namespace
Also make the following other changes:
Save the file and don't forget to do source ~/.bashrc
Set namespace on your laptop with environment variable
Now that the robot is configured properly with its own unique name space, how do we talk to it?
There are three ways:
Configure your laptop to be permanently associated with the same name space
Permanently associate your laptop with the name space
Use the same steps above. Make sure your namespace is exactly the same as the namespace of the robot you want to control.
From now on, whenever you do, e.g. a cmd_vel, it will be directed just to your robot.
Use an environment variable
Set namespace for a termimal with temporary environment variable.
To set a namespace temporarily for a terminal, which will be gone when you close the termial, just type in export ROS_NAMESPACE={namespace_you_choose} directly in your terminal window.
You can use echo $ROS_NAMESPACE
Use the .launch file
To set namespace for a node in launch file, Use the attribute ns, for example:
<node name="listener1" pkg="rospy_tutorials" type="listener.py" ns="{namespace_you_choose}" />
Not recommended: add __ns to the run or launch command
Launch/Run a file/node with namespace in terminal. Add a special key __ns (double underscore here!) to your command, for example: roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch __ns:={namespace_you_choose} However,
Use of this keyword is generally not encouraged as it is provided for special cases where environment variables cannot be set. ()
Publishing/Subsribing topics in other namespace
Do a rostopic list, you will find out topics under a namespace will be listed as /{namespace}/{topic_name}
Make changes to turtlebot3_navigation package on your laptop
Type roscd turtlebot3_navigation to go to the package directory.
Type cd launch to go to the folder that stores .launch files.
Open the turtlebot3_navigation.launch
Change move base arguments
Add another argument cmd_vel_topic to the four arguments in the <!-- Arguments --> section:
Pass the new argument to move base launch file:
Change rviz arguments
Type roscd turtlebot3_navigation to go to the package directory.
Type cd rviz to go to the folder that has turtlebot3_navigation.rviz. It stores all the arguments for rviz.