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
Set a temporary environment variable that specifies the name space
Add the namespace to a launch file
Use the __ns parameter for roslaunch or rosrun (not recommended)
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
to check it.
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. (http://wiki.ros.org/Nodes)
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
file with nano or your favorite code editor.You will see the scripts for launching move base and rviz:
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:
These changes will make move base publish to
/{namespace_you_choose}/cmd_vel
instead of/cmd_vel
. Open themove_base.launch
file in the launch folder, you will see why it worked.
Change rviz arguments
Type
roscd turtlebot3_navigation
to go to the package directory.Type
cd rviz
to go to the folder that hasturtlebot3_navigation.rviz
. It stores all the arguments for rviz.Open
turtlebot3_navigation.rviz
with VSCode or other realiable code editors, since this file is long and a bit messy.In the .rviz file, search for all the lines that has the part
Topic:
Add your namespace to the topics you found. For example, change
to
These changes will make rviz subsribe to topics in your namespace.
Last updated