Rosanswers logo

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.

Originally posted by MarosROS on ROS Answers with karma: 33 on 2020-03-03

Post score: 0


2 Answers 2


Rosanswers logo


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.

Originally posted by Tahir M. with karma: 213 on 2020-03-04

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by MarosROS on 2020-03-04:
@Tahir Mehmood I edited the question with the example


Rosanswers logo

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!

Originally posted by LukeBowersox with karma: 31 on 2020-04-01

This answer was NOT ACCEPTED on the original site

Post score: 1

Original comments

Comment by MarosROS on 2020-04-02:
Thanks this was also very helpful.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.