1)安装apriltag
1.下载apriltag代码。参考官方的教程下载安装。网上其他博客已失效。
https://github.com/AprilRobotics/apriltag_ros
export ROS_DISTRO=melodic # Set this to your distro, e.g. kinetic or melodic
source /opt/ros/$ROS_DISTRO/setup.bash # Source your ROS distro
mkdir -p ~/catkin_ws/src # Make a new workspace
cd ~/catkin_ws/src # Navigate to the source space
git clone https://github.com/AprilRobotics/apriltag.git # Clone Apriltag library
git clone https://github.com/AprilRobotics/apriltag_ros.git # Clone Apriltag ROS wrapper
cd ~/catkin_ws # Navigate to the workspace
rosdep install --from-paths src --ignore-src -r -y # Install any missing packages
catkin build # Build all packages in the workspace (catkin_make_isolated will work also)
更新:
直接使用以下命令编译安装:
~/catkin_ws$ catkin_make -DCATKIN_WHITELIST_PACKAGES="apriltag_ros" install
2)测试运行
2.roscore
3.启动相机
roslaunch realsense2_camera rs_camera.launch
2.1)修改apriltag配文件
4.修改配置文件~/catkin_ws/src/apriltag_ros/apriltag_ros/config/tags.yaml
修改tag_bundles中的id=0这一行的size信息为自己实际打印二维码的宽度(单位是米)。
# # Definitions of tags to detect
#
# ## General remarks
#
# - All length in meters
# - Ellipsis (...) signifies that the previous element can be repeated multiple times.
#
# ## Standalone tag definitions
# ### Remarks
#
# - name is optional
#
# ### Syntax
#
# standalone_tags:
# [
# {id: ID, size: SIZE, name: NAME},
# ...
# ]
standalone_tags:
[
]
# ## Tag bundle definitions
# ### Remarks
#
# - name is optional
# - x, y, z have default values of 0 thus they are optional
# - qw has default value of 1 and qx, qy, qz have default values of 0 thus they are optional
#
# ### Syntax
#
# tag_bundles:
# [
# {
# name: 'CUSTOM_BUNDLE_NAME',
# layout:
# [
# {id: ID, size: SIZE, x: X_POS, y: Y_POS, z: Z_POS, qw: QUAT_W_VAL, qx: QUAT_X_VAL, qy: QUAT_Y_VAL, qz: QUAT_Z_VAL},
# ...
# ]
# },
# ...
# ]
tag_bundles:
[
{
name: 'my_bundle',
layout:
[
{id: 0, size: 0.151, x: 0.0000, y: 0.0000, z: 0.0, qw: 0.707, qx: 0.0, qy: 0.0, qz: -0.707},
{id: 1, size: 0.152, x: 1.2000, y: 0.0000, z: 0.0, qw: 0.707, qx: 0.0, qy: 0.0, qz: -0.707}
]
}
]
5.修改配置文件~/catkin_ws/src/apriltag_ros/apriltag_ros/config/settings.yaml
修改tag_family
# AprilTag 3 code parameters
# Find descriptions in apriltag/include/apriltag.h:struct apriltag_detector
# apriltag/include/apriltag.h:struct apriltag_family
tag_family: 'tag16h5' # options: tagStandard52h13, tagStandard41h12, tag36h11, tag25h9, tag16h5, tagCustom48h12, tagCircle21h7, tagCircle49h12
tag_threads: 2 # default: 2
tag_decimate: 1.0 # default: 1.0
tag_blur: 0.0 # default: 0.0
tag_refine_edges: 1 # default: 1
tag_debug: 0 # default: 0
# Other parameters
publish_tf: true # default: false
6.编辑launch文件
2.2)启动检测
7.启动apriltag节点
cd ~/catkin
source devel_isolated/setup.bash
cd ~/catkin_ws/src/apriltag_ros/apriltag_ros/launch
roslaunch apriltag_ros continuous_detection.launch
更新:
~/catkin_ws$ source ~/catkin_ws/install/setup.bash
~/catkin_ws$ roslaunch apriltag_ros continuous_detection.launch
8.获取位姿信息
cd ~/catkin
source devel_isolated/setup.bash
rostopic echo /tag_detections
更新:
$ source ~/catkin_ws/devel/setup.bash
$ rostopic echo /tag_detections
9.可视化检测信息
cd ~/catkin
source devel_isolated/setup.bash
rostopic echo /tag_detections_image
#新开窗口
rosrun rviz rviz
更新:
直接rviz选择对应topic展示窗口