Roban2 Docs
Roban2 (ROS1) Legacy VersionsFeature ExamplesGeneral Examples

QR Code Detection Example

QR Code

Usage

  • Adjust the configuration file
    • The configuration file is located at ~/kuavo_ros_application/src/ros_vision/detection_apriltag/apriltag_ros/config/tags.yaml
    standalone_tags:
    [
      {id: 0, size: 0.042, name: 'tag_0'},
      {id: 1, size: 0.042, name: 'tag_1'},
      {id: 2, size: 0.042, name: 'tag_2'},
      {id: 3, size: 0.04, name: 'tag_3'},
      {id: 4, size: 0.04, name: 'tag_4'},
      {id: 5, size: 0.04, name: 'tag_5'},
      {id: 6, size: 0.04, name: 'tag_6'},
      {id: 7, size: 0.04, name: 'tag_7'},
      {id: 8, size: 0.04, name: 'tag_8'},
      {id: 9, size: 0.04, name: 'tag_9'},
    ]
    Modify/add the ID and size of the target QR codes to be recognized; the unit is m

Enter in the terminal:

rqt_image_view

Select the /tag_detections_image topic

Example Program

  • Path: ~/kuavo_ros_application/src/demo/examples_code/tag_detect/get_tag_info.py

  • Startup steps

    • Before starting the script, you need to first launch the load_robot_head.launch file on the host computer
cd ~/kuavo_ros_application
source devel/setup.bash
python3 src/demo/examples_code/tag_detect/get_tag_info.py

Obtaining Detection Results

⚠️ Because /robot_tag_info depends on the tf tree, you must make the robot stand up for this topic to take effect

  • Based on the camera coordinate frame: /tag_detections; based on the robot base coordinate frame: /robot_tag_info
  • Modify the subscribed topic in the example program to obtain different pose information of the QR code relative to the camera coordinate frame and the robot base coordinate frame

Example Code Description

  • AprilTagProcessor class: responsible for processing AprilTag detection data, including initializing the ROS node, converting quaternions to Euler angles, obtaining AprilTag data, looking up AprilTags by ID, and computing averaged AprilTag data.
  • quaternion_to_euler function: converts a quaternion to the yaw angle in Euler angles, used to represent rotation.
  • get_apriltag_data function: obtains AprilTag detection data from the ROS topic and extracts the ID, position, and orientation of each tag.
  • get_apriltag_by_id function: looks up AprilTag data by the specified ID.
  • get_averaged_apriltag_data function: obtains multiple detections of the AprilTag with the specified ID and computes its average position and orientation.
  • Main program: creates an AprilTagProcessor instance, initializes the ROS node, and obtains the averaged data of the AprilTag with the specified ID.