Ask Your Question
1

Roslaunch and SSH over local and remote machines using avahi

asked 2017-08-23 13:14:59 -0500

fastestindian gravatar image

updated 2017-08-23 21:39:38 -0500

How do you setup a local and remote ROS system to launch a roscore and nodes on two machines with avahi/zeroconf, i.e. without hard coding IP addresses on your LAN?

In my case, the requirements are:

  1. Local machine: some nodes for image visualization and slam
  2. Remote robot: roscore, platform specific nodes, sensor publishers
  3. Avoid hard coding IPs in .launch, .bashrc and shell scripts - robot and laptop
  4. should find each other by a hostname without editing /etc/hosts
edit retag flag offensive close merge delete

Comments

While I do appreciate the content and work laid out here, it would (in my mind) be more beneficial (and to the site's standards) to separate out the answer from the question.

jayess gravatar imagejayess ( 2017-08-23 15:49:48 -0500 )edit
1

@jayess, you're absolutely right. Resolved!

fastestindian gravatar imagefastestindian ( 2017-08-23 21:42:48 -0500 )edit

1 Answer

Sort by » oldest newest most voted
5

answered 2017-08-23 21:42:08 -0500

fastestindian gravatar image

Some (long) hours later, here's an answer for those new to ROS who might face the same questions.

The basic idea behind avahi is... you can resolve and connect to ROS machines without worrying about the IP they're behind. This particularly when moving from one LAN to another (e.g lab to field, lab to investor, etc). For e.g. theoretically, you could just connect your robot and laptop to a hotspot on your phone and demo your kit.

Hint: a lowercase system hostname/avahi hostname will serve you well! Ssh issue avoided later.

Avahi setup There are a number of good tutorials out there. Your machines would look like something.local and somethingelse.local In my case it was remote.local and local.local Do bi-directional ping tests so both machines can ping and resolve the avahi hostnames

/etc/hosts In my opinion, this should be vanilla Ubuntu something like this:

    127.0.0.1   localhost
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

SSH Issues: As some threads have noted, roslaunch uses an ssh lib that requires an RSA key (default is now ECDSA-SHA2).

IMPORTANT: Check your machine hostname is lowercase. ssh-server defaults to lowercase in the authorized keys file so your remote machine will keep asking you for a password when you punch in your upper case hostname.

$ ssh user@remote.local -oHostKeyAlgorithms=’ssh-rsa’

Follow the prompts and say “yes”

user@remote $ exit
$ ssh-keygen

Follow the prompt and generate a public-private key at ~/.ssh/ Provide a password

$ ssh-copy-id -i ~/.ssh/id_rsa.pub ssh user@remote.local

This copies your public key to the ~/.ssh/authorized_keys file on the other machines

$  ssh user@remote.local

Confirm a passwordless entry is possible Repeat for local.local from remote.local

~/.bashrc I’ve setup my ~/.bashrc like so

source /opt/ros/kinetic/setup.bash
export ROS_MASTER_URI=http://local.local:11311
export ROS_IP=local.local
export ROS_HOSTNAME=local.local

This allows me to launch roscore and nodes on my development machine when needed and remote connect from remote.local as well. You can replicate the script as you please on remote.local

I use env-loader from roslaunch to setup environment variables on both machines

Environment-loader script somewhere on remote.local:

export ROS_IP=remote.local
export ROS_MASTER_URI=http://remote.local:11311
export ROS_HOSTNAME=remote.local
exec "$@"
# Anything else you need….

Environment-loader script somewhere on local.local:

export ROS_IP=local.local
export ROS_MASTER_URI=http://remote.local:11311
export ROS_HOSTNAME=local.local
exec "$@"
# Anything else you need….

Again, above, my ros master needs to be on the remote robot so it’s alive even if the link dies.

BTW these scripts MUST be read-writeable for the user you’re ssh-ing into

For the launch file:

    <launch>
         <!-- Setup environment -->
        <arg name="machine_bot" default = "remote"/>
        <arg name="machine_c2i" default = "local"/>
        <arg name="ip_bot" default = "remote.local"/>
        <arg name="ip_c2i" default = "local.local"/>
        <arg name="machine_bot_user" default = "abc"/>
        <arg ...
(more)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-08-23 13:14:59 -0500

Seen: 1,062 times

Last updated: Aug 23 '17