Kuavo Docs
Feature ExamplesGeneral Examples

QR Code Water Bottle Grasping Example

Case Introduction

Overview

  • The robot recognizes the QR code through the head camera, computes the coordinate information of the QR code, and calculates the arm joint angles through IK inverse kinematics for grasping.

Features

  • By recognizing the AprilTag marker, the position of the grasping target in the coordinate system is obtained
  • Autonomously determines the left or right hand and calculates the desired position and orientation of the arm end effector
  • Obtains the target angles of each arm joint through the IK inverse kinematics service
  • Implements the water-grasping and water-handing workflow smoothly

Workflow Logic

  1. The robot lowers its head, and after a short delay obtains the averaged data of the AprilTag with the specified ID
  2. Sets the arm motion mode to external control
  3. Opens the hand and moves to the ready pose
  4. Calculates the IK solving parameters, performs IK solving, and moves using the IK result
  5. Closes the hand, hands over the water, opens the hand, resets the arm, raises the robot's head, and the workflow ends

Real Robot Video Demo

Preparation

Preparing the QR Code (Upper Computer)

  1. Download the QR code
  • QR code download website
  • The QR code type used is apriltag, tag family 36h11; the ID and size are set according to actual needs QR code
  1. Adjust the configuration file (upper computer)
  • 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'},
  ...
]
  1. Note:
  • The size here must match the size of the printed QR code (the QR code size can be set on the website mentioned above)
  • The default grasp point is directly below the QR code, so the QR code must be affixed on top of the bottle cap

Checking the Gripper Robot Configuration (Lower Computer)

  • If your robot's end effector is a dexterous hand, just skip this step
  • If your robot's end effector is a gripper, you need to check the configuration file /home/lab/kuavo-ros-opensource/src/kuavo_assets/config/kuavo_v$ROBOT_VERSION/kuavo.json on the lower computer Gripper configuration check
  • If the value in the red box in the figure is "qiangnao", it needs to be changed to "lejuclaw"

Code Path

  • Path: /home/lab/kuavo-ros-opensource/src/demo/arm_capture_apriltag

Code Compilation

cd /home/lab/kuavo-ros-opensource #仓库目录
sudo su
catkin build kuavo_sdk

ROS Topics and Services

Upper Computer

  • Starts the sensor, recognizes the QR code in real time, and computes its position in the robot base coordinate system
  • Publishes the /robot_tag_info topic to transmit the information

Lower Computer

  1. Set the arm motion mode
  • Calls the ROS service /arm_traj_change_mode to set the arm motion mode to external control mode
  1. Start the IK inverse kinematics service
  • Calculates the IK inverse kinematics parameters and calls the ROS service /ik/two_arm_hand_pose_cmd_srv to compute the inverse kinematics solution for the given coordinates and orientation.
  • Obtains the IK result: q_arm, the arm joint values (in radians)
  1. Control the robot head
  • Publishes to the /robot_head_motion_data topic
  • Sets the joint data, including the yaw and pitch angles
  1. Control the opening and closing of the robot hand
  • Publishes to the /control_robot_hand_position topic
  • Sets the joint angles for closing or opening
  1. Control the opening and closing of the robot gripper
  • Calls the ROS service /control_robot_leju_claw
  • Sets the opening/closing angle of the gripper
  1. Obtain the QR code tag information
  • Receives the AprilTagDetectionArray message from the /robot_tag_info topic
  • Obtains the average position of the AprilTag with the specified ID (based on the robot base coordinate system)
    • avg_off_horizontal corresponds to the x-axis
    • avg_off_camera corresponds to the y-axis
    • avg_off_vertical corresponds to the z-axis

Running the Example

Launch Parameters

  • offset_start : whether to enable coordinate offsets
    • Entering True for the parameter: enables coordinate offsets, generally used on the real robot to observe the grasping result
    • Entering False for the parameter: disables coordinate offsets, generally used in simulation to observe the solving result

Coordinate Offsets

  • Main parameters:
    • offset_z offset in the z direction; by default the grasp point is directly below the QR code, so it is a negative value
    • temp_x_l temp_x_r offsets in the x direction; both left and right are negative values
    • temp_y_l temp_y_r offsets in the y direction; both are positive values, added for the left and subtracted for the right
    • offset_angle angular offset about the z-axis; during IK solving, if the yaw angle does not meet expectations, this value can be increased or decreased appropriately
  • Tuning notes: (taking the right hand as an example; the direction the robot faces is forward)
    • If the grasp point is too high, decrease the value of offset_z; otherwise increase it
    • If the grasp point is too far to the right, increase the value of temp_y_r; otherwise decrease it
    • If the grasp point is too far forward, decrease the value of temp_x_r; otherwise increase it
  • Parameter location:
    • In the arm_capture_apriltag.py file, set in the main function
    • Usage example:
    # offset_start="True"表示启用偏移量 否则不启用偏移量
    if args.offset_start == "True":
        # 偏向侧后边一点
        offset_z=-0.10  # 抓取点位于标签正下方
        temp_x_l=-0.035
        temp_y_l=0.035
        temp_x_r=-0.045
        temp_y_r=0.035
    else :
        offset_z=0.00
        temp_x_l=0.00
        temp_y_l=0.00
        temp_x_r=0.00
        temp_y_r=0.00
    # 角度偏移量(修正绕z轴的偏移角度)
    offset_angle=1.00

