본문 바로가기

임베디드/JetsonNano

2) JetsonNano 개발 환경 구성 + 카메라, ROS (rev3)

Contents

1) 개발 환경 구성

  1-1) 설치법  (Jetson Nano / Rasberry Pi4 사양 비교)

  1-2) Jetson Fan 구동 명령

  1-3) HOST에서 Serial로 연결

 

2) 센서 구동

  2-1) 카메라

  2-2) 카메라 on ROS, 설치 부터 실행까지

  2-3) Docker on JetsonNano

  2-4) [Optional] OpenCV 설치

  2-5) 리얼센스(RealSense) 사용

  2-6) [Optional] SLAM Library 설치

  2-6) 라이다

        - 카메라 라이다 켈리브레이션

        - Ros2로 Lidar 구동

        - ORB SLAM on JetsonNano


1) 개발 환경 구성

1-1) 설치법  (Jetson Nano / Rasberry Pi4 사양 비교)

https://dhpark1212.tistory.com/entry/%EB%B9%84%EA%B3%B5%EA%B0%9C-Jetson-Nano-vs-Rasberry-Pi4?category=809879 

 

1) 설치법 (Jetson Nano / Rasberry Pi4 사양 비교)

1) Jetson Nano Image 설치법 공식 홈페이지에 나온데로 수행하면 된다. 1) Micro SD 카드를 포맷한다. - Formatter 다운(link) 2) JetsonNano Image를 내려 받는다 - (link) 3) Etcher와 같은 FlashLoad 프로그..

dhpark1212.tistory.com

- Kernel Check

donghun@donghun-desktop:~$ uname -r
>>> 4.9.140-tegra

1-2) Jetson Fan 구동 명령

sudo sh -c 'echo 100 > /sys/devices/pwm-fan/target_pwm'

1-3) HOST에서 Serial로 연결

- Jetson 홈페이지에 Micro-USB to USB 연결하여 모니터링 하는 방법이 나와 있다. Headless Mode 참고.

(https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#setup)(Baudrate는 9600 하면 잡힌다)

- 물론 USB2Uart 방식도 있다. (jetson-nano-uart) (jetson-nano-serial-console)

 

2) 센서 구동

2-1) 카메라

- Jetson은 MIPI-CSI cameras 모듈 지원한다

- MIPI(Mobile Industry Processor Interface), CSI(Camera Serial Interface)

- Sony IMX219칩을 사용한 V2 만 사용 가능

- 야간용(카메라) 도 판매한다

https://github.com/JetsonHacksNano/CSI-Camera.git

 

JetsonHacksNano/CSI-Camera

Simple example of using a CSI-Camera (like the Raspberry Pi Version 2 camera) with the NVIDIA Jetson Nano Developer Kit - JetsonHacksNano/CSI-Camera

github.com

 

2-2) 카메라 on ROS, 설치 부터 실행까지

- 출처 (github.com/dusty-nv/jetbot_ros)

- Ros1 melodic 설치

- JetsonHack 자료 (영상) (github.com/jetsonhacks/installROS)

- 본인은 ros-melodic-desktop 를 설치하였다.

※ base , desktop, desktop-full 차이 (what-are-differences-of-ros-desktop-vs-base/) (본인은 desktop을 설치하였다)

 Steros Camera 글(stereolabs.com/blog/ros-and-nvidia-jetson-nano/)

 

이하 ROS 설치 & Catkin workspace 설치 명령

더보기
# enable all Ubuntu packages:
$ sudo apt-add-repository universe
$ sudo apt-add-repository multiverse
$ sudo apt-add-repository restricted

# add ROS repository to apt sources
$ 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

# install ROS Base
$ sudo apt-get update
$ sudo apt-get install ros-melodic-desktop # ros-melodic-ros-base

# add ROS paths to environment
sudo sh -c 'echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc'

# To install this tool and other dependencies for building ROS packages
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

# Initialize rosdep
sudo rosdep init
# To find available packages, use:
rosdep update
# create the catkin workspace
$ mkdir -p ~/workspace/catkin_ws/src
$ cd ~/workspace/catkin_ws
$ catkin_make

# add catkin_ws path to bashrc
$ sudo sh -c 'echo "source ~/workspace/catkin_ws/devel/setup.bash" >> ~/.bashrc'

 

- csi_cam을 ROS에서 실행하기 위해서 참고 하였다(github.com/peter-moran/jetson_csi_cam).

'peter-moran/jetson_csi_cam' 와 'ros-drivers/gscam' 가 필요하다고 나와 있지만 에러가 난다.

'ros-perception/image_common' 가 추가로 필요하다. ;;;

- 다음 Repo가 더 자세히 나와 있다. (https://shiroku.net/robotics/connect-csi-camera-on-jetson-tx2-to-ros/)

  

# Run
$ roscore
$ roslaunch jetson_csi_cam jetson_csi_cam.launch

드디어 성공!

 

2-3) Docker on JetsonNano

- docker version check

