Getting Started with Robotic Operating System (ROS) and JetRacer AI Kit

There is nothing more fun and interesting than learning ROS together with JetRacer AI Kit!

Introduction

JetRacer is the AI Racing Robot powered by Nvidia Jetson Nano Developer Kit. It supports deep learning, auto line following, autonomous driving and so on. Thus, it is the best place for you to start learning about AI application where you can see how the trained model being applied to the physical world.

Meanwhile, when we talked about robotics applications, especially those involved in the multi-sensory autonomous robots, Robotic Operating System (ROS) is the natural choice for many. We all know that getting started with ROS is actually very challenging due to the steep learning curve of ROS. Therefore, why not we make the learning process more fun by directly applying what we learnt into the physical robot instead of just using simulation?

In this tutorial, we will cover all the steps needed for setting up JetRacer to run with ROS Melodic. You can refer to this tutorial to see how well can Jetson Nano run the simulations in ROS.

Note: This tutorial assumes that you have already gone through the JetRacer notebook. Please refer to Getting Started with JetRacer AI Kit tutorial if you haven’t do so.

Contents

Hardware Requirements

Note: You can also use Jetson Nano 2GB for running ROS in JetRacer. However, keep in mind that there will be some minor incompatibility such as no display on the Expansion Board’s LCD and the lack of M.2 Key E slot for Wi-Fi and Bluetooth module.

Software Requirements

We will be using the original Operating System provided by Nvidia (JetPack) instead of the Jetcard image given by Waveshare for the JetRacer AI Kit. This is because currently there is no way to enable desktop interface with the Jetcard image provided (see this issue), hence, it will be very inconvenient to setup and run ROS in headless mode with the Jupyter Lab.

Here is the OS version that is being used in this tutorial. You can follow the hyperlinks below to setup your Jetson Nano.

Jetson Nano 4GB: JetPack 4.4 / NVIDIA L4T 32.4.3 / Ubuntu 18.04
Jetson Nano 2GB: LXDE 18.04

Setting Up

Since that we are building the JetRacer from scratch, there are many libraries needed to be installed. Follow closely to the steps below.

We will first started by installing pip and yaml for python3 as well as some installation tools and libraries Open up a terminal and enter the following command:

$ sudo apt-get install python3-pip python3-yaml
$ pip3 install setuptools traitlets getkey

After that, we will install PyGame in the Jetson Nano by building from source:

$ sudo apt install libsdl1.2-dev python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev libfreetype6-dev
$ cd ~
$ git clone https://github.com/takluyver/pygame.git
$ cd pygame
$ sudo python3 setup.py install

Honestly, I have no idea what the packages on the first line are needed for, but they are necessary for the installation to get done. To verify the installation, enter the following command:

$ python3
>>> import pygame
>>> print(pygame.__version__)
1.9.3
>>> exit()

Next we will install the Jetcam library so that we can access to the CSI camera:

$ cd ~
$ git clone https://github.com/NVIDIA-AI-IOT/jetcam
$ cd jetcam
$ sudo python3 setup.py install

Proceed to the JetRacer package installation from Waveshare:

$ cd ~
$ git clone https://github.com/waveshare/jetracer
$ cd jetracer
$ sudo python3 setup.py install

Installing the Waveshare UPS Power Module library for the LCD display on the Expansion Board:

$ cd ~
$ git clone https://github.com/waveshare/UPS-Power-Module
$ cd UPS-Power-Module
$ ./install.sh <password>

Take note that you have to change the <password> on the scripts above into the password you used to log in into the Jetson Nano. Once you have completed the installation, the LCD on the Expansion Board should displaying some information. However, keep in mind that the display will get glitched at times as the library we installed is not originally created for the JetRacer’s Carrier Board. 

Moving on, we need to setup ROS Melodic on the Jetson Nano. Kindly follow the ROS official guide from the links below:

  1. ROS Melodic Installation for Ubuntu (You can choose to install either the Desktop or Desktop-Full version).
  2. Create ROS Workspace (Catkin)

Verify your installation by running “roscore” on the terminal to see if there is any error or not. After that, we have to add the the catkin workspace into .bashrc so that it source the workspace automatically:

$ gedit ~/.bashrc

Add this line at the bottom of the file:

