Kuavo Docs
Feature 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 IDs and sizes of the target QR codes to be detected; the unit is m

Example Program

  • Path: /home/lab/kuavo-ros-opensource/src/demo/examples_code/tag_detect/get_tag_info.py

Startup Steps

  • Before running the script, you must first start the load_robot_head.launch file on the upper-level computer
# Run on the upper-level computer
cd ~/kuavo_ros_application
source devel/setup.bash # Make sure compilation has succeeded
# Start the program according to the actual robot version:
# Old 4th generation, 4Pro
roslaunch dynamic_biped load_robot_head.launch
# Standard version, Advanced version, Showroom version, Showroom Compute version
roslaunch dynamic_biped load_robot_head.launch use_orbbec:=true
# Max version
roslaunch dynamic_biped load_robot_head.launch use_orbbec:=true enable_wrist_camera:=true
  • Visualize the QR code detection preview image
# Run on the upper-level computer
cd ~/kuavo_ros_application
source devel/setup.bash 
python3 src/ros_vision/detection_apriltag/detection_show/tag_detection_show.py
  • Observe the detection result with rqt

Open a new terminal and enter:

rqt_image_view

Select the /tag_detections_image topic

QR code

  • Example program to obtain the detection results
# Run on the lower-level computer
cd ~/kuavo-ros-opensource
source devel/setup.bash
python3 src/demo/examples_code/tag_detect/get_tag_info.py

About the Detection Results

⚠️ Because /robot_tag_info depends on the tf tree, you need to make the robot stand up on the lower-level computer for this topic to take effect

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

Example Code Description

  • AprilTagProcessor class: Handles AprilTag detection data, including initializing the ROS node, converting quaternions to Euler angles, retrieving AprilTag data, looking up AprilTags by ID, and calculating 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: Retrieves AprilTag detection data from a 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: Retrieves multiple detection results for the AprilTag with the specified ID and calculates 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.