Euler Angle Settings

  • Usage example:
    • quat=ToQuaternion(relative_angle*offset_angle, -1.57 , 0)
    • eef_pose_msg.hand_poses.left_pose.quat_xyzw = [quat.x,quat.y,quat.z,quat.w]
  • ToQuaternion parameters:
    • Yaw angle: calculated from the current arm end-effector position and the target arm end-effector position
    • Pitch angle: fixed at negative 90 degrees for both the left and right hands
    • Roll angle: negative for the left hand and positive for the right hand; taking the right hand as an example, tests show that setting a negative value (0~20) gives better results

Running Steps

  1. Build the SDK environment
  • Run catkin build kuavo_sdk to build the SDK package
  • Run catkin build motion_capture_ik to build the IK package
  1. Lower computer: make the robot stand up
  • Simulation: roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch
  • Real robot: roslaunch humanoid_controllers load_kuavo_real.launch cali:=true
  1. Lower computer: start the IK solving service
  • Note: in some versions, the IK inverse kinematics service starts automatically when the robot is launched in the previous step; be careful not to start it twice
  • How to check: enter rosnode list | grep ik in the terminal
  • If /arms_ik_node already exists, skip this step
  • If /arms_ik_node does not exist, run:
    • Open a new terminal in the lab directory and run cd /home/lab/kuavo-ros-opensource ,

    • Run sudo su to switch to the root user,

    • Run source devel/setup.bash ,

    • Run roslaunch motion_capture_ik ik_node.launch ,

      cd kuavo-ros-opensource  # 进入下位机工作空间
      sudo su
      source devel/setup.bash
      roslaunch motion_capture_ik ik_node.launch 
  1. Send tag information (choose either simulation run or real robot run; do not run both at the same time)
  • Simulation run, lower computer: start the tag information mock tool

    • Open a new terminal and run cd kuavo-ros-opensource ,
    • Run sudo su to switch to the root user,
    • Run source devel/setup.bash ,
    • Run python3 src/demo/arm_capture_apriltag/mock_tag_publisher.py
  • Real robot run, upper computer: start the sensor

    • Open a new terminal and run cd kuavo_ros_application ,
    • Run source /opt/ros/noetic/setup.bash to switch to the ROS 1 environment ,
    • If connecting remotely to the upper computer desktop
      • If the upper computer is i7, run export DISPLAY=:1.0
      • If the upper computer is ORIN-NX or AGX-Orin, run export DISPLAY=:2.0
    • Run source devel/setup.bash ,
    • Launch the program according to the actual robot version:
    # 旧版4代, 4Pro
    roslaunch dynamic_biped load_robot_head.launch
    # 标准版, 进阶版, 展厅版, 展厅算力版
    roslaunch dynamic_biped load_robot_head.launch use_orbbec:=true
    # Max版
    roslaunch dynamic_biped load_robot_head.launch use_orbbec:=true enable_wrist_camera:=true
  1. Check whether the lower computer receives the tag information
  • On the lower computer, run rostopic list | grep tag
  • If /robot_tag_info exists
    • Run rostopic echo /robot_tag_info
    • Check whether the coordinate information of the tag is present
  • Notes:
    • When running on the real robot, you need to measure whether the obtained coordinate information is accurate
    • The upper computer can detect the angles of the robot's joints only after the lower computer program is started, so as to compute results based on the robot coordinate system
  1. Lower computer: start the QR code grasping workflow
  • Open a new terminal in the lab directory and run cd /home/lab/kuavo-ros-opensource ,

  • Run sudo su to switch to the root user,

  • Run source devel/setup.bash ,

  • Running on the real robot

    • Run python3 src/demo/arm_capture_apriltag/arm_capture_apriltag.py --offset_start True
  • Running in simulation

    • Run python3 src/demo/arm_capture_apriltag/arm_capture_apriltag.py --offset_start False
  • Note 1: If the simulation environment lags, increase the delays appropriately to ensure that every robot arm motion is fully executed, as shown below:

    • Change publish_arm_target_poses([1.5], [20.0, ...]) to publish_arm_target_poses([3], [20.0, ...])
    • Change time.sleep(2.5) to time.sleep(5)
  • Note 2: If using a gripper

    • Just run python3 src/demo/arm_capture_apriltag/claw_capture_apriltag.py; the parameters have the same meaning as in arm_capture_apriltag.py
    • This example was developed on a robot with a dexterous hand; the gripper robot has only been compatibly adapted. If you reproduce this example on a gripper robot, you need to additionally adjust the "ready pose" before grasping yourself

Real Robot Result Example

  • Ready pose

Ready pose

  • IK inverse kinematics motion

IK inverse kinematics motion

  • Handing over the water

Handing over the water