Posted

OS image:

Linux 4.9.337-tegra #1 SMP PREEMPT Thu Jun 8 21.19:14 PDT 2023 aarch64 aarch64 aarch64 GNU/Linux
Ubuntu 18.04.6 LTS (Bionic Beaver)
NVIDIA Jetson Nano Developer Kit - Jetpack 4.6.4 [L4T 32.7.4]

Ref:

  1. https://www.stereolabs.com/en-th/blog/ros-and-nvidia-jetson-nano

Setup:

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://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc $ source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo rosdep init 
rosdep update
sudo apt-get install cmake python-catkin-pkg python-empy python-nose python-setuptools libgtest-dev python-rosinstall python-rosinstall-generator python-wstool build-essential git
mkdir -p ~/catkin_ws/src 
cd ~/catkin_ws/
catkin_make
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc 
source ~/.bashrc

Author

Posted

OS image:

Debian GNU/Linux 12 (bookworm) aarch64
Linux raspberrypi 6.6.62+rpt-rpi-2712 SMP PREEMPT Debian 1:6.6.62-1+rpt1 (2024-11-25)

Ref:

  1. https://www.gtk.org/docs/language-bindings/python/
  2. https://pygobject.gnome.org/getting_started.html#ubuntu-getting-started
  3. https://python-gtk-3-tutorial.readthedocs.io/en/latest/

Setup:

sudo apt update
sudo apt install libopenblas-dev libblas-dev m4 cmake python3-dev python3-yaml python3-setuptools
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-4.0
sudo apt install at-spi2-core
sudo rm /usr/lib/python3.*/EXTERNALLY-MANAGED
sudo pip install cython

First Run:

Create new pyscript and,

import gi
gi.require_version('Gtk','4.0')
from gi.repository import Gtk,Gdk,GLib
import threading
import time
import sys
class MyApp(Gtk.Application):
    def __init__(self):
        super().__init__(application_id="com.example.myapp")
        GLib.set_application_name("MyApp")  
        self.bgevt = threading.Event()
        self.bgthread = threading.Thread(target=loop_sleep,args=(self.bgevt,))
        self.bgthread.start()
    def do_activate(self):
        self.win = Gtk.ApplicationWindow(application=self,title="Dance Box Set v0.0.1")
        self.win.present()
def loop_sleep(evt):
    i = 1
    while not evt.is_set():
        print(i)
        i = i+1
        time.sleep(0.5)
def loop_shutdown(app):
    app.bgevt.set()
app = MyApp()
app.connect("shutdown",loop_shutdown)
ex = app.run(sys.argv)
sys.exit(ex)

Author

Posted

OS Image:

Linux ubuntu 5.15.0-1070-raspi #73-Ubuntu SMP PREEMPT Thu Dec 19 17:56:10 UTC 2024 aarch64 aarch64 GNU/Linux
Ubuntu 22.04.5 LTS (Jammy Jellyfish)

Ref:

  1. https://www.unitree.com/LiDAR
  2. https://github.com/unitreerobotics
  3. https://github.com/unitreerobotics/unilidar_sdk/blob/main/unitree_lidar_ros2/src/unitree_lidar_ros2/README.md
  4. https://github.com/unitreerobotics/point_lio_unilidar
  5. https://docs.ros.org/en/foxy/How-To-Guides/Installing-on-Raspberry-Pi.html
  6. https://roboticsbackend.com/install-ubuntu-on-raspberry-pi-without-monitor/
  7. https://roboticsbackend.com/install-ros2-on-raspberry-pi/
  8. https://linuxconfig.org/ubuntu-22-04-connect-to-wifi-from-command-line
  9. https://github.com/unitreerobotics/unilidar_sdk2
  10. https://github.com/dfloreaa/point_lio_ros2

Setup Ubuntu:

sudo apt update
sudo apt install net-tools
sudo apt install htpdate
sudo timedatectl set-timezone Asia/Bangkok
sudo apt install zram-config
sudo apt install ubuntu-desktop
sudo reboot
sudo vi /boot/firmware/config.txt
{
dtoverlay=vc4-fkms-v3d
max_framebuffer_height=1920
max_usb_current=1
hdmi_mode=87
extra_transpose_buffer=2
over_voltage=4
arm_freq=1850
v3d_freq=650
gpu_freq=650
hdmi_enable_4kp60=1
hdmi_force_hotplug=1
max_framebuffers=2
gpu_mem=512
}
sudo swapon --show
sudo swapoff -a
sudo rm /swapfile
sudo fallocate -l 5G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo reboot
sudo vcgencmd get_mem gpu
sudo free -h
sudo add-apt-repository universe
sudo apt update
sudo apt install build-essential software-properties-common -y
sudo apt install libopenblas-dev libblas-dev m4 cmake python3-dev python3-yaml python3-setuptools git
sudo apt update 
sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

Install ROS core:

