realsense d435i+apriltags二维码实现定位+ros

目的

想检测apriltag相较于棋盘格的位姿识别效果,便于手眼标定
安装环境
系统:ubuntu 18.04 内核
ROS: melodic
相机:intel realsense d435i

已安装相机驱动

librealsense 以及相机ROS Wrapper,相机能够正常工作

#1. 安装时需要将realsense相机拔掉
#2. 打开终端,依次输入以下命令行(见到Y/n,输入y即可)
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
sudo apt-get install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense/
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/ 
sudo udevadm control --reload-rules && udevadm trigger
./scripts/patch-realsense-ubuntu-lts.sh
echo 'hid_sensor_custom' | sudo tee -a /etc/modules
mkdir build && cd build
cmake ../ -DBUILD_EXAMPLES=true
sudo make uninstall && make clean && make -j4 && sudo make install
#3. realsense相机通过3.0或以上USB接口连接主机
#打开终端,输入
#realsense-viewer

apriltags2_ros的编译

安装教程
出现报错:Could not find a package configuration file provided by apriltag
解决方案

准备实验

apriltag二维码生成
下载地址

sudo chmod +x openmv-ide-linux-x86_64-2.6.5.run 
./openmv-ide-linux-x86_64-2.6.5.run 

工具-机器视觉-ApirlTag生成器-TAG36H11

运行apriltag_ros

修改launch文件,主要是camera_name和image_topic要改成对应相机的topic

<launch>
  <arg name="launch_prefix" default="" /> <!-- set to value="gdbserver localhost:10000" for remote debugging -->
  <arg name="node_namespace" default="apriltag_ros_continuous_node" />
  <arg name="camera_name" default="/cv_camera" />
  <arg name="camera_frame" default="cv_camera" />
  <arg name="image_topic" default="image_raw" />

  <!-- Set parameters -->
  <rosparam command="load" file="$(find apriltag_ros)/config/settings.yaml" ns="$(arg node_namespace)" />
  <rosparam command="load" file="$(find apriltag_ros)/config/tags.yaml" ns="$(arg node_namespace)" />
  
  <node pkg="apriltag_ros" type="apriltag_ros_continuous_node" name="$(arg node_namespace)" clear_params="true" output="screen" launch-prefix="$(arg launch_prefix)" >
    <!-- Remap topics from those used in code to those on the ROS network -->
    <remap from="image_rect" to="$(arg camera_name)/$(arg image_topic)" />
    <remap from="camera_info" to="$(arg camera_name)/camera_info" />

    <param name="camera_frame" type="str" value="$(arg camera_frame)" />
    <param name="publish_tag_detections_image" type="bool" value="true" />      <!-- default: false -->
  </node>
</launch>

修改settings.yaml文件,采用何种apriltags二维码

修改tags.yaml文件,主要是自己的AprilTag

tag_bundles:
  [
 {
       name: 'CUSTOM_BUNDLE_NAME',
       layout:
         [
           {id: 0, size: 0.146, x: 0, y: 0, z: 0, qw: 1.0, qx: 0.0, qy: 0.0, qz: 0.0},
         ]
     }
  ]

运行roslaunch apriltags2_ros continuous_detection.launch
可以通过topic list看到新的topic,其中/tag_detection就是我们的检测结果了。
rostopic echo /tag_detection

header: 
  seq: 3211
  stamp: 
    secs: 1640585817
    nsecs: 812052488
  frame_id: "camera_color_optical_frame"
detections: 
  - 
    id: [0]
    size: [0.095]
    pose: 
      header: 
        seq: 5240
        stamp: 
          secs: 1640585817
          nsecs: 812052488
        frame_id: "camera_color_optical_frame"
      pose: 
        pose: 
          position: 
            x: 0.150823692867
            y: 0.0563776419582
            z: 0.630823164063
          orientation: 
            x: 0.998524587587
            y: 0.032129927311
            z: -0.014006748795
            w: 0.0414744106955
        covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

运行launch文件报错:

>>rostopic echo /tag_detections
ERROR: Cannot load message class for [apriltag_ros/AprilTagDetectionArray]. Are your messages built?

原因在与没有在bash中source
source devel_isolated/setup.zsh
正常运行
若想要在rviz里也看到/tag_detection的数据也要在启动前source