zl程序教程

您现在的位置是:首页 >  其他

当前栏目

ROS1 noetic + depthai_ros教程

教程 ros
2023-09-14 09:01:43 时间

编辑:OAK中国
首发:oakchina.cn
喜欢的话,请多多👍⭐️✍

▌前言

Hello,大家好,这里是OAK中国,我是助手君。

之前有小伙伴表示OAK相机在C++上用起来有问题,我们的技术小哥们也立马安排起来了!C++的开发环境终于打包好啦!

本文来自OAK中国的使用文档,教程可能会不定期更新,最新内容请查看官网。

ROS上使用预编译的depthai C++ 库

▌测试结果

depthai-ros(Gen2)安装包下载链接:点击这里

测试设备详情
测试一平台:X86 PC端;系统:ubuntu18.04;ROS版本:melodic;depthai版本:2.15.0;设备:OAK-D
测试二平台:X86 PC端;系统:ubuntu20.04;ROS版本:noetic;depthai版本:2.15.0;设备:OAK-D
测试三平台:arch64 Jetson nano;系统:ubuntu18.04;ROS版本:melodic;depthai版本:2.15.0;设备:OAK-D
  1. 目前X86和arch64平台测试安装包没有问题;树莓派上安装ROS需要自己编译安装,时间比较长,需要测试的可以到官网查看,替换下面安装ROS步骤就可以了。
  2. ROS的noetic版本目前推荐在ubuntu20.04安装,ubuntu18.04推荐安装melodic版本。

▌开始

(以下步骤是ubuntu18.04 melodic版本)

安装依赖项

更新 usb 规则

 sudo wget -qO- https://mirror.ghproxy.com/https://raw.githubusercontent.com/luxonis/depthai-docs-website/master/source/_static/install_dependencies.sh | bash 
 sudo dpkg -i ./depthai_2.14.1_x86_64.deb

depthai core安装包 下载地址

sudo apt install ./depthai_2.15.0_x86_64_Shared.deb

如果您没有安装 opencv,请尝试

sudo apt install libopencv-dev

Jetson平台不需要安装opencv,系统自带。

如果您未安装rosdep且未初始化,请执行以下步骤:(这里安装的是melotic版本,如果想要安装ROS的其他版本,前往官网下载,建议安装ros基础版,缺什么包再装)

sudo apt update
sudo apt upgrade

# 设置sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# 如果下载速度较慢,使用以下命令替换上面的命令
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
# 如果依然遇到连接失败问题,请尝试换源https://developer.aliyun.com/mirror/ubuntu

# 设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# 若无法连接到密钥服务器,可以尝试替换上面命令中的 hkp://keyserver.ubuntu.com:80 为 hkp://pgp.mit.edu:80 。

sudo apt update
sudo apt install ros-melodic-ros-base
sudo apt install python-rosdep
sudo rosdep init
rosdep update

# 设置环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

需要安装的ros其他包

sudo apt install ros-melodic-rviz 

设置程序

mkdir -p <directory_for_workspaces>/src
cd <directory_for_workspaces>
git clone https://gitee.com/oakchina/depthai-ros.git
cd ../..
rosdep install --from-paths src --ignore-src -r -y
source /opt/ros/melodic/setup.bash
catkin_make
source devel/setup.bash

执行示例

cd <directory_for_workspaces>
source devel/setup.bash
roslaunch depthai_examples stereo_node.launch

运行示例

Mobilenet Publisher

OAK-D

roslaunch depthai_examples mobile_publisher.launch camera_model:=OAK-D

OAK-D-LITE

roslaunch depthai_examples mobile_publisher.launch camera_model:=OAK-D-LITE

带可视化器

roslaunch depthai_examples mobile_publisher.launch | rqt_image_view -t /mobilenet_publisher/color/image

测试结果

● ImageConverter - 使用 roslaunch depthai_examples stereo_inertial_node.launch && roslaunch depthai_examples rgb_publisher.launch 测试
● ImgDetectionCnverter - 测试使用 roslaunch depthai_examples mobile_publisher.launch
● SpatialImgDetectionConverter - 测试使用 roslaunch depthai_examples stereo_inertial_node.launch

▌常见问题解决

1.执行catkin_make出现的错误1

请添加图片描述

上述问题解决办法

2.执行catkin_make出现的错误2

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2.0: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
/usr/bin/ld: /lib/libgdal.so.26: undefined reference to `TIFFSetDirectory@LIBTIFF_4.0'
/usr/bin/ld: /lib/libgdal.so.26: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'
/usr/bin/ld: /lib/libgdal.so.26: undefined reference to `TIFFNumberOfTiles@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
make[2]: *** [luxonis/depthai-ros-examples/depthai_examples/CMakeFiles/rgb_node.dir/build.make:181/home/xiaotang/depthai_build/devel/lib/depthai_examples/rgb_node] 错误 1
make[1]: *** [CMakeFiles/Makefile2:2382:luxonis/depthai-ros-examples/depthai_examples/CMakeFiles/rgb_node.dir/all] 错误 2

遇到上面问题,检查是否把conda环境取消

3.执行catkin_make出现的错误3

ModuleNotFoundError: No module named 'pkg_resources'

解决方法:

sudo apt install --reinstall python3-pkg-resources python3-setuptools

OAK中国 | 追踪AI技术和产品新动态
公众号 | OAK视觉人工智能开发
点「这里」添加微信好友(备注来意)
戳「+关注」获取最新资讯↗↗

▌参考资料

https://docs.oakchina.cn/en/latest/
https://www.oakchina.cn/selection-guide/


OAK中国
| OpenCV AI Kit在中国区的官方代理商和技术服务商
| 追踪AI技术和产品新动态

戳「+关注」获取最新资讯↗↗