source ~/catkin_ws/devel/setup.bash

Restart the terminal to apply the changes. To install Python 3 support for ROS:

$ sudo pip3 install rospkg catkin_pkg
$ sudo apt-get install python-catkin-tools python3-dev python3-numpy

Download the examples to control JetRacer with ROS:

$ cd ~/catkin_ws/src
$ git clone https://github.com/CytronTechnologies/cytron_jetracer.git
$ cd cytron_jetracer/scripts
$ chmod +x camera.py joint_state.py racecar.py teleop.py teleop_gamepad.py
$ cd ~/catkin_ws
$ catkin_make

That’s all we needed to setup the JetRacer AI Kit! Proceed to the next section for running the examples.

Running the Examples

We all know that running ROS requires many tabs of terminal. Therefore, here’s a great tool for you to do that:

$ sudo apt-get install terminator
$ terminator

You can create more tabs on the Terminator by right clicking on the window and select “split horizontally / vertically”. We have everything properly setup. Now, let’s start running the examples.

$ roscore

Next, we can run the racecar.py script. This script creates a subscriber node which controls the steering and throttle of the JetRacer based on the data obtained from the topics. Open up a new terminal and enter the command below:

$ rosrun cytron_jetracer racecar.py

The teleop.py script allows us to control the JetRacer via keyboard. You can refer to the printed information on the terminal for the control instructions. Open up a new terminal and enter the command below:

$ rosrun cytron_jetracer teleop.py

The teleop_gamepad.py script can be used to control the JetRacer by using the gamepad. Open up a new terminal and enter the command below:

$ rosrun cytron_jetracer teleop_gamepad.py

You need to plug in the receiver on the Jetson Nano and make sure that the gamepad is in PS3 mode. Run the gamepad tester to see if your gamepad is working properly. To switch the mode of the gamepad, press the home button for 5 seconds.

You can also tune your JetRacer at the tuning section of the racecar.py script:

$ roscd cytron_jetracer/scripts
$ gedit racecar.py

We can also enable the live streaming from the camera by running the camera.py script. Open up a new terminal and enter the command below:

$ rosrun cytron_jetracer camera.py

By default, the IP address of the http server is set to localhost. Open up an internet browser in the Jetson Nano and enter “localhost:5000” on the search bar. You should be able to view the output similar to the image below:

If you want to access the live streaming from other device, you have to change the output IP address of the http server:

$ ifconfig

Take note of your JetRacer’s IP address at the inet section.

Then, you have to edit the IP address inside the camera.py script.

$ roscd cytron_jetracer/scripts
$ gedit camera.py

Now we have all the examples running. Lets take a look at the current structure of the nodes and topics by using the rqt graph tools:

$ rosrun rqt_graph rqt_graph

As you can see the structure of this example is very simple. We have two publishers sending the same topics, that are, steering and throttle. Meanwhile, the racecar subscriber will listens to these 2 topics and control the steering and throttle of the JetRacer accordingly.

Running RViz Visualization Tool

In this example, a simple robot model is developed in Unified Robot Description Format (URDF) being built with Xacro which is an XML macro language. The model is then being parsed and visualized in RViz. To launch the RViz example, open a new terminal and enter the following command:

$ roslaunch cytron_jetracer rviz.launch

A RViz window will be launched and you should be able to see a simple robot model. You can move the robot by using the teleop scripts as discussed previously. 

Now, refresh the rqt_graph and see the current structure of the nodes and topics.

The “joint_state_publisher” is being created by the “joint_state.py” script. What the script does is it reads the data from “steering” and “throttle” topics and convert them to the joints data (published as joint_states). Then, the “robot_state_publisher” package will publish the state of the robot into tf2 and finally being shown in RViz.

Feel free to open up the source code and look at how all of these are made possible. You can locate them by using “roscd cytron_jetracer/scripts” or find them at “~/catkin_ws/src/cytron_jetracer/scripts”. Refer to the ROS tutorials to learn more about the basics of ROS.

Conclusion

Hope you have enjoyed learning ROS in this tutorial. There’s a lot more you can do by using ROS with the JetRacer AI Kit. How about training the JetRacer with the interactive_regression notebook and then implement the model into ROS? That will be very cool to see AI taken into action in ROS!

References

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top