ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Using ROS namespaces programmaticaly

asked 2020-03-03 13:02:21 -0500

MarosROS gravatar image

updated 2020-04-01 07:30:19 -0500

It seems like the simple question, but is it possible to control robots with different ROS namespaces in one launch file programmaticaly? For example, i want to move robot1 one meter forward, and robot2 one meter backward programmaticaly in one file. Also i wonder if it is possible for a launch file which is launched for example in ROS_NAMESPACE=robot1, to programmaticaly control nodes of another robot in ROS_NAMESPACE=robot2? Thanks for answers.


For example, i use code from this tutorial

What i want to know is, if it is somehow possible to write code like this:

#include <ros/ros.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>

typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;

int main(int argc, char** argv){
  ros::init(argc, argv, "simple_navigation_goals");

  //tell the action client that we want to spin a thread by default
  MoveBaseClient ac("tb3_0/move_base", true);

  //wait for the action server to come up 
    ROS_INFO("Waiting for the move_base action server to come up");

 move_base_msgs::MoveBaseGoal goal;

 //we'll send a goal to the robot to move 1 meter forward
 goal.target_pose.header.frame_id = "tb3_0/base_link";
 goal.target_pose.header.stamp = ros::Time::now();

 goal.target_pose.pose.position.x = 1.0;
 goal.target_pose.pose.orientation.w = 1.0;

 ROS_INFO("Sending goal");


 if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
    ROS_INFO("Hooray, the base moved 1 meter forward");
    ROS_INFO("The base failed to move forward 1 meter for some reason");

return 0;

My goal would be to add two more move_base clients to control more robots from different namespace in this one source file.


I found out, this example is possible.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-03-04 01:37:37 -0500

Tahir M. gravatar image


Yes it is possible to control multiple robots using ROS namespaces. Every robot will have its own attributes (topics, services etc.) appended with its very own name.

I didn't understood in one launch file programmaticaly? but I will answer it with two possibilities.

  1. You can launch robot software using roslaunch api, you can find a few example here on how to use this api.

  2. You can use launch file and use namespaces and other arguments to control each of your robot.

edit flag offensive delete link more


@Tahir Mehmood I edited the question with the example

MarosROS gravatar image MarosROS  ( 2020-03-04 12:08:59 -0500 )edit

answered 2020-04-01 17:34:10 -0500

LukeBowersox gravatar image

Try in your launch file

<group ns="robot1">
<robot launch files etc>
<remap from="cmd" to="/robot2/cmd"/>

<group ns="robot2">
<robot launch files etc>

This will put your robots in separate namespaces with ns, and the remap will make the topic cmd be changed to /robot2/cmd the leading slash in front tells ros to ignore your namespace declaration for this remapped topic. Hope that at least gives you a hint!

edit flag offensive delete link more


Thanks this was also very helpful.

MarosROS gravatar image MarosROS  ( 2020-04-02 13:41:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-03-03 13:02:21 -0500

Seen: 248 times

Last updated: Apr 01 '20