Open main menu

Humanoid Robots Wiki β

Changes

CAN/IMU/Cameras with Jetson Orin

5,274 bytes added, 24 April
Created page with "The Jetson Orin is a development board from Nvidia. === CAN Bus === See [https://docs.nvidia.com/jetson/archives/r34.1/DeveloperGuide/text/HR/ControllerAreaNetworkCan.html h..."
The Jetson Orin is a development board from Nvidia.

=== CAN Bus ===

See [https://docs.nvidia.com/jetson/archives/r34.1/DeveloperGuide/text/HR/ControllerAreaNetworkCan.html here] for notes on configuring the CAN bus for the Jetson.

Install dependencies:

<syntaxhighlight lang="bash">
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt upgrade
sudo apt install g++ python3.11-dev
</syntaxhighlight>

Initialize the CAN bus on startup:

<syntaxhighlight lang="bash">
#!/bin/bash

# Set pinmux.
busybox devmem 0x0c303000 32 0x0000C400
busybox devmem 0x0c303008 32 0x0000C458
busybox devmem 0x0c303010 32 0x0000C400
busybox devmem 0x0c303018 32 0x0000C458

# Install modules.
modprobe can
modprobe can_raw
modprobe mttcan

# Turn off CAN.
ip link set down can0
ip link set down can1

# Set parameters.
ip link set can0 type can bitrate 1000000 dbitrate 1000000 berr-reporting on fd on loopback off
ip link set can1 type can bitrate 1000000 dbitrate 1000000 berr-reporting on fd on loopback off

# Turn on CAN.
ip link set up can0
ip link set up can1
</syntaxhighlight>

You can run this script automatically on startup by writing a service configuration to (for example) <code>/etc/systemd/system/can_setup.service</code>

<syntaxhighlight lang="text">
[Unit]
Description=Initialize CAN Interfaces
After=network.target

[Service]
Type=oneshot
ExecStart=/opt/kscale/enable_can.sh
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
</syntaxhighlight>

To enable this, run:

<syntaxhighlight lang="bash">
sudo systemctl enable can_setup
sudo systemctl start can_setup
</syntaxhighlight>

=== Cameras ===

==== Arducam IMX 219 ====

* [https://www.arducam.com/product/arducam-imx219-multi-camera-kit-for-the-nvidia-jetson-agx-orin/ Product Page]
* Shipping was pretty fast
* Order a couple backup cameras because a couple of the cameras that they shipped came busted
* [https://docs.arducam.com/Nvidia-Jetson-Camera/Nvidia-Jetson-Orin-Series/NVIDIA-Jetson-AGX-Orin/Quick-Start-Guide/ Quick start guide]

Run the installation script:

<syntaxhighlight lang="bash">
wget https://github.com/ArduCAM/MIPI_Camera/releases/download/v0.0.3/install_full.sh
chmod u+x install_full.sh
./install_full.sh -m imx219
</syntaxhighlight>

Supported kernel versions (see releases [https://github.com/ArduCAM/MIPI_Camera/releases here]):

* <code>5.10.104-tegra-35.3.1</code>
* <code>5.10.120-tegra-35.4.1</code>

Install an older kernel from [https://developer.nvidia.com/embedded/jetson-linux-archive here]. This required downgrading to Ubuntu 20.04 (only changing <code>/etc/os-version</code>).

Install dependencies:

<syntaxhighlight lang="bash">
sudo apt update
sudo apt install \
gstreamer1.0-tools \
gstreamer1.0-alsa \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav
sudo apt install
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev \
libgstreamer-plugins-bad1.0-dev
sudo apt install \
v4l-utils \
ffmpeg
</syntaxhighlight>

Make sure the camera shows up:

<syntaxhighlight lang="bash">
v4l2-ctl --list-formats-ext
</syntaxhighlight>

Capture a frame from the camera:

<syntaxhighlight lang="bash">
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! "video/x-raw(memory:NVMM), width=1280, height=720, framerate=60/1" ! nvvidconv ! jpegenc snapshot=TRUE ! filesink location=test.jpg
</syntaxhighlight>

Alternatively, use the following Python code:

<syntaxhighlight lang="bash">
import cv2

gst_str = (
'nvarguscamerasrc sensor-id=0 ! '
'video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! '
'nvvidconv flip-method=0 ! '
'video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! '
'videoconvert ! '
'video/x-raw, format=(string)BGR ! '
'appsink'
)

cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

while True:
ret, frame = cap.read()
if ret:
print(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break

cap.release()
cv2.destroyAllWindows()
</syntaxhighlight>

=== IMU ===

We're using the [https://ozzmaker.com/product/berryimu-accelerometer-gyroscope-magnetometer-barometricaltitude-sensor/ BerryIMU v3]. To use it, connect pin 3 on the Jetson to SDA and pin 5 to SCL for I2C bus 7. You can verify the connection is successful if the following command matches:

<syntaxhighlight lang="bash">
$ sudo i2cdetect -y -r 7
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- --
70: -- -- -- -- -- -- -- 77
</syntaxhighlight>

The equivalent command on the Raspberry Pi should use bus 1:

<syntaxhighlight lang="bash">
sudo i2cdetect -y -r 1
</syntaxhighlight>

The default addresses are:

* <code>0x6A</code>: Gyroscope and accelerometer
* <code>0x1C</code>: Magnetometer
* <code>0x77</code>: Barometer
488
edits