knowledge_map/工作/艾航/灵汐osdk ros开发环境配置.md
2024-11-16 14:33:59 +08:00

141 lines
4.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 编译运行环境配置
## 配置硬件环境
### 硬件连接
*使用转接线typeC接口连接无人机OSDK接口uart接口接入下图 Uart-TTL0USB接口插入两个叠起来的USB口中的下面那一个*
![image-20210629094214655](img/uart_port.png)
### 硬件驱动配置
*将drivers路径下cdc-acm.ko、cdc_ether.ko、rndis_host.ko 三个驱动文件放入 /lib/modules路径下并将以下内容写入到/etc/init.d/load_driver.sh文件末尾*
```bash
echo "load cdc acm"
insmod $LYNKOPATH/cdc-acm.ko
echo "loading cdc_ether driver"
insmod $LYNKOPATH/cdc_ether.ko
echo "loading rndis_host driver "
insmod $LYNKOPATH/rndis_host.ko
```
### osdk 硬件运行环境配置
```bash
echo "SUBSYSTEM=="usb", ATTRS{idVendor}=="2ca3", MODE="0666"" >> /etc/udev/rules.d/DJIDevice.rules # 添加dji usb 设备节点
sudo usermod -a -G dialout $USER  # 添加uart 读取权限
```
## 配置软件环境
*由于ros无法使用sudo 权限启动程序但是AI推理需要使用sudo 权限所以下面操作都是使用root 用户执行*
### 换国内镜像源
将/etc/apt/sources.list 的内容替换为以下内容
```bash
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# # deb-src https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.bfsu.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
```
替换完成之后执行
```bash
sudo apt update
```
### 安装ros 环境
```bash
sudo apt install gnupg1  
sudo echo "deb https://mirrors.bfsu.edu.cn/ros/ubuntu/ focal main" >> /etc/apt/sources.list.d/ros-latest.list # 添加ros 源地址
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-noetic-ros-base  ros-noetic-nmea-msgs ros-noetic-sensor-msgs ros-noetic-nav-msgs ros-noetic-tf  # 安装ros 相关库
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc  # 配置ros 环境变量
source ~/.bashrc
```
### apt 安装依赖库
```bash
sudo apt install libavformat-dev libavcodec-dev    
sudo apt install libopencv-dev libopencv-contrib-dev                                    
sudo apt install libsdl2-dev libusb-1.0-0-dev
sudo apt install build-essential
sudo apt install libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-bad gstreamer1.0-plugins-rtp gstreamer1.0-plugins-ugly    
sudo apt install libeigen3-dev  
sudo apt install git
```
### 编译安装相关依赖库
#### osdk
```bash
git clone https://github.com/dji-sdk/Onboard-SDK.git
cd Onboard-SDK
mkdir build && cd build
cmake ..
make -j4 && sudo make install
```
#### websocketpp
```bash
git clone https://github.com/zaphoyd/websocketpp.git
cd websocketpp
mkdir build && cd build
cmake ..
make -j && sudo make install
```
### 编译yolov5 plugin
*编译产物在yolov5_plugin/obj/ 路径下*
```bash
cd yolov5_plugin/build
cmake ..
make -j
```
## 编译运行 osdk_ros
### 编译 osdk_ros
```bash
cd osdk_ros
catkin_make -j4  # 如果使用更多核心编译会导致编译过程中内存不足
```
### 运行项目
*运行之前要先打开osdk_ros/src/ah_osdk_ros/launch/mission.launch文件检查pluginPath和modelPath的value是否正确pluginPath是前面编译的yolov5 plugin产物的路径。  modelPath是算法模型的路径在modules路径下有一个电力设备目标识别的模型yolov5s-6.1-device一个yolov5s基础模型yolov5s.6.1_110_abc*
```bash
source devel/setup.sh
roslaunch ah_osdk_ros mission.launch
```