Feature ExamplesGeneral Examples
QR Code Water Bottle Grasping Example
- 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
- The robot lowers its head, and after a short delay obtains the averaged data of the AprilTag with the specified ID
- Sets the arm motion mode to external control
- Opens the hand and moves to the ready pose
- Calculates the IK solving parameters, performs IK solving, and moves using the IK result
- 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)
- 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

- 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'},
...
]- 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.jsonon the lower computer
- 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_sdkROS 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_infotopic to transmit the information
Lower Computer
- Set the arm motion mode
- Calls the ROS service
/arm_traj_change_modeto set the arm motion mode to external control mode
- Start the IK inverse kinematics service
- Calculates the IK inverse kinematics parameters and calls the ROS service
/ik/two_arm_hand_pose_cmd_srvto compute the inverse kinematics solution for the given coordinates and orientation. - Obtains the IK result: q_arm, the arm joint values (in radians)
- Control the robot head
- Publishes to the
/robot_head_motion_datatopic - Sets the joint data, including the yaw and pitch angles
- Control the opening and closing of the robot hand
- Publishes to the
/control_robot_hand_positiontopic - Sets the joint angles for closing or opening
- 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
- Obtain the QR code tag information
- Receives the AprilTagDetectionArray message from the
/robot_tag_infotopic - Obtains the average position of the AprilTag with the specified ID (based on the robot base coordinate system)
avg_off_horizontalcorresponds to the x-axisavg_off_cameracorresponds to the y-axisavg_off_verticalcorresponds to the z-axis
Running the Example
Launch Parameters
offset_start: whether to enable coordinate offsets- Entering
Truefor the parameter: enables coordinate offsets, generally used on the real robot to observe the grasping result - Entering
Falsefor the parameter: disables coordinate offsets, generally used in simulation to observe the solving result
- Entering
Coordinate Offsets
- Main parameters:
offset_zoffset in the z direction; by default the grasp point is directly below the QR code, so it is a negative valuetemp_x_l temp_x_roffsets in the x direction; both left and right are negative valuestemp_y_l temp_y_roffsets in the y direction; both are positive values, added for the left and subtracted for the rightoffset_angleangular 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
- If the grasp point is too high, decrease the value of
- Parameter location:
- In the
arm_capture_apriltag.pyfile, set in the main function - Usage example:
- In the
# 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.00Euler 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
- Build the SDK environment
- Run
catkin build kuavo_sdkto build the SDK package - Run
catkin build motion_capture_ikto build the IK package
- 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
- 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 ikin the terminal - If
/arms_ik_nodealready exists, skip this step - If
/arms_ik_nodedoes not exist, run:-
Open a new terminal in the lab directory and run
cd /home/lab/kuavo-ros-opensource, -
Run
sudo suto 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
-
- Send tag information (choose either
simulation runorreal 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 suto switch to the root user, - Run
source devel/setup.bash, - Run
python3 src/demo/arm_capture_apriltag/mock_tag_publisher.py
- Open a new terminal and run
-
Real robot run, upper computer: start the sensor- Open a new terminal and run
cd kuavo_ros_application, - Run
source /opt/ros/noetic/setup.bashto switch to the ROS 1 environment , - If connecting remotely to the upper computer desktop
- If the upper computer is
i7, runexport DISPLAY=:1.0 - If the upper computer is
ORIN-NXorAGX-Orin, runexport DISPLAY=:2.0
- If the upper computer is
- 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 - Open a new terminal and run
- Check whether the lower computer receives the tag information
- On the
lower computer, runrostopic list | grep tag - If
/robot_tag_infoexists- Run
rostopic echo /robot_tag_info - Check whether the coordinate information of the tag is present
- Run
- 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
- 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 suto 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
- Run
-
Running in simulation
- Run
python3 src/demo/arm_capture_apriltag/arm_capture_apriltag.py --offset_start False
- Run
-
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, ...])topublish_arm_target_poses([3], [20.0, ...]) - Change
time.sleep(2.5)totime.sleep(5)
- Change
-
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 inarm_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
- Just run
Real Robot Result Example
- Ready pose

- IK inverse kinematics motion

- Handing over the water
