Allison Thackston


Digging into ROS on the DeepRacer

So you have a deep racer and you want to learn more about the software that’s on it, read on!

ROS Kinetic

ros kinetic

At the time of this writing, the DeepRacer runs ROS Kinetic. The Robot Operating System (ROS) isn’t really an operating system, it’s more like a software development kit (SDK). It’s comprised of a set of software libraries and tools that help you build robot applications. It’s a staple in a lot of university programs in Robotics and it is easy to add new packages to share with the world. Best of all, it’s all open source.

ROS Kinetic is the long term support (LTS) version of ROS that works with Ubuntu Xenial 16.04. Its support ends in April 2021, so I hope that Amazon is planning on releasing an update!

Setting up the DeepRacer

The first thing you’ll do when setting up your DeepRacer is to connect it to your computer so you can set up its wifi. You should begin by following the setup instructions.

After the wifi network has been set up, you can reconnect to the DeepRacer via your browser. Just type in the IP address of your deep racer into your browser and you’ll be presented with the vehicle control and settings.

To interface with ROS instead of using the web console, you’ll need to enable SSH. Inside the DeepRacer console, click on settings then SSH.

deepracer ssh

Go ahead and click “enable” and set up your SSH password.

Note that the default username is DeepRacer.

After you’ve enabled SSH, you can now log into your deep racer from the terminal.

export DEEPRACER_IP=<the IP address>
ssh deepracer@$DEEPRACER_IP

When it asks you for a password, enter the one you created on the webpage.

Note: this password is different from the default password to log into the DeepRacer console webpage.

Now you can start exploring the software that’s running

Exploring the software

The first thing I did was to find where all the software was. Since ROS is normally installed into the /opt directory, that’s the first place I looked.

deepracer@amss-hd4i:~$ cd /opt
deepracer@amss-hd4i:/opt$ ls
aws  ros

As you can see, we have the base ROS installation in ros and a custom aws folder. Let’s see what’s in there!

deepracer@amss-hd4i:/opt$ cd aws/
deepracer@amss-hd4i:/opt/aws$ ls
deepracer  intel  pyudev
deepracer@amss-hd4i:/opt/aws$ cd deepracer/
deepracer@amss-hd4i:/opt/aws/deepracer$ ls
artifacts            env.sh           password.txt    setup.zsh                    token.txt
brazil-npm-registry  led_values.json  setup.bash      share                        util
calibration.json     lib              setup.sh        software_update_status.json
camera               nginx            _setup_util.py  start_ros.sh

There’s a suspiciously titled start_ros.sh script in this directory that probably tells us a whole lot about how the software is started. The contents of this file are:

source /opt/ros/kinetic/setup.bash
source /opt/aws/deepracer/setup.bash
source /opt/aws/intel/dldt/bin/setupvars.sh
export PYTHONPATH=/opt/aws/pyudev/pyudev-0.21.0/src:$PYTHONPATH
roslaunch deepracer_launcher deepracer.launch

Here, we can see that this file:

  1. Sources the ROS Kinetic installation
  2. Sources the AWS DeepRacer installation
  3. Sets up the inference engine
  4. Sets up USB devices so they can be accessed through python
  5. Launches the software suite.

After sourcing the Kinetic and DeepRacer installations, we can now run DeepRacer ROS commands.

There are a couple of commands that let you introspect the ROS software system. The first we are going to use is the rosnode list command. This command will print all of the ROS programs that are running.

deepracer@amss-hd4i:/opt/aws/deepracer$ rosnode list
/battery_node
/control_node
/inference_engine
/media_engine
/model_optimizer
/navigation_node
/rosout
/servo_node
/software_update
/web_video_server
/webserver

Since there isn’t any documentation on the ROS nodes running, I’m going to guess at their function.

If you want to learn more about any particular node, just enter rosnode info <node_name>

For example, if you want to know more about the navigation node:

deepracer@amss-hd4i:/opt/aws/deepracer$ rosnode info /navigation_node
--------------------------------------------------------------------------------
Node [/navigation_node]
Publications:
 * /auto_drive [ctrl_pkg/ServoCtrlMsg]
 * /rosout [rosgraph_msgs/Log]

Subscriptions:
 * /rl_results [unknown type]

Services:
 * /load_action_space
 * /navigation_node/get_loggers
 * /navigation_node/set_logger_level
 * /navigation_throttle


contacting node http://amss-hd4i:38873/ ...
Pid: 2996
Connections:
 * topic: /auto_drive
    * to: /control_node
    * direction: outbound
    * transport: TCPROS
 * topic: /rosout
    * to: /rosout
    * direction: outbound
    * transport: TCPROS

You can see that it publishes two topics – /auto_drive which is of type ctrl_pkg/ServoCtrlMsg and /rosout which is the default ROS logging topic of type rosgraph_msgs/Log. It also subscribes to one topic – /rl_results which is reporting an unknown type. ROS will sometimes report topic types as unknown when no module is publishing them.

If you want to know more about that topic, you can use rostopic info.

deepracer@amss-hd4i:/opt/aws/deepracer$ rostopic info /rl_results
Type: inference_pkg/InferResultsArray

Publishers: None

Subscribers:
 * /navigation_node (http://amss-hd4i:38873/)

This tells us the type is actually inference_pkg/InferResultsArray and that no one is currently publishing to the topic, although the navigation_node is subscribed to it.

If you want to know more about the message, you can use rosmsg show to see the message format

 deepracer@amss-hd4i:/opt/aws/deepracer$ rosmsg show inference_pkg/InferResultsArray
inference_pkg/InferResults[] results
  int32 classLabel
  float32 classProb
  float32 xMin
  float32 yMin
  float32 xMax
  float32 yMax
sensor_msgs/Image img
  std_msgs/Header header
    uint32 seq
    time stamp
    string frame_id
  uint32 height
  uint32 width
  string encoding
  uint8 is_bigendian
  uint32 step
  uint8[] data

The navigation_node also lists the services which (other than logging) are /load_action_space and /navigation_throttle.

Services, like topics, allow you to find out more information. But this time you’ll need to use the command rosservice info

deepracer@amss-hd4i:/opt/aws/deepracer$ rosservice info /load_action_space
Node: /navigation_node
URI: rosrpc://amss-hd4i:38519
Type: inference_pkg/LoadModelSrv
Args: artifactPath taskType preProcessType

And also, like topics you can query the message format for a service using rossrv show

deepracer@amss-hd4i:/opt/aws/deepracer$ rossrv show inference_pkg/LoadModelSrv
string artifactPath
int8 taskType
int8 preProcessType
---
int32 error

Connecting to another computer

One of the biggest advantages of ROS is being able to connect to other computers on your network. To do this, you will need ROS installed on the other computer, or you can use my docker image to get started quickly.

But since ROS uses ephemeral ports to connect nodes, you’ll need to first disable the firewall on the DeepRacer with the following command:

deepracer@amss-hd4i:/opt/aws/deepracer$ sudo ufw disable

Note the password for sudo is the same as your SSH password

Now on your computer, run my docker image with the following command:

docker run --network=host -it athackst/ros:kinetic-dev bash

This starts my docker image in an interactive terminal and shares your network with the image. You’ll want to share your network with the image for the same reason you needed to disable the firewall.

Now all you need to do is set the ROS_MASTER_URI to your DeepRacer. This is done simply through an environment variable.

root@x1-carbon:/$ export ROS_MASTER_URI=http://$DEEPRACER_IP:11311

Don’t forget to add the 11311 for the port the rosmaster host is listening to!

Once the ROS master has been set, you can do things like list, echo, and publish to topics to control your DeepRacer.

root@x1-carbon:/$ rostopic list
/auto_drive
/calibration_drive
/manual_drive
/rl_results
/rosout
/rosout_agg
/video_mjpeg