더보기
donghun@donghun-desktop:~$ sudo docker version
[sudo] password for donghun: 
Client:
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        369ce74a3c
 Built:             Fri Feb 28 23:47:53 2020
 OS/Arch:           linux/arm64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       369ce74a3c
  Built:            Wed Feb 19 01:06:16 2020
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.3.3-0ubuntu1~18.04.2
  GitCommit:        
 runc:
  Version:          spec: 1.0.1-dev
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit:

- Container Runtime Check

더보기
donghun@donghun-desktop:~$ sudo docker info | grep nvidia
 Runtimes: nvidia runc

- 주요 명령어

- 본인 사용 명령어

$ docker run (<옵션>) <이미지 식별자> (<명령어>) (<인자>)

- -idt : ineractive + detached+ tty

         (d 옵션을 쓰지 않으면, 실행 후에 바로 컨테이너 화면으로 넘어간다)

- -v <메인 OS 디렉토리>:<컨테이너 디렉토리> (volumn의 약어, 호스트 파일 시스템 특정 경로를 컨테이너에 마운트)

더보기
# [Optional] 슈퍼 유저로 전환
$ su 

# 1. 도커 이미지 당겨오기
$ docker pull {이미지 경로} # 보통은 이미지를 pull 해 온다

# 2. 도커 이미지 목록 확인
$ docker images

# 3. 도커 컨테이너 확인(실행 컨테이너 확인)
$ docker ps -a

# 4. 도커 컨테이너 생성 및 실행 ('Container Name'은 본인이 정할 것)
$ docker run -v /home/user/XXX:/etc -it --name 'Container Name' -dit 'ImageRepo:TAG' bash
                                    (여기 까지가 컨테이너 생성 명령)
# 5. 도커 컨테이너 실행
$ docker start 'Container Name'(or 'Container ID')  # 컨테이너 stop 상태 라면
$ docker attach 'Container Name'(or 'Container ID') # 컨테이너 running 상태 라면

# 6. 도커 컨테이너 끄기
$ docker stop {Container name}

# 도커 컨테이너 지우기 (이름 or ID로 삭제 가능)
$ docker rm 'Container Name'(or 'Container ID')

# 도커 이미지 지우기
$ docker rmi 'Image ID'
# 호스트 환경에서 도커에 명령을 내릴 경우
$ docker exec {컨테이너 ID} "명령어"
# 모든 실행 중인 도커 컨테이너 종료 및 제거
$ docker kill $(docker ps -q) # docker ps -q 명령은 모든 실행 중인 컨테이너를 보여준다.
$ docker rm $(docker ps -a -q) # docker ps -q 명령은 모든 컨테이너 목록은 보여준다.

# 모든 도커 이미지 제거
docker rmi $(docker images -q) # docker images -q 명령은 모든 이미지 ID를 보여준다.

[TODO]

- Dockerfile을 이용해 필요 라이브러리가 생성된 Image 만들기(컨테이너는 실험용으로 돌려보고 삭제)

  (팀원끼리 같은 이미지에서 생성된 컨테이너로 작업하면 작업을 동기화 할 수 있다)

- Dockerfile에 내장할 디펜던시 스크립트 작성

- 디펜던시 스크립트 업데이트 해 나가기(이미지 업데이트 및 공유)

sudo docker build --no-cache --force-rm -f Dockerfile -t "ImageRepo:TAG" .
# --no-cache 는 이전 빌드에서 생성된 캐시를 사용하지 않음
# --force-rm 은 빌드중 문제가 생기면 이미지/컨테이너를 지운다
# -f 는 사용할 Dockerfile의 이름 명시
# .는 Dockerfile 경로 명시

 

2-4) [Option] OpenCV 설치

- jetsonhacks 아저씨의 Repo도 있지만(JetsonHacksNano/buildOpenCV/blob/master/buildOpenCV.sh) Shell로 자동화 시켜 놓으셨고, 본인은 line by line으로 설치 명령을 알고 싶어서 다른 Repo를 참고 하였다.

- 본인이 참조한 링크 (AastaNV/JEP/blob/master/script/install_opencv4.5.0_Jetson.sh)

 

※ CUDA_ARCH_BIN 에서 5.3 : NANO / 6.2 : Tx2 / 7.2 : Xavier 이다. 따라서 Nano만 설치하고 싶으면 5.3만 남겨둔다.

더보기
#!/bin/bash
#
# Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#

version="4.5.0"
folder="workspace"

echo "** Remove other OpenCV first"
sudo sudo apt-get purge *libopencv*


echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl


echo "** Download opencv-"${version}
mkdir $folder
cd ${folder}
curl -L https://github.com/opencv/opencv/archive/${version}.zip -o opencv-${version}.zip
curl -L https://github.com/opencv/opencv_contrib/archive/${version}.zip -o opencv_contrib-${version}.zip
unzip opencv-${version}.zip
unzip opencv_contrib-${version}.zip
cd opencv-${version}/


echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D WITH_CUDNN=ON -D CUDA_ARCH_BIN="5.3,6.2,7.2" -D CUDA_ARCH_PTX="" -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${version}/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install


echo "** Install opencv-"${version}" successfully"
echo "** Bye :)"

 

2-5) 리얼센스(Realsense) 사용

