ROS mutiple machines

asked 2021-06-03 06:19:00 -0500

sgttrieu gravatar image

updated 2021-06-03 07:59:12 -0500

Delb gravatar image

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 image description

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 image description

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.

edit retag flag offensive close merge delete

Comments

Have you tried to set the variable ROS_HOSTNAME instead of ROS_IP (using the same values) ? I can't explain why but when using multiple machines I use this variable and it works fine.

Delb gravatar image Delb  ( 2021-06-03 08:02:17 -0500 )edit

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.

sgttrieu gravatar image sgttrieu  ( 2021-06-04 02:06:16 -0500 )edit