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.
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
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)
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.
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.
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}" />
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)
Do a rostopic list
, you will find out topics under a namespace will be listed as /{namespace}/{topic_name}
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:
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 the move_base.launch
file in the launch folder, you will see why it worked.
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.
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.