Jetson - MRoboSub/mrobosub GitHub Wiki

Post OS Flash Setup

These steps outline what you should do to setup the jetson after you have flashed it with a blank OS, ex. if you just flashed Linux and Jetson SDK onto a new ssd.

Setup IP

Once the Jetson is flashed you will need to setup a permanent IP address for it and SSH before you are able to connect to it from the base station, for these steps you will need to plug the Jetson into a monitor with a keyboard and mouse. Add steps (netplan, openssh-server)

Installing ROS and Setting Up Workspace

To install ROS follow the ROS installation guide on http://wiki.ros.org/noetic/Installation/Ubuntu and http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment. Note we use Catkin build as our build tool not catkin_make, if you get an error saying that Catkin is not a command you will need to also install sudo apt install python3-catkin-tools.

Additional Fixes

You may need to update symlink that the python command uses, you can check the version of this python by doing python --version, if this gives a version that is not our current (our current version is 3.8.10) then you will need to change this. You can also check python3 --version if this matches then you can simply change the symlink of the python command. To do this do the following commands which python sudo rm {output of which python}, sudo ln -s {output of which python3}, this should now set the python version to 3.8.10.

You will also have to clone the YOLO_v5 repository into the YOLO_v5 folder in the mrobosub_perception package, you can find this repo linked through the github.

You will also need to install the PID implementation that we use which you can find here http://wiki.ros.org/pid and can download via sudo apt-get install ros-noetic-pid.

Flashing

These steps outline how to flash the Jetson. This should only be done when using a new carrier board, or something is significantly wrong with the current Jetson. This will flash both the OS and the Jetson SDK (CUDA, etc).

Prerequisites

This guide assumes you are using a Jetson Xavier NX with the reComputer J202 carrier board, though in theory this should also work for similar carrier boards. It is also required that the carrier board has a M.2 Key M SSD installed (Seeed Studio recommends you buy their SSD for maximal compatibility with their carrier board). The OS will be flashed on the SSD; this is necessary because the Jetson's internal storage has little free space.

Initial flash

First we flash the OS to the internal storage of the Jetson, and later we will move it to the SSD.

Follow the Seeed Studio flashing guide for how to put the Jetson in recovery mode and flash it with the Jetson SDK Manager.

In Step 01 on the Jetson SDK Manager, choose Jetpack 5.02, as this installs Ubuntu 20.04 which is the most compatible with ROS Noetic.

In Step 02, only select "Jetson OS", and deselect "Jetson SDK Components". We only want to flash the OS at this stage, as the SDK components will likely not fit on the small internal storage.

Proceed with flashing. Once complete, take the Jetson out of recovery mode, reboot, and connect a monitor, keyboard, and mouse to it to log in.

Booting from the SSD

Once you log in to the Jetson, we will now copy the root file system (rootfs) to the SSD, and then configure the Jetson to boot from the SSD instead of the internal storage.

Clone the rootOnNVMe repository onto the Jetson. If you do not have internet access on the Jetson set up, you can copy the repository to it from the host machine. To do so, connect the ethernet and use scp (you will probably need to set the IP address on the Jetson as well).

Format the SSD as EXT4. You can do this through the "Disk" program on the Jetson (make sure you format the correct device). After formatting, follow the steps on the rootOnNVMe repository to copy the rootfs and switch boot to the SSD (basically just run ./copy-rootfs-ssd.sh and then ./setup-service.sh).

Once finished, reboot the Jetson. You should still be able to log in using the monitor. Run df -H to confirm that the root file system is now on the large SSD (look for the line that is mounted on /; this is the root file system, and it should be roughly the same size as the SSD).

Installing the Jetson SDK

Now that the root file system is on the sufficiently large SSD, we can install the Jetson SDK. This is needed to use CUDA and other tools.

Boot up the Jetson but do not put it into recovery mode. Connect it to the host and open the Jetson SDK Manager once again.

In Step 02 on the Jetson SDK Manager, only select "Jetson SDK Components", and deselect "Jetson OS", since we already flashed the OS and now just want to install the SDK.

In Step 03, choose to connect to the Jetson over Ethernet rather than USB. You will need to connect the Jetson to the host via Ethernet, and enter the Jetson's IP address in the prompt.

Proceed with installation. Once complete, you can run nvcc --version on the Jetson to confirm that CUDA is now installed.

Installing pytorch

Now that CUDA is installed, we can install and use pytorch.

The official Jetson docs has a guide on installing pytorch, however we will need a few modifications to it for our purposes. For us, the provided URL for the .whl is not correct; since we are on Jetpack 5.02, we need a URL with /v502/ in the path. Also, to use vision models, we probably also need to install torchvision at the same time.

With these corrections, we can install pytorch with the following commands:

$ export TORCH_INSTALL=https://developer.download.nvidia.com/compute/redist/jp/v502/pytorch/torch-1.13.0a0+936e9305.nv22.11-cp38-cp38-linux_aarch64.whl
$ pip install --no-cache $TORCH_INSTALL torchvision==0.14