sudo apt update
sudo apt upgrade
#sudo apt install ros-humble-ros-base
sudo apt install ros-humble-desktop
sudo apt install python3-colcon-common-extensions
sudo apt install ros-humble-example-interfaces

Setup ROS2 environment:

source /opt/ros/humble/setup.bash
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

Setup Unitree LidarL1 sdk:

sudo apt install ros-humble-pcl-ros
sudo apt install ros-humble-pcl-conversions
sudo apt install ros-humble-visualization-msgs
sudo apt install libeigen3-dev
git clone https://github.com/unitreerobotics/unilidar_sdk.git
cd unilidar_sdk/unitree_lidar_ros2
colcon build
cd unilidar_sdk/unitree_lidar_ros2
source install/setup.bash
ros2 launch unitree_lidar_ros2 launch.py
sudo su
free -h && sync && echo 3 > /proc/sys/vm/drop_caches && free -h
exit

Setup Livox ROS Driver 2:

cd ~
git clone https://github.com/Livox-SDK/Livox-SDK2.git
cd ./Livox-SDK2/
mkdir build
cd build
cmake .. && make -j
sudo make install
cd ~
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2
cd ./ws_livox/src/livox_ros_driver2
source /opt/ros/humble/setup.sh
./build.sh humble
source ~/ws_livox/install/setup.bash
ros2 launch livox_ros_driver2 rviz_HAP_launch.py

Setup Point-LIO-ROS2:

RUN:

Author

Posted

Source

An jetson-inference lib. provided by Dystin Franklin (github)

Revising glDisplay

Add below code to file “/jetson-inference/utils/display/glDisplay.cpp”, lines~1367

LogInfo(LOG_GL "glDisplay -- event KEY_STATE %i %s (%s)\n", a, XKeysymToString(a), b ? "pressed" : "released");
display->mKeyStates[a] = (b == KEY_PRESSED)?1:0;
display->mCurKeyChar = (b == KEY_PRESSED)?(char)a:0;

Change encapsulation of mKeyState[] as public in file “/jetson-inference/utils/display/glDisplay.h”,lines~589 (move from line~683)

bool     mKeyStates[1024];
char     mCurKeyChar = 0;

Add following method to get key state, line~427

inline bool GetKeyI( int key ) const { return mKeyStates[key]; }
inline char GetCurKeyChar() const { return mCurKeyChar; }

Usage

Put this code in main func. of program

if(output->IsType<glDisplay>())
{
	glDisplay* dis = (glDisplay*)output;
	LogInfo(LOG_COLOR_YELLOW "Mouse-pos x,y & key: %u,%u,%u\n",dis->GetMousePosition()[0],dis->GetMousePosition()[1],dis->GetKeyI(XK_a));
}

Result

Author
Categories C++, Nvidia Jetson Nano

Posted

ติดตั้ง Jetson Nano DevKit

(link)
** พื้นที่ disc ที่ใช้หลังติดตั้งทั้งหมด ~36G ควรใช้ microSD ขนาด 64G

Update python3.8

sudo apt-get update
sudo apt-get search python3 | grep "python3\."
sudo apt-get install python3.8
sudo apt-get install binutils
sudo apt-get install python-pip python3-pip
sudo update-alternatives --list python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
sudo update-alternatives --list python3
sudo update-alternatives --config python
sudo vi /usr/bin/gnome-terminal #/usr/bin/python3 to /usr/bin/python3.6
sudo reboot
python3

Build OpenCV

Enlarge memory swap

sudo apt-get update
sudo apt-get upgrade
#install dphys-swapfile
sudo apt-get install dphys-swapfile
sudo vi /sbin/dphys-swapfile
#enlarge CONF_MAXSWAP=4096
sudo vi /etc/dphys-swapfile
#give CONF_SWAPSIZE=4096
sudo reboot

Setup dependencies

sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf"
sudo ldconfig
sudo apt-get install build-essential cmake git unzip pkg-config zlib1g-dev
sudo apt-get install libjpeg-dev libjpeg8-dev libjpeg-turbo8-dev
sudo apt-get install libpng-dev libtiff-dev libglew-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev libcanberra-gtk*
sudo apt-get install python-dev python-numpy python-pip
sudo apt-get install python3-pip python3.8-dev
sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev libxine2-dev
sudo apt-get install gstreamer1.0-tools libgstreamer-plugins-base1.0-dev
sudo apt-get install libgstreamer-plugins-good1.0-dev
sudo apt-get install libv4l-dev v4l-utils v4l2ucp qv4l2
sudo apt-get install libtesseract-dev libxine2-dev libpostproc-dev
sudo apt-get install libavresample-dev libvorbis-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev
sudo apt-get install liblapack-dev liblapacke-dev libeigen3-dev gfortran
sudo apt-get install libhdf5-dev libprotobuf-dev protobuf-compiler libprotoc-dev
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install ffmpeg libavutil-dev libavdevice-dev libavfilter-dev
sudo python3 -m pip install ONNX
sudo python3 -m pip install numpy

