Digging into ROS on the DeepRacer
So you have a DeepRacer, and you want to learn more about the software that’s on it, read on!
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 a set of software libraries and tools that help you build robot applications. It’s a staple in many 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. Begin by following the setup instructions.
After you’ve set up the wifi network, you can reconnect to the DeepRacer via your browser. Type in the IP address of your DeepRacer into your browser, and you’ll see 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->SSH.
Go ahead and click “enable” and set up your SSH password.
The default username is DeepRacer.
After you’ve enabled SSH, you can now log into your DeepRacer 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.
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 find where 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
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 this file:
- Sources the ROS Kinetic installation
- Sources the AWS DeepRacer installation
- Sets up the inference engine
- Sets up USB devices for access in python
- 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 will guess at their function.
- battery_node: A battery monitoring process
- control_node: The interface to the robot drive train that incorporates calibration
- inference_engine: ML inference engine for controlling the bot
- media_engine: Publishes camera data
- model_optimizer: Loads/compresses your model for the inference engine
- navigation_node: The interface to control commands
- rosout: default ROS system status
- servo_node: Low-level servo controller
- software_update: Update software/ml model
- web_video_server: Compress the video stream and serve it on a port
- webserver: Serve the webpage for the robot
If you want to learn more about any particular node, 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 of type
/rosout, which is the default ROS logging topic of
rosgraph_msgs/Log. It also subscribes to one topic –
/rl_results of 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
deepracer@amss-hd4i:/opt/aws/deepracer$ rostopic info /rl_results Type: inference_pkg/InferResultsArray Publishers: None Subscribers: * /navigation_node (http://amss-hd4i:38873/)
The output tells us that the type is
inference_pkg/InferResultsArray, that no
one is currently publishing to the topic, and that the
navigation_node is a
If you want to know more about the message, you can use
rosmsg show to see the
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
navigation_node also lists the services which (other than logging) are
Services, like topics, allow you to find out more information. But this time,
you’ll need to use the command
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 like topics, you can query the message format for a service using
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 connect, you will need ROS. 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
The password for
sudois the same as your SSH password.
Now on your computer, run my docker image with the following command:
docker run --network=host -it althack/ros:kinetic-dev bash
This command starts the docker image in an interactive terminal and shares the host network. You’ll want to share your network with the docker 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 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
Once the ROS master is set, you can do things like list, echo, and publish messages to topics to control your DeepRacer.
root@x1-carbon:/$ rostopic list /auto_drive /calibration_drive /manual_drive /rl_results /rosout /rosout_agg /video_mjpeg