Lab 5 Phase 2

In the second phase of Lab 5, we will be using Robot
Operating System (ROS) in order to do both SLAM and path
planning on the car. After we setup the car’s control system,
we can then combine everything we have made thus far
using ROS and run it on the car.

Installing ROS on the Jetson

The first step to use ROS is to install it on the Jetson. You will likely
need to do some additional steps before that however. Open up
a terminal and run the following command:

uname -r

If the output is:

4.4.38

Then you will need to rebuild the Jetson TX2 kernel before installing ROS. If
you have a different number than the kernel version installed on your Jetson
does not need to be rebuilt. You may skip the next step if this is the case.

Rebuilding the Jetson TX2 Kernel

We need to rebuild the Jetson TX2 kernel in order to give support to the
sensors we are using in this lab. This includes both our IMU and the
RPLIDAR. Because our IMU connects to USB through FTDI we need to
include support for that at the kernel level. In order to do this change to
the Jetson’s home directory and clone the following repo.

cd
git clone https://github.com/jetsonhacks/buildJetsonTX2Kernel.git

Change into the directory and run the scripts getKernelSourcesNoGUI.sh,
makeKernel.sh, and copyImage.sh in that order.

cd buildJetsonTX2Kernel
./getKernelSourcesNoGUI.sh
./makeKernel.sh
./copyImage.sh

After running all the scripts the kernel will be rebuilt. At this point, you can reboot
the Jetson and start on installing ROS.

Installing ROS Kinetic

For the Jetson, we need to install the ROS distribution kinetic. Kinetic is the
distribution of ROS made for Ubuntu 16.04. It also has the largest available
open source package suite of all ROS distributions outside of ROS Indigo.
Typically, we would try and use docker to install software dependencies like ROS.
Unfortunately, that would make things fairly inconvenient for us, as we’d like
easy access to USB devices and network interfaces, and using a Docker container
adds an extra layer of complexity to this whole process. The Jetson also has a
different processor architecture that affects docker’s ability to run things. So
we don’t have easy access to a ROS container. Instead, we do a native
installation of ROS without docker. First, we will need to add all Ubuntu
repositories so the Jetson knows where to download ROS from. Run the
following command to add the universe, restricted, and multiverse
repositories:

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse" 
sudo apt-get update

After setting up the repositories we can finally install ROS kinetic onto the
Jetson. Run the following to install ROS.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt-get update
sudo apt-get install ros-kinetic-desktop
sudo rosdep init
rosdep update
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

ROS Tutorials

For the first part of the lab, you will need to go through the official ROS
tutorials. You can find them here. You only need to go through the
beginner ROS tutorials but they are fairly comprehensive in covering all of
the basic ROS concepts.

Installing ROS sensor packages

After installing ROS on the Jetson and going through the ROS tutorials,
you should be ready to get the RPLIDAR and IMU ready and sending
data through ROS. We will first setup the RPLIDAR.

Setting up a Catkin Workspace

Before we can work with the sensors we need to setup a catkin
workspace. Navigate to your home directory and create a workspace.

cd
mkdir -p catkin_ws/src
cd catkin_ws/src

We will later use the native ROS build tools within this workspace to make
a ROS package that can run all the modules for our car.

Installing the RPLIDAR ROS Node

In the src directory of our catkin workspace we will hold all of the
ROS packages we use on the car. In this case, we will first install the
RPLIDAR ROS Node. Clone the repo and then run catkin_make to build
the RPLIDAR node.

cd ~/catkin_ws/src
git clone https://github.com/Slamtec/rplidar_ros.git
cd ~/catkin_ws
catkin_make

This will build the RPLIDAR node. You can then run the following command
to bring up RVIZ and visualize the results of the RPLIDAR.

roslaunch rplidar_ros view_rplidar.launch

You can also run the following to see the RPLIDAR used in a test application.

roslaunch rplidar_ros rplidar.launch
rosrun rplidar_ros rplidarNodeClient

USB Devices

An important thing to keep track of here is the USB devices connected to the
Jetson. There are 7 port USB hubs you can use to extend the amount of
peripherals you can attach to the Jetson. Typically the way USB devices work
in Linux is by opening a logical file path where all the data from a USB device
is serially streamed to. There are two typical file paths that are used in Linux,
/dev/ttyUSB*and /dev/ttyACM* where the * star represents a number.
In my case, if I inspect these paths using ls I get the following:

ls /dev/ttyUSB*
/dev/ttyUSB0
ls /dev/ttyACM*
/dev/ttyACM0

On my Jetson, /dev/ttyUSB0 is the file corresponding to the LIDAR. The
filepath for the IMU is /dev/ttyACM0.

Install the Razor IMU ROS node

Flash the IMU Firmware

Before installing ROS IMU node you need to follow the hookup guide to properly
flash the firmware. It will also give you some more information about the sensor
itself that may come in handy.

Installing the ROS node

After following the hookup guide, you can follow the guide to install IMU ROS
node here. It includes 4 launch files to confirm that the IMU is working. One other
thing to note is that the default configuration searches for the IMU at
/dev/ttyUSB0 so you may need to change that value to whatever the logical
filepath is for the IMU on the Jetson.

Install Hector SLAM/Cartographer

You can now install the SLAM node in order to do SLAM on the robot. Again
everything you’ll need to setup it up is in the official ROS wiki
documentation. If both your IMU and RPLIDAR are publishing to the proper
ROS topics /imu and /LaserScan, you will now be able to inspect a map of the
car using RVIZ.

The .bag Format

ROS uses a file called a .bag in order to bundle various records of data. An example
ROS bag might include images and point clouds from a self-driving car going down
a highway.

Setting up Cartographer

You can install Cartographer by following the steps in the official documentation.
Getting cartographer running can be slightly tricky. You will need to have a proper config and launch file for the cartographer node to run properly. Luckily, Google has provided excellent documentation for this issue. I recommend
getting the demo running on a bag file.

Setting up Hector SLAM

To setup Hector SLAM you can clone the Hector SLAM repo into the src folder
of your catkin_ws and then run catkin_make in catkin_ws.

cd ~/catkin_ws/src
git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git
cd ..
catkin_make

You will need to setup a proper launch file for Hector SLAM. I recommend looking
at the launch files used at this Github if you are struggling with creating a good
launch file.

Install the Navigation Stack

You will now need to install the ROS Navigation stack in order to provide the
robot with a path planning module. Unlike most of the algorithms we
discussed in class, the navigation stack generates trajectories for
the car to take based on the obstacles it sees. The trajectory will then
generate a list of velocities and steering angles we can input
into our control system to drive the car. Unfortunately, because we do
not have a control algorithm ready for the car we can not take
advantage of the Navigation stack. However, you will need to
understand how it functions in order to integrate autonomous
control of the vehicle. Refer to the official documentation for the
navigation stack to become familiar with how it works. There are
certain sections in particular you should look at.

Note: In the map building section you can also generate these maps
using cartographer or hector SLAM. You may choose to do so as these
algorithms are more robust and may generate a higher fidelity map
of the arena.

Submission Details

Your lab 5 submission will simply be a checkoff to
demonstrate that you were able to get the sensor
packages running and could generate a map. Your
car group will need to submit a Google Drive link
to a ROS bag of the arena map and all point
cloud and IMU data used to create that map.