ROS Programming
Raspberry Pi

Pixhawk Telemetry 2와 Rasbberry Pi 연결하여 텔레메트리 QGC에 전송하기

4ehSbva.png

  1. Pixhawk Telemetry 2(SERIAL2) 와 Raspberry Pi의 6(GND), 8(TXD), 10(RXD)번핀과 연결.
  2. Ardupilot의 SERIAL2 관련 파라미터 설정. SERIAL2_BAUD: 921600, SERIAL2_PROTOCOL: MAVLink2, SERIAL2_OPTION: 0
  3. Raspberry Pi의 시리얼 포트 활성화. raspi-config 인터페이스 -> 시리얼포트 -> Login Shell(NO) -> Serial Hardware Enable (YES)
  4. MAVProxy 설치
  5. Raspberry Pi 리붓
  6. MAVProxy로 시리얼포트와 QGC의 UDP 포트를 연결
  7. QGroundControl의 어플리케이션 세팅에서 Com Links에 UDP, 14550, 서버주소로 Raspberry Pi 아이피 넣기

Raspberry Pi에 MAVProxy 설치

sudo apt-get install python3-dev python3-opencv python3-wxgtk4.0 python3-pip python3-matplotlib python-pygame python-serial python3-lxml libxml2-dev libxslt-dev tmux
pip3 install PyYAML mavproxy --user

sudo adduser $USER dialout
echo "%$USER ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers

Raspberry Pi에 MavRos 설치

## Install dependencies
sudo apt-get install python-wstool python-rosinstall-generator python-catkin-tools -y

## Create catkin workspace (ROS build system)
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin init

## Initialise wstool
wstool init ~/catkin_ws/src

## Build MAVROS
### Get source (upstream - released)
rosinstall_generator --upstream mavros --rosdistro melodic | tee /tmp/mavros.rosinstall
### Get latest released mavlink package
rosinstall_generator mavlink --rosdistro melodic | tee -a /tmp/mavros.rosinstall

### Setup workspace & install deps
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src
rosdep install --from-paths src --ignore-src --rosdistro melodic -y

### Install GeographicLib datasets
sudo ./src/mavros/mavros/scripts/install_geographiclib_datasets.sh

### Build source
catkin build

### source setup.bash
source devel/setup.bash

mavros 패키지 설치 확인

rospack list |grep mavros

mavros node 실행 (rosrun 사용하는 방법)

rosrun mavros mavros_node _fcu_url:="/dev/ttyS0:921600" _gcs_url:="udp://@192.168.88.xxx"

MAVProxy 실행 (MAVRos 사용시 필요 없음)

sudo chgrp dialout /dev/ttyS0
sudo chmod 770 /dev/ttyS0
/usr/bin/python3 $HOME/.local/bin/mavproxy.py --master=/dev/ttyS0 --baudrate 921600 --out=udpin:0.0.0.0:14550

QGroundControl에서 Raspberry Pi Camera로 영상 보기

  • QGroundControl 설정: Video Settings -> Source -> UDP h.264 Video Stream
  • Raspberri Pi 설정: gstreamer 사용하여 QGC에 Video 스트림을 보낸다

Raspberri Pi에 gstreamer 설치

sudo apt-get install gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools libgstreamer1.0-dev libgstreamer1.0-0-dbg libgstreamer1.0-0 libgstreamer-plugins-base1.0-dev gtk-doc-tools -y

Raspberry Pi에 gst-rpicamsrc 설치

git clone https://github.com/thaytan/gst-rpicamsrc.git
cd gst-rpicamsrc
./autogen.sh
make
sudo make install
gst-inspect-1.0 | grep rpicamsrc

GStreamer RTSP Server 설치 (RTSP 사용할 경우)

git clone git://anongit.freedesktop.org/gstreamer/gst-rtsp-server
cd gst-rtsp-server
git checkout 1.12.5
sudo apt-get install meson
meson build

./autogen.sh
make
sudo make install

UDP h.264 Video Stream

QGroundControl IP가 192.168.88.14인 경우

gst-launch-1.0 rpicamsrc bitrate=1000000 ! 'video/x-h264,width=640,height=480' ! h264parse ! queue ! rtph264pay config-interval=1 pt=96 ! udpsink host=192.168.88.14 port=5600

FPV, QGC, MAVProxy: https://gist.github.com/donghee/06c1ae937fa7f7adb58794c4d303113e

노트북에 QGroundControl 설치

sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y

Author: 박동희

Created: 2021-08-25 수 17:20

Validate