YOLOV8 Recognition and Grasping Example
- Case Introduction
- Adjusting the Configuration File (Host Computer)
- Adjusting the Configuration File (Robot Controller)
- Code Compilation
- Running the Example
- ROS Topics and Services
Case Introduction
Introduction
- The robot identifies the target object with its head camera, computes the coordinate information and the grasping pose, and finally calculates the arm joint angles through IK inverse kinematics to perform the grasp.
Feature Description
- Identify the target object with YOLO to obtain the position of the grasping target in the coordinate frame
- Autonomously determine the left or right hand, and compute the desired position and orientation of the arm end effector
- Obtain the target angles of each arm joint through the IK inverse kinematics service
- Implement a smooth "grasp - lift - return" sequence
Workflow Logic
- The robot lowers its head and, after a short delay, acquires the averaged pose data of the target object with the specified ID
- Set the arm motion mode to external control
- Open the hand and move to the ready pose
- Compute the IK solving parameters, run the IK solver, and move using the IK result
- Close the hand, lift the object, open the hand, return the arm to its home pose, raise the robot's head, and the process ends
Real-Robot Video Demo
Adjusting the Configuration File (Host Computer)
- The configuration file is located at
~/kuavo_ros_application/src/ros_vision/detection_yolo_v8/config/params.yaml
Positioning Height Parameter Configuration (Important)
-
height_table
Purpose: sets the table height (in meters) on which the target is placed, used as the reference height for spatial positioning.
Example value: 0.864 -
height_bottle
Purpose: sets the actual height of the bottle target (in meters), used together with the image pixel coordinates to compute the target's actual 3D position.
Example value: 0.22 -
height_orange
Purpose: sets the actual height of the orange target (in meters), used together with the image pixel coordinates to compute the target's actual 3D position. Example value: 0.071 -
Notes:
- height_bottle and height_orange are the heights of the object body itself, not the height of the object in space
- If the detection confidence is low, you can lower
conf_thresholdappropriately (default0.5)
Adjusting the Configuration File (Robot Controller)
Code Check
The demo package on robot controller 1.4.0 is the version without waist rotation; run the following command to update it first.
cd ~/kuavo-ros-opensource
git fetch origin beta
git restore --source origin/beta --worktree --staged src/demo/yolo_object_captureProgram Runtime Configuration Parameters
- The grasping programs are located in
~/kuavo-ros-opensource/src/demo/yolo_object_capture/- Grasping a water bottle:
yolo_cylinder_capture.py - Grasping an orange:
yolo_sphere_capture.py
- Grasping a water bottle:
- Offset configuration file:
yolo_object_capture/config/offset.yaml
Launch Parameters
--use_offset: enable the grasping offset (recommended)--no_waist: disable the waist-rotation grasping logic- Note: the two parameters are independent; they can be used separately or together
Coordinate Offsets
- Configure the grasping offset in
yolo_object_capture/config/offset.yaml - Referenced to the
base_linkcoordinate frame (right-handed; the direction the robot faces is the positive x direction, and upward is the positive z direction) - Effective conditions:
- Takes effect only when the launch parameters include
--use_offsetand the currenttarget_idexists intargets - Otherwise, the offset is treated as
0.0andoffset_angleas1.0
- Takes effect only when the launch parameters include
- Example file structure:
targets:
"39": # 瓶子
offset:
z: 0.00
left:
x: -0.00
y: 0.03
right:
x: -0.00
y: -0.03
offset_angle: 0.15- Field descriptions:
targets: configurations grouped by target ID; different targets can use different offset parameters"39" / "41" / "49": YOLO target IDs (in the current example these correspond to bottle / cup / orange)offset.z: correction amount for the grasp point in the z direction (in meters), used inset_z = yolo_object_z + offset_zoffset.left.x / offset.left.y: correction amounts for x/y when grasping with the left hand (in meters)offset.right.x / offset.right.y: correction amounts for x/y when grasping with the right hand (in meters)offset_angle: yaw angle scaling factor (unitless), used inrelative_angle * offset_angle
- Tuning suggestions:
- Grasp point too high: decrease
offset.z; grasp point too low: increaseoffset.z - Grasp point too far forward: decrease
offset.*.xfor the corresponding hand; grasp point too far back: increaseoffset.*.x - Grasp point too far left: decrease
offset.*.yfor the corresponding hand; grasp point too far right: increaseoffset.*.y - End-effector orientation incorrect: fine-tune
offset_anglefirst
- Grasp point too high: decrease
- Additional notes:
- The default target ID of
yolo_cylinder_capture.pyis39, and the default target ID ofyolo_sphere_capture.pyis49 - If you add a new target category, you need to add the corresponding ID configuration in
offset.yaml; otherwise--use_offsetwill not take effect for that target
- The default target ID of
Euler Angle Settings
- The grasping script automatically computes the end-effector Euler angles from the target pose
- If the end-effector orientation deviates significantly, fine-tune the yaw direction first using
offset_angleinoffset.yaml
Code Compilation
Deploying the Remote Controller Service on the Host Computer (Skip This Step If Already Deployed)
cd ~/kuavo_ros_application/src/ros_audio/kuavo_audio_player/scripts
./deploy_autostart_h12pro.shHost Computer Code Compilation
cd ~/kuavo_ros_application #仓库目录
catkin build detection_yolo_v8Robot Controller Dependency Installation
sudo apt-get install ros-noetic-vision-msgsRunning the Example
Running Steps
Before starting, it is recommended to complete the automatic calibration of the head and arm limits first:
https://kuavo.lejurobot.com/manual/basic_usage/kuavo-ros-control/docs/3%E8%B0%83%E8%AF%95%E6%95%99%E7%A8%8B/%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%85%B3%E8%8A%82%E6%A0%87%E5%AE%9A/#%E5%A4%B4%E9%83%A8%E5%92%8C%E6%89%8B%E8%87%82%E9%9B%B6%E7%82%B9%E8%87%AA%E5%8A%A8%E6%A0%87%E5%AE%9A
1. Robot Controller: Make the Robot Stand Up
- Note: if the robot is already standing (for example, via the remote controller), you can skip this step
cd ~/kuavo-ros-opensource # 进入下位机工作空间
sudo su
source devel/setup.bash
# 仿真
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch
# 实物
roslaunch humanoid_controllers load_kuavo_real.launch cali:=true2. Robot Controller: 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; do not start it twice
- How to check: enter
rosnode list | grep ikin a terminal - If
/arms_ik_nodealready exists, skip this step - If
/arms_ik_nodedoes not exist, run:cd ~/kuavo-ros-opensource # 进入下位机工作空间 sudo su source devel/setup.bash roslaunch motion_capture_ik ik_node.launch
3. Host Computer: Start the YOLOv8 Detection Program
- Start the sensor
cd ~/kuavo_ros_application # 进入上位机工作空间
source devel/setup.bash
# 五代进阶版(无手腕相机)
roslaunch dynamic_biped kuavo5_sensor_only_enable.launch
# 五代MaxA版,MaxB版(有手腕相机)
roslaunch dynamic_biped kuavo5_sensor_only_enable.launch enable_wrist_camera:=true- Start the detection program
cd ~/kuavo_ros_application # 进入上位机工作空间
source devel/setup.bash
roslaunch detection_yolo_v8 detection.launch4. Robot Controller: Check Whether Label Information Is Received
- Run
rostopic list | grep yolov8 - If
/robot_yolov8_infoexists- Run
rostopic echo /robot_yolov8_info - Check whether the label coordinate information is present
- Run
- Notes:
- The coordinate information is position information in the robot's base_link coordinate frame
- If running on the real robot, measure whether the obtained coordinate information is accurate
- The host computer can detect the angles of the robot's joints and thereby compute results in the robot's coordinate frame only after the robot controller starts the program and the robot stands up
5. Robot Controller: Start the YOLOv8 Grasping Process
- Make sure steps 1-3 are running properly
- Example: grasping a water bottle:
cd ~/kuavo-ros-opensource # 进入下位机工作空间
source devel/setup.bash
# 带抓取偏移量, 自动转腰(推荐)
python3 src/demo/yolo_object_capture/yolo_cylinder_capture.py --use_offset
# 不带抓取偏移量, 不带转腰
python3 src/demo/yolo_object_capture/yolo_cylinder_capture.py --no_waist- Example: grasping an orange:
cd ~/kuavo-ros-opensource # 进入下位机工作空间
sudo su
source devel/setup.bash
# 带抓取偏移量, 自动转腰(推荐)
python3 src/demo/yolo_object_capture/yolo_sphere_capture.py --use_offset
# 不带抓取偏移量, 不带转腰
python3 src/demo/yolo_object_capture/yolo_sphere_capture.py --no_waist- Note: if the simulation lags, increase the delays appropriately to ensure that every robot arm motion completes, 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
ROS Topics and Services
Host Computer
- Start the sensor to identify YOLO target objects in real time and compute their positions in the robot's base coordinate frame
- Publish the
/robot_yolov8_infotopic to pass the information
Robot Controller
- Set the arm motion mode
- Call the ROS service
/arm_traj_change_modeto set the arm motion mode to external control mode
- Start the IK inverse kinematics service
- Compute the IK solving parameters and call the ROS service
/ik/two_arm_hand_pose_cmd_srvto calculate the inverse kinematics solution for the given position and orientation. - Obtain the IK result: q_arm: arm joint values (in radians)
- Control the robot head
- Publish to the
/robot_head_motion_datatopic - Set the joint data, including the yaw and pitch angles
- Control the opening and closing of the robot hand
- Publish to the
/control_robot_hand_positiontopic - Set the joint angles for closing or opening
- Control the opening and closing of the robot gripper
- Call the ROS service
/control_robot_leju_claw - Set the gripper opening/closing angle
- Obtain YOLO label information
- Receive Detection2DArray messages from the
/robot_yolov8_infotopic - Obtain the average position of the YOLO target object with the specified ID (in the robot's base coordinate frame)
- Receive Detection2DArray messages from the