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

How to configure ROS_MASTER_URI & ROS_HOSTNAME

asked 2022-09-20 13:07:48 -0500

praveen_khm gravatar image

Hi,

I am not able to clearly understand the concept of ROS_MASTER_URI. Can someone kindly help me with the below?

I have two systems. One robot which runs on ESP32 and connects via WiFi. I want this to be the slave device. On the other hand, I have a laptop which I want to be the master. I have followed a lot of tutorials and finally able to get it working, but the issue is if I change the network, what will happen?

On the ESP32, I have below code:

IPAddress server(192, 168, 0, 110); // ip of ROS server -> the laptop

On the laptop, there is still no ROS_MASTER_URI setup in bashrc file. I have manually checked the IP of the laptop and added that in ESP32. Now, how is this done? Every time the IP address of ROS changes in master, the same IP should be given on the slave device? This means, I need to reprogram it every time I go to a new location?

Secondly, what are Host names and ROS_IP used for? Will they help if creating an alias which I can give to robot?

In simple words, I do not want to open and reprogram the robot slave device every time I take my laptop to a new location. I should be able to change the IP on the laptop and somehow (magically :) work on the robot. Any help is extremely appreciated as I am struggling to get a solution from a week.

-Praveen

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-09-23 15:56:45 -0500

peci1 gravatar image

updated 2022-09-23 16:04:15 -0500

The best way to use ROS_IP and ROS_HOSTNAME is not to use them. These two variables are provided mostly as workarounds for cases where the network cannot handle the standard DHCP+DNS setup that works on many (even SOHO) routers. I.e. in the ideal case, the router should keep a local DNS database that is filled with hostnames and the IP addresses they got from DHCP.

If your network supports this ideal case, just set ROS_MASTER_URI=http://the-master-computer:11311 on the non-master computer and that's it. Please, also note that if the robot HW allows it, it is always a better idea to run the ROS master (aka roscore) on the robot than on your laptop. If ROS_MASTER_URI is not set, it defaults to http://0.0.0.0:11311 (it is sometimes also written as http://localhost:11311, however the default-created ROS master binds to all network interfaces and not just the loopback as localhost might suggest). So on the "master" computer, just run roscore and you don't have to care about setting ROS_MASTER_URI. The computer will be its own master.

Sometimes the network works correctly, but the operating system complicates things. E.g. Ubuntu. If you have an Ubuntu computer in the network, it cannot contact LAN hosts by hostnames in the default configuration. We set up all of our Ubuntu machines with sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf which makes hostname resolution via DNS possible (the command enables a different mode of /etc/resolv.conf). This has been tested on 18.04 and most pobably also 20.04. Please, do some research before running this command on newer versions as the network stack may have different composition.

In case your network does not run this clever DNS+DHCP combination, or if it is buggy, the next option of choice is mDNS (avahi). I'm not sure if ESP32 supports it or not, though. On a default-configured Ubuntu, you can try contacting other hosts by addresses in the form ofhostname.local. The only requirement for this to work is that all machines run mDNS clients and that the network does not block mDNS discovery. If you want to go this way, that's where ROS_HOSTNAME comes into play. When it is empty, whenever a computer advertises a topic, it tells others the topic can be found on e.g. http://hostname:33333. If another computer tries to subscribe the topic, it tries to resolve hostname to an IP address and fails. Let ROS_HOSTNAME save the day! On the publishing computer, set ROS_HOSTNAME=hostname.local and voila, all published topics will now be advertised as http://hostname.local:33333 which other clients should be able to resolve. Theoretically, setting this on the publisher should be enough, but if you want e.g. services or actions to work, both communicating computers should have this setting, each with its own mDNS hostname.

ROS_IP is the "poor man's" last resort. I usualy ... (more)

edit flag offensive delete link more

Comments

Thank you for the detailed explanation. I was not able to get this detailed explanation till now.

Regarding my setup, I am no longer using host name or ROS Master. I took a side route as to not mess up with ROS at all. I configured the ESP32 to run a captive portal. So everytime I go to a new location, I (or someone else) will log into ROS and get the IP address of the ROS master, which can be a laptop or Raspberry PI.

A clever trick with joystick connected to ESP32 will erase all the previously stored IP address, SSID, Password and Port and open captive portal. Now the end user will add the credentials and that is permanently saved in ROM until next joystick erase. This way, I never touch ROS Master, or try to connect directly using HOSTNAME. This may not be a better approach ...(more)

praveen_khm gravatar image praveen_khm  ( 2022-09-23 16:37:02 -0500 )edit
1

answered 2022-09-20 17:21:18 -0500

ljaniec gravatar image

This answer mentioning using DNS server should help you partially:

This is a situation in which a DNS server (which is coupled with / knows how to deal with your DHCP server) would work best. Instead of using IP addresses, you'd give hostnames to your robots and your PC, and then make sure the DNS server can resolve the hostnames to the IPs (and back).

The ROS Network Setup can also help (2.3-2.4).

Some links to resources I found regarding DNS for ROS etc.:

edit flag offensive delete link more

Comments

Ok. Thank you. I will check these links and try to understand. It seems like a solution i am looking for.

praveen_khm gravatar image praveen_khm  ( 2022-09-21 00:08:57 -0500 )edit

https://answers.ros.org/question/2287...

All your robots would then have ROS_MASTER_URI=http://hostname_of_your_pc:11311, which would work no matter what IP your PC gets. You would also need to make sure ROS_HOSTNAME is configured correctly on all three robots & your PC.

This is exactly what I wanted. However, to my limited knowledge, I am still not able to understand this. So, does it mean that I set ROS_HOSTNAME and export ROS_MASTER_URI="http://192.168.0.100:11311" and the same IPaddress on all the robots and it connects directly without a fuss? Please advice.

praveen_khm gravatar image praveen_khm  ( 2022-09-21 02:03:35 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-09-20 13:07:48 -0500

Seen: 2,449 times

Last updated: Sep 23 '22