NOTE: It is important that we install both torch and torchvision using the same command like this because it allows the correct version of torchvision corresponding to the version of torch to be found. If we tried just installing torch first, and then separately installing torchvision with pip install torchvision, this would replace our torch version and install the newest version of torchvision, which is not what we want.

To confirm that pytorch installed successfully, you can enter a Python interpreter with python3 and then try import torch and import torchvision.

Torch on the Nano

If you are using the Nano for some reason, you might run into a lib issue when running yolov5. This might help

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1

System Setup

This guide is for setting up key components on a Jetson that has already been flashed.

Shutdown

Some of the scripts require the jetson user to run the /sbin/shutdown command without needing authentication. To do this, first add a shutdown group using

$ sudo groupadd shutdown

Then, add the jetson user to the shutdown group by running

$ sudo vim /etc/group

Add scrolling to the line starting with shutdown, simply adding jetson to the end. The line should look something like shutdown:x:NNN:jetson where NNN is some number.

Then, we need to allow the shutdown group privileges to run the sbin/shutdown command from root, by running visudo and adding the following line to the file

%shutdown ALL=(root) NOPASSWD: /sbin/shutdown

Now the jetson user can run sudo shutdown ... and not need to enter a password.

Bringup

Use the robot_upstart package to run a launch file on boot

$ sudo apt install ros-noetic-robot-upstart
$ rosrun robot_upstart install <pkg>/launch/<file>.launch --job <service_name> --symlink
$ sudo systemctl daemon-reload
$ sudo systemctl start <service_name>

Then edit the service script with

$ sudo vim /usr/sbin/<service_name>-start

Find the line with export ROS_HOSTNAME=$(hostname) and replace it with export ROS_IP=192.168.2.3

GPIO

Bringup as currently written relies on GPIO. In order to run GPIO code, regular users need read/write access to /dev/gpiomem

$ chmod o+rw /dev/gpiomem

To permanently allow this

$ sudo usermod -a -G dialout $USER
$ sudo apt install rpi.gpio-common

Persistent Bottom Camera Device Name

In /etc/udev/rules.d, add a file named 25-myvideorules.rules with the following content

SUBSYSTEM=="video4linux", ATTRS{name}=="H264 USB Camera: USB Camera", ATTRS{index}=="0", SYMLINK+="botcam"

If the name of the camera is different, find it by running

udevadm info -a -p $(udevadm info -q path -p /class/video4linux/video0)

Where video0 is the capture device name under /dev (for example, /dev/video0)

Then restart or run

sudo udevadm control --reload-rules && udevadm trigger

The camera will now be available under /dev/botcam

Submodule init

We use git submodules for yolo and inertial-sense-sdk. Submodules are not cloned when the repo is cloned, so run

git submodule update --init --recursive

to download all submodules

YoloV5 setup

The yolov5 repository is provided as a git submodule in mrobosub_perception/yolov5. Run pip install -r requirements.txt in this folder. Unfortunately this may replace torch and torchvision with incorrect versions; if so, repeat the steps for installing pytorch. You can probably get around this by removing the lines for torch and torchvision in the requirements.txt before installing.

Note: it is important that the repo is at git hash 3e55763d45f9c5f8217e4dad5ba1e6c1f42e3bf8. Using the latest version may result in an error such as TypeError: 'weights_only' is an invalid keyword argument for Unpickler().

Boot options [old]

The jetson now has 2 boot options. You can use the old SD card labeled as Xavier backup or the new, faster(?), boot option. Default will be the new faster method.

To switch to the old boot:

Plug the sd card into the SD card slot on the carrier board.

Run df -h and see and see the options available.

Usually the secondary sd card will be /dev/mmcblk1p1.

Copy the address above

Run sudo vim /boot/extlinux/extlinux.conf

You will then edit the line with APPEND change root=/dev/mmcblk0p1 to root=/dev/mmcblk1p1

Reboot and you will now be booted into the SD card

Switching back to internal memory boot

Run df -h. If you do not see the internal memory launch disk and mount the 16gb sd card reader

Run sudo vim /media/mrobosub/{random_assigned_name}/boot/extlinux.conf

You will then edit the line with APPEND change root=/dev/mmcblk1p1 to root=/dev/mmcblk0p1

Reboot and you will now be booted into the internal memory

Misc commands (will sort later)

sudo apt install libudev1 libudev-dev v4l-utils
ln ~/catkin_ws/src/mrobosub/.bash_aliases ~/.bash_aliases

Reflashing the Jetson [old]

https://wiki.seeedstudio.com/reComputer_A205_Flash_System/

(Hopefully, you never need this)

This is the guide to booting the Jetson with internal memory, the guide also links to setting up the SD card slot. The current setup is that all python packages are downloaded to the sd card via changing PYTHONPATH.

⚠️ **GitHub.com Fallback** ⚠️