Using ROS namespaces programmaticaly
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.
Edit:
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
while(!ac.waitForServer(ros::Duration(5.0))){
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");
ac.sendGoal(goal);
ac.waitForResult();
if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
ROS_INFO("Hooray, the base moved 1 meter forward");
else
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.
---Edit---
I found out, this example is possible.