Remote machine running ROS nodes

Prefence:

This document describes how can you launch roslaunch file to run remote machine running ROS nodes.

The following requires you need to meet:

  1. Local machine
  2. Remote machine
  3. ROS_MASTER_URL
1. Build SSH Connection Between Local And Remote:

The way roslaunch-nodes works, needs a valid ssh-connection between the local and the remote machines. To ensure connection, create an authorized-key:

1
2
3
4
5
6
7
8
9
10
11
12
# 1. Creat an ssh-key on local machine.(Because ros node ssh not the linux ssh, so it must choose rsa way.)
ssh-keygen -t rsa
# 2. The following messages you will get:
Enter file in which to save the key (/home/localhost/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):
# 3. Copy the public key into the new machine's authorized_keys file, using the ssh-copy-id command:
# <ssh-key-path> eg: ~/.ssh/id_rsa.pub
ssh-copy-id -i <ssh-key-path> remote-machine-user@remote-machine-ip

# If Unable to establish ssh connection:
export ROSLAUNCH_SSH_UNKNOWN=1
2. Create An Env-loader Script:

Due to the automated nature of ROS launch, it avoids executing the user’s .bashrc on the remote nodes and requires an envirnoment file to assign remote environment variables.

Let’s assume that we need to create env-loader for a workspace located under /home/nvidia/workspace:

The following is an example of the env-loader script:

1
2
3
4
5
6
7
8
#!/bin/bash

export ROS_IP=172.16.1.102
export ROS_MASTER_URI=http://172.16.1.100:11311

source /root/workspace/ros/devel/setup.bash

exec "$@"

Finally save the above created env-loader script on the remote-machine. Let’s assume that we saved the above mentioned env-loader script into /home/nvidia/workspace/devel/remote_env_loader.sh.

3. Create The Roslaunch File:

The following example configure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<launch>
<machine
name="<remote-machine-name>"
address="<remote-machine-ip>"
user="<remote-machine-user>"
password="<ssh-password of the remote-machine>"
timeout="<timeout-value for the ssh-connection>"
env-loader="<env-loader file path>"
ssh-port="<SSH Port>"
default="true"
/>

<!-- Remote Machine Running Node -->
<node
machine="<remote-machine-name>"
name="<node name>"
pkg="<node package>"
type="<node executive>"
/>

</launch>
5. Allow Remote Docker SSH:
  1. First step install openssh-server

    1
    apt-get install openssh-server
  2. If you docker run images with parameter ‘–net=host’, the local host ports are your container ports. So you need to change ssh port to connect container.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    vim /etc/ssh/sshd_config
    ########################

    # 1. Change Port 22 to Your port.
    Port 22 --> Port 22333

    # 2. Change PermitRootLogin to yes.
    PermitRootLogin prohibit-password --> PermitRootLogin yes

    # 3. If you want to connect container without root password, change PermitEmptyPasswords to yes.
    PermitEmptyPasswords no --> PermitEmptyPasswords yes
If docker container's root need password to connect, please set new password.

1
2
# Input the root password.
passwd root
Finally, restart ssh service. `service ssh restart`
  1. If you docker run images without parameter ‘–net=host’, you need to set the port.

    1
    2
    # <local-host-port>:<container-ssh-port>
    docker run -p 22333:22 <image>
Mikoy Chinese wechat
Subscribe my public wechat account by scanning.

--------------------   ENDING   --------------------