Monday, April 13, 2020

Setup to launch ROS nodes on a remote computer on a network

ROS nodes can be setup to run on a remote computer from a local computer on the same network. However, there are some setup to be done. After reading the tutorials and trying out on my own, the following steps summarized what worked for me.

Create known hosts
On the local Linux computer e.g. a Raspberry Pi (local1) do the following:
  1. Open a Terminal.
     
  2. Type in the command.

    $  ssh -oHostKeyAlgorithms='ssh-rsa' remote_user1@remote1

    The prompt appears: Are you sure you want to continue connecting (yes/no)?
  3. Type in yes. Press RETURN.
  4. When prompted, type in the password for the remote1 computer's remote_user1.

    The Terminal is now connected to the computer remote1 and remote_user1 is logged in.

    The remote1 computer name is encrypted with the RSA encryption and stored in the Raspberry Pi's /home/local_user1/.ssh/known_hosts file.

  5. Type in exit.

    The connection to remote1 is closed.
  6. If necessary, repeat the previous steps 2 to 4 for the IP address of the computer remote1.

    $ ssh -oHostKeyAlgorithms='ssh-rsa' user1@192.168.8.101

    Note: where 192.168.8.101 is the IP address for the computer remote1.
Create SSH public and private keys for authentication
  1. On the local1 computer, open a Terminal.
  2. Type in the command:

    $ ssh-keygen -t rsa

    Enter file in which to save the key (/home/local_user1/.ssh/id_rsa):
  3. Press RETURN.

    Enter passphrase (empty for no passphrase):
  4. Press RETURN.

    Enter same passphrase again:
  5. Press RETURN.

    The private key is generated in /home/local_user1/.ssh/id_rsa.
    The public key is generated in /home/local_user1/.ssh/id_rsa.pub
    .
Install the public key(s) to the remote computer
  1. On the computer local1, open a Terminal.
  2. Type in the command:

    $ ssh-copy-id remote_user1@remote1
  3. When prompted, type in the password for remote_user1.

    The public keys are installed on computer remote1.
Create a remote ROS environment shell script file
The following steps should be executed on the remote computer remote1.
  1. Using a text editor, create a shell script file e.g. /opt/ros/melodic/env_remote1.sh with the following content.

    #!/bin/bash
    
    export ROS_MASTER_URI=http://remote1:11311
    
    source /opt/ros/melodic/setup.bash
    source /home/remote_user1/catkin_ws/devel/setup.bash
    
    exec "$@"
    

  2. Open a Terminal. Make the shell script executable.

    $ sudo chmod a+x env_remote1.sh

Create and run local launch file
The following should be done on the local computer local1.
  1. Using a text editor, create a launch file e.g. run_remote.launch.
    <launch>
            <machine
                    name="remote1"
                    address="remote1"
                    env-loader="/opt/ros/melodic/env_remote1.sh"
                    default="true"
                    user="remote_user1"
            />
            <node machine="remote1" pkg="beginner_tutorials" name="hello_doubles" type="hello_doubles" />
    </launch>
    

    Note: this launch file will run the hello_doubles node from the beginner_tutorials package on the remote1 computer.

  2. Open a Terminal. Type in the following command assuming the launch file is in the current directory:

    $ roslaunch remote.launch
    The following messages may appear. Ws06 in this example screenshot is the remote computer.

    No comments: