Skip to content

Instantly share code, notes, and snippets.

@chfritz
Last active September 2, 2024 02:39
Show Gist options
  • Save chfritz/8c2adab45a94e091be77c55b0432ad2e to your computer and use it in GitHub Desktop.
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
#!/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
@jc-cr
Copy link

jc-cr commented Sep 2, 2024

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