Download OpenCV

cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.8.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.8.0.zip
# unpack
unzip ./opencv.zip
unzip ./opencv_contrib.zip
# some administration to make live easier later on
mv ./opencv-4.8.0 ./opencv
mv ./opencv_contrib-4.8.0 ./opencv_contrib
# clean up the zip files
rm -f ./opencv.zip
rm -f ./opencv_contrib.zip

Build make

cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_PROTOBUF=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..
make -j4
sudo rm -r /usr/include/opencv4/opencv2
sudo make install
sudo ldconfig
# cleaning (frees 300 MB)
make clean
sudo apt-get update
python3 -m pip install opencv-contrib-python
python3 -m pip install imutils
python3 -m pip install screeninfo
python3 -m pip install schedule
python3 -m pip install pyModbusTCP #optional
python3 -m pip install pymodbus #optional

Build & Install PyTorch

Update cmake (>=3.13)

sudo apt-get install -y software-properties-common lsb-release
sudo wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
sudo vi /usr/bin/apt-add-repository #change /usr/bin/python3.6
sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install -y cmake

Download Pytorch

git clone -b v1.11.0 --depth 1 --recursive --recurse-submodules --shallow-submodules https://github.com/pytorch/pytorch.git
cd pytorch
python3 -m pip install -r requirements.txt
wget https://raw.githubusercontent.com/otamajakusi/build_jetson_nano_libraries/main/pytorch/pytorch-1.11-jetson.patch
patch -p1 < pytorch-1.11-jetson.patch
export BUILD_CAFFE2_OPS=OFF
export USE_FBGEMM=OFF
export USE_FAKELOWP=OFF
export BUILD_TEST=OFF
export USE_MKLDNN=OFF
export USE_NNPACK=OFF
export USE_XNNPACK=OFF
export USE_QNNPACK=OFF
export USE_PYTORCH_QNNPACK=OFF
export USE_CUDA=ON
export USE_CUDNN=ON
export TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
export USE_NCCL=OFF
export USE_SYSTEM_NCCL=OFF
export USE_OPENCV=ON
export MAX_JOBS=2
# set path to ccache
export PATH=/usr/lib/ccache:/usr/local/cuda/bin:$PATH
# set clang compiler
export CC=clang
export CXX=clang++
python3 ./setup.py bdist_wheel  #(~12 ชั่วโมง)
find dist/*.whl -type f | xargs python3 -m pip install

Build & Install TorchVision

cd ~
git clone --depth=1 https://github.com/pytorch/vision torchvision -b v0.12.0
cd torchvision
export TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
export FORCE_CUDA=1
export MAX_JOBS=2
python3 ./setup.py bdist_wheel  #(~15 นาที)
find dist/*.whl -type f | xargs python3 -m pip install

Install Ultralytics

cd ~
python3 -m pip install ultralytics

Build & Install Jetson-Inference

cd ~
git clone --recursive --depth=1 https://github.com/dusty-nv/jetson-inference
cd jetson-inference
mkdir build
cd build
cmake ..
make -j4    #(~5 mins.)
sudo make install
sudo ldconfig

Build & Install Open3D

cd
git clone https://github.com/isl-org/Open3D
cd ./Open3D
sudo ./util/install_deps_ubuntu.sh
mkdir build
cd build
cmake -DBUILD_CUDA_MODULE=ON -DBUILD_GUI=ON ..
make -j4    #(~5 hrs.)
make install-pip-package -j4
# Test C++ viewer app
./Open3D/Open3D

Build & Install TorchAudio

cd ~
git clone -b release/0.10 https://github.com/pytorch/audio.git torchaudio
cd torchaudio
export USE_FBGEMM=OFF
export BUILD_CAFFE2_OPS=OFF
export USE_FAKELOWP=OFF
export BUILD_TEST=OFF
export USE_MKLDNN=OFF
export USE_NNPACK=OFF
export USE_XNNPACK=OFF
export USE_QNNPACK=OFF
export USE_PYTORCH_QNNPACK=OFF
export USE_CUDA=ON
export USE_CUDNN=ON
export TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
export USE_NCCL=OFF
export USE_SYSTEM_NCCL=OFF
export USE_OPENCV=ON
export MAX_JOBS=4
export PATH=/usr/lib/ccache:$PATH
# set clang compiler
export CC=clang
export CXX=clang++
export CUDACXX=/usr/local/cuda-10.2/bin/nvcc
vi ./CMakeLits.txt #change CMAKE_CXX_STANDARD 14
python3 setup.py clean
python3 setup.py bdist_wheel
find dist/*.whl -type f | xargs python3 -m pip install

Check the installation

python3
import torchaudio
print(torchaudio.__version__)

Author
Categories Nvidia Jetson Nano