Last active
September 2, 2024 02:39
-
-
Save chfritz/8c2adab45a94e091be77c55b0432ad2e to your computer and use it in GitHub Desktop.
Simple script to setup your machine env to use a remote ROS master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple script to setup your machine env to use a remote ROS master | |
# example usage: use_robot.sh myrobot | |
# where myrobot is a resolvable hostname or an IP address | |
NORMAL=`tput sgr0 2> /dev/null` | |
GREEN=`tput setaf 2 2> /dev/null` | |
# get the IP of our device we'll use to conect to the host | |
TARGET_IP=$1 | |
IP=`ip route get $TARGET_IP | head -n 1 | sed "s/.*src \(\S*\) .*/\1/"` | |
echo -e "${GREEN}using $1 ($TARGET_IP) via $IP${NORMAL}" | |
export ROS_MASTER_URI=http://$1:11311 | |
export ROS_HOSTNAME=$IP | |
export ROS_IP=$IP |
Thanks! My robot had a different hostname for all the nodes than expected. By adding the correct hostname and IP to a container's /etc/hosts
, I was able to successfully listen to the nodes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Troubleshooting
If after running this script on the ROS client things are not working as expected, here are some things to help debug further.
rosnode list
work? If not, then your client machine cannot reach the master by the name you specified.rostopic echo /rosout
work? If not, then check whichROS_HOSTNAME
the master uses. It is possible that it uses a hostname, X, different from what you are assuming and that hostname is not resolvable from the client. This is the most common issue I have seen. What's happening here is that the publisher of/rosout
is registered with the ROS master using name X, and when the client subscribes to the topic, the master (via xmlrpc) tells the client to try and contact X for any messages on that topic. The client tries that but fails, because it cannot resolve X. So you need to either make sure all publishers (including the core itself) only use DNS resolvable names or use IPs. Or you can add the unresolvable names to the client's/etc/hosts
(not recommended). To see which names ROS nodes used when registering with the master you can runrosnode list -a
. You should be able to resolve all names listed there from any other machine connected to that master.