ROS mutiple machines
Hi, I try to run ROS in multiple machines, I use ROS master to publish vehicle command and subscribe the topic in another machine I configure .bashrc file like below Master machine:
export ROS_MASTER_URI=http://MasterIP:11311
export ROS_IP=MasterIP
Other machine:
export ROS_MASTER_URI=http://MasterIP:11311
export ROS_IP=machineIP
My code to subscribe (just basic code to test if I got the data in other machine)
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "vtd2ros/EgoVehicleControl.h"
#include <sstream>
vtd2ros::EgoVehicleControl vehicle_cmd; // ego vehicel control command
void ROSControlCmdCallback(const vtd2ros::EgoVehicleControl::ConstPtr &msg)
{
vehicle_cmd = *msg;
ROS_INFO("Throttle: [%g]", msg->throttle_cmd);
ROS_INFO("Steering Angle: [%g]", msg->steering_target_cmd);
}
int main(int argc, char **argv){
/*** ROS stuff ***/
ros::init(argc, argv, "VehicleCommand");
ros::NodeHandle n;
ros::Subscriber subscriber = n.subscribe<vtd2ros::EgoVehicleControl>("/control_cmd_ros", 1000, ROSControlCmdCallback );
std::cout<< "My modifzied Throttle: " << vehicle_cmd.throttle_cmd;
ros::spin();
return 0;
When I run the code in other machine, It show nothing
robotest@robotest:~/robo-test/Vu/vtd2ros$ rosrun vtd2ros vehiclecontrol_test
Then I tried to run the subscribe in the same master machine It is able to receive the vehicle control
robotest@robotest:~/RoboTest/Vu/vtd2ros$ rosrun vtd2ros vehiclecontrol_test
My modifzied Throttle: 0[ INFO] [1622716994.915362905]: Throttle: [0]
[ INFO] [1622716994.916656551]: Steering Angle: [0]
[ INFO] [1622716994.925302807]: Throttle: [0]
What could be a possible problem here? Anyone know please help.
Have you tried to set the variable
ROS_HOSTNAME
instead ofROS_IP
(using the same values) ? I can't explain why but when using multiple machines I use this variable and it works fine.Hi Delb, Thanks for your information. I found the problem. It was because my Master machine runs the publisher package in the docker container. Now, I am trying to make docker working with outside of docker.