2-5-1) T256 intelrealsense.com/tracking-camera-t265

- 저전력, 저지연(<6ms)

- <1% Drift Error

- Camera + IMU(BMI055)를 이용해서 VIO-SLAM 기술 내장

- 2 Fisheye Camera(165 ± 5˚) + VPU

- Host Independent

- Wheel Odometry가 내장되어 있다(사용자는 USB를 통해 TM2에 Data를 제공해야 한다)

- 15lux 까지의 낮은 밝기에도 잘 동작한다

- 그외 특징, 

    - T265는 렌즈 위에 적외선 차단 필터가 있어 D4xx와 같은 Depth Camera의 투영 패턴(단점으로 작용하나 보다)을

      무시할 수 있다. 따라서, 개발자는 Depth Camera와 같이 쓸 수 있다. 

    - Occupancy Grid Map, Collision Avoidance, Navigation & Localization에 사용

    - Tracking 성능은 D435i 보다 더 좋다. Depth Camera 시리즈 보다 

 

Tracking camera T265 – Intel RealSense Depth and Tracking Cameras

Tracking camera for Robotics, Drones and More. Low power SLAM camera solution. Cross-platform compatibility, high accuracy, small formfactor.

www.intelrealsense.com

- Youtube(JetsonHack)

- T256 + JetsonNano(RealSense)

위의 링크는 JetsonHack 아저씨의 Repo이고 librealsense build from source를 수행한다. 하지만, apt-get으로 설치하는 것을 추천한다. 두번째 링크인 RealSense 홈페이지에도 그렇게 안내되어 있다.

"Starting with L4T 32.2.1 (JetPack 4.2.2) on the NVIDIA Jetsons and the Intel RealSense SDK version v2.23.0, it is now possible to do a simple install from a RealSense debian repository (i.e. apt-get install). Previous versions of this repository require building librealsense from source, and (possibly) rebuilding the Linux kernel."

※ 현재 본인의 Jetson은 realsense-viewer를 실행하면 재부팅이 된다. 전력이 모자란 듯 하다.

더 많은 전력을 가하는 방법은 아래 링크를 참조한다.

https://www.jetsonhacks.com/2019/04/10/jetson-nano-use-more-power/

 

※ T256은 두개의 어안 렌즈를 이용해서 Visual-SLAM을 구현한 것이다. 하지만, 요즘 트렌드는 IMU 센서를 같이 이용하므로 T435i와 같이 i(IMU) 센서를 붙인 것을 사용하기도 한다. 

 

2-5-2) intelrealsense.com/depth-camera-d435

2-5-3) intelrealsense.com/depth-camera-d435i

   - Youbute

 

 

2-6) [Optional] SLAM Library 설치

더보기
# CMake
sudo apt-get install cmake
# google-glog + gflags
sudo apt-get install libgoogle-glog-dev libgflags-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
sudo apt-get install libsuitesparse-dev

#clone code
git clone https://ceres-solver.googlesource.com/ceres-solver

mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-2.0.0
make -j3
make test
# Optionally install Ceres, it can also be exported using CMake which
# allows Ceres to be used without requiring installation, see the documentation
# for the EXPORT_BUILD_DIR option for more information.
make install

 

 

 

(현재 여기 까지 성공)


2-x) 라이다

 

2-x)카메라 라이다 켈리브레이션

https://youtu.be/WmzEnjmffQU

 

Ros2로 Lidar 구동

https://www.hackster.io/shahizat005/lidar-integration-with-ros-2-foxy-on-the-nvidia-jetson-board-34fa62?fbclid=IwAR2hi8RQoz4Efqdxex8tZuXjLbm8jT6Ry11v4DI7osPl2APh-WyNeYdggOs 

 

LiDAR integration with ROS 2 Foxy on the Nvidia Jetson Board

LiDAR integration with ROS 2 Foxy Fitzroy using Docker container on the Nvidia Jetson SBCs. By Nurgaliyev Shakhizat.

www.hackster.io

 

ORB-SLAM2

- https://github.com/raulmur/ORB_SLAM2 

- http://wiki.ros.org/orb_slam2_ros

 

 

어플리케이션 개발

- stmFx에서 한것을 그대로 Nvidia에 포팅

 

- 카메라 설치

 

- 사람 트레킹

 

ROS

ROS1 강좌

- ROS Kinetic과 Melodic은 구분할 것 없이 ROS 1이면 동일하다고 한다(출처)

- ROS1은 15년 이후로 개발X. 유지보수만 진행한다고 한다.

 

https://cafe.naver.com/openrt/24335

 

ros 한국어 추천 강좌 링크 입니다.

한국어로 구성된 양질의 ros1 강좌 있어 공유 드립니다. 최근 ros1 오프 강좌에 쓰신 자료라 그런지 링크라 구성이 감동적입니다. 링크 공유해주신 제작자 안병규 (By...

cafe.naver.com

 


Docker 참조 사이트

[1] https://changh95.github.io/20210808-docker-for-slam/?fbclid=IwAR2JUChho8WnNDK20DbppoKeht5V-awCSNNSvZoTBe2_13HfDWHIT9z_tNw 

반응형