ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to establish subscription/publication communication within C++ code?

asked 2013-07-27 11:36:07 -0500

Bholms gravatar image

updated 2013-11-18 19:06:01 -0500

tfoote gravatar image

To establish communication (simple listen/talk) between two machines, I simply use

export ROS_HOSTNAME=ip1
export ROS_MASTER_URI=http://ip2:11311
rosrun ...

However, if I want machine1 to communicate with machine2 without explicitly tell machine1, but rather I use a machine3 to tell machine1 the ip address of machine2 to make the connection. How should I achieve this through c++? Is there any code that's equivalent to the commands above?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-07-29 00:57:39 -0500

Victor Lopez gravatar image

If you have a third machine you want to use as a coordinator, why not run the roscore in machine3?

In your other machines you do:

export ROS_HOSTNAME=ip1
export ROS_MASTER_URI=http://ip3:11311
edit flag offensive delete link more


The problem is that if I have 100 machines, then I will have to do this for all of them... That's why I am thinking of doing it with C++.

Bholms gravatar image Bholms  ( 2013-07-29 05:02:21 -0500 )edit

If you are setting up that many machines it is probably worth setting them up with proper hostnames so you don't need to reference their IPs.

tfoote gravatar image tfoote  ( 2013-11-18 19:07:02 -0500 )edit

answered 2013-07-28 22:01:01 -0500

Lucile gravatar image

I am not sure, but it looks more like a C++ problem than a ROS specific one.

I think you can write a C++ code for your machines which uses sockets to communicate the IP addresses you need and the setenv() function to change ROS_MASTER_URI and ROS_HOSTNAME the way you want to.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-07-27 11:36:07 -0500

Seen: 236 times

Last updated: Jul 29 '13