Kuavo 5-W Interface Usage Documentation
This document describes in detail the ROS topics and service interfaces for controlling the wheeled base and robotic arms of the Kuavo 5-W robot. Through these interfaces, developers can precisely control each part of the robot and analyze the time reachability and control performance of commands.
Table of Contents
Related File Directory
src/demo/test_kuavo_wheel_real contains real-robot test cases for reference.
Published Topics
Functional topics can be divided into three categories: chassis control, lower-limb control, and upper-limb control.
Notes:
- Each category contains multiple topics, and each topic has a different priority, which must be taken into account when calling them;
- All position control topics, including joint control, use time-optimal planning, with the MPC automatically adjusting the arrival time, so desired forms such as step, triangular, and sinusoidal are all supported;
- For all position control topics, after a command is issued, the corresponding time topic feeds back the arrival time, indicating the execution time required for the corresponding action; you are free to choose whether to use it;
- All position control topics support both single-shot and repeated sending;
- In the case of repeated sending, second-order continuity and third-order differentiability are maintained; there is distortion, but kinematic limits are satisfied, so please feel free to use repeated sending;
- Commands of different categories do not interrupt each other, while commands of the same category do; after interruption, the robot follows the new command along an interpolated trajectory that satisfies kinematic limits;
- Complete test cases are provided on the real robot; please refer to the files in the current directory;
Chassis Interfaces
- /cmd_vel - Body-frame velocity control
- /cmd_vel_world - World-frame velocity control
- /cmd_pose - Body-frame position control
- /cmd_pose_world - World-frame position control (position topic)
Lower-Limb Control Interfaces
- /lb_leg_traj - Leg joint control
- /cmd_lb_torso_pose - Torso pose control relative to the base
- /cmd_torso_vel - Torso velocity control
- /cmd_torso_delta - Torso incremental control
Upper-Limb Control Interfaces
- /cmd_head_vel - Head angular velocity control
- /cmd_head_delta - Head incremental control
- /kuavo_arm_traj - Arm joint control
- /mm/two_arm_hand_pose_cmd - Dual-arm hand Cartesian pose control
Subscribed Topics
Arrival Time Feedback
- /lb_cmd_pose_reach_time - Chassis pose arrival time feedback
- /lb_leg_joint_reach_time - Lower-limb joint command arrival time feedback
- /lb_torso_pose_reach_time - Torso Cartesian pose arrival time feedback
- /lb_arm_joint_reach_time - Upper-limb joint command arrival time feedback
- /lb_arm_ee_reach_time - Dual-arm hand Cartesian pose arrival time feedback
Wheel-Arm MPC Current Mode Feedback
MPC Debug Information Feedback (stored in bag)
- /mobile_manipulator/currentMpcTarget/state - The cost-desired state of the wheel-arm MPC at the current moment
- /mobile_manipulator/currentMpcTarget/input - The cost-desired input of the wheel-arm MPC at the current moment
- /mobile_manipulator/torso_target_6D - The torso Cartesian desired value of the wheel-arm MPC at the current moment
- /mobile_manipulator/ee_target_6D/point - The arm end-effector Cartesian desired value of the wheel-arm MPC at the current moment
Controller Debug Information Feedback (stored in bag)
- /mobile_manipulator_wbc_observation - Raw sensor data received by the robot
- /mobile_manipulator_mpc_observation - Raw sensor data filtered before being input to the wheel-arm MPC )
- /humanoid_wheel/optimizedState_mrt - The native MRT state desired value output by the MPC
- /humanoid_wheel/optimizedInput_mrt - The native MRT input desired value output by the MPC
- /humanoid_wheel/optimizedState_mrt_kinemicLimit - The MRT state desired value after kinematic limit filtering
- /humanoid_wheel/optimizedInput_mrt_kinemicLimit - The MRT input desired value after kinematic limit filtering
- /humanoid_wheel/bodyAcc - Chassis acceleration solved by the WBC
- /humanoid_wheel/jointAcc - Joint accelerations solved by the WBC, including lower and upper limbs
- /humanoid_wheel/torque - Joint torques solved by the WBC, including lower and upper limbs
- /humanoid_wheel/eePoses - 6D poses of both arm end-effectors in the world frame
Called Services
- /enable_lb_arm_quick_mode - Joint quick mode switching
- /mobile_manipulator_mpc_control - MPC control mode switching
- /enable_control - Software pause/resume
ROS Topic Interfaces
Published Topics
1. /cmd_vel - Body-frame velocity control
Message type: geometry_msgs/Twist
Function description: Sends velocity control commands for the robot base; the x direction points to the robot's current forward direction.
Notes:
- Highest priority among chassis commands;
- If zero velocity is sent or no msg is sent, the robot stops automatically after 1 second;
Field description:
geometry_msgs/Vector3 linear:
float64 x # X方向线速度(米/秒),正值向前
float64 y # Y方向线速度(米/秒),正值向左
float64 z # Z方向线速度(米/秒),不起作用,可不设置
geometry_msgs/Vector3 angular:
float64 x # Roll轴角速度(弧度/秒),不起作用,可不设置
float64 y # Pitch轴角速度(弧度/秒),不起作用,可不设置
float64 z # Yaw轴角速度(弧度/秒),正值逆时针旋转Related demo script: cmd_vel_base_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# 初始化ROS节点
rospy.init_node('cmd_vel_publisher')
# 创建发布者
cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_vel_msg = Twist()
cmd_vel_msg.linear.x = 0.5 # 本体系 x 方向速度 (m/s)
cmd_vel_msg.linear.y = 0.0 # 本体系 y 方向速度 (m/s)
cmd_vel_msg.linear.z = 0.0
cmd_vel_msg.angular.x = 0.0
cmd_vel_msg.angular.y = 0.0
cmd_vel_msg.angular.z = 1.57 # 本体系旋转(偏航)角速度,单位为弧度/秒 (rad/s)
cmd_vel_pub.publish(cmd_vel_msg)
print("cmd_vel 消息已发布")2. /cmd_vel_world - World-frame velocity control
Message type: geometry_msgs/Twist
Function description: Sends velocity control commands for the robot base; the x direction points to the forward direction the robot was facing when it started up.
Notes:
- Lower priority than cmd_vel among chassis commands;
- If zero velocity is sent or no msg is sent, the robot stops automatically after 1 second;
Field description:
geometry_msgs/Vector3 linear:
float64 x # X方向线速度(米/秒),世界系的x方向前进
float64 y # Y方向线速度(米/秒),世界系的y方向前进
float64 z # Z方向线速度(米/秒),不起作用,可不设置
geometry_msgs/Vector3 angular:
float64 x # Roll轴角速度(弧度/秒),不起作用,可不设置
float64 y # Pitch轴角速度(弧度/秒),不起作用,可不设置
float64 z # Yaw轴角速度(弧度/秒),正值逆时针旋转Related demo script: cmd_vel_world_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# 初始化ROS节点
rospy.init_node('cmd_vel_world_publisher')
# 创建发布者
cmd_vel_world_pub = rospy.Publisher('/cmd_vel_world', Twist, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_vel_world_msg = Twist()
cmd_vel_world_msg.linear.x = 0.1 # 世界系 x 方向速度 (m/s)
cmd_vel_world_msg.linear.y = 0.0 # 世界系 y 方向速度 (m/s)
cmd_vel_world_msg.linear.z = 0.0
cmd_vel_world_msg.angular.x = 0.0
cmd_vel_world_msg.angular.y = 0.0
cmd_vel_world_msg.angular.z = 0.0 # 世界系旋转(偏航)角速度,单位为弧度/秒 (rad/s)
# 发布消息
cmd_vel_world_pub.publish(cmd_vel_world_msg)
print("cmd_vel_world 消息已发布")3. /cmd_pose - Body-frame position control
Message type: geometry_msgs/Twist
Function description: Sends relative position control commands for the robot base, moving relative to the current position.
Notes:
- If the yaw desired value spans multiple turns, the robot will rotate multiple turns (e.g., 6.28 means the robot rotates one full turn);
- Same priority as cmd_pose_world; they can interrupt each other;
Field description:
geometry_msgs/Vector3 linear:
float64 x # X方向相对位移(米),正值向前,负值向后
float64 y # Y方向相对位移(米),正值向左,负值向右
float64 z # Z方向相对位移(米),不起作用,可不设置
geometry_msgs/Vector3 angular:
float64 x # Roll轴相对旋转角度(弧度),不起作用,可不设置
float64 y # Pitch轴相对旋转角度(弧度),不起作用,可不设置
float64 z # Yaw轴相对旋转角度(弧度),正值逆时针,负值顺时针Related demo script: cmd_pos_base_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# 初始化ROS节点
rospy.init_node('cmd_pose_publisher')
# 创建发布者
cmd_pose_pub = rospy.Publisher('/cmd_pose', Twist, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_pose_msg = Twist()
cmd_pose_msg.linear.x = 0.5 # 基于当前位置的 x 方向值 (m)
cmd_pose_msg.linear.y = 0.0 # 基于当前位置的 y 方向值 (m)
cmd_pose_msg.linear.z = 0.0 # 增量高度
cmd_pose_msg.angular.z = 0.0 # 基于当前位置旋转(偏航)的角度,单位为弧度 (radian)
# 发布消息
cmd_pose_pub.publish(cmd_pose_msg)
print("cmd_pose 消息已发布")4. /cmd_pose_world - World-frame position control
Message type: geometry_msgs/Twist
Function description: Sends absolute position control commands for the robot base in the world frame.
Notes:
- If the yaw desired value spans multiple turns, it will be calibrated back;
- Same priority as cmd_pose; they can interrupt each other;
Field description:
geometry_msgs/Vector3 linear:
float64 x # 世界坐标系X位置(米)
float64 y # 世界坐标系Y位置(米)
float64 z # 世界坐标系Z位置(米),通常为0.0
geometry_msgs/Vector3 angular:
float64 x # Roll轴绝对角度(弧度),通常为0.0
float64 y # Pitch轴绝对角度(弧度),通常为0.0
float64 z # Yaw轴绝对角度(弧度),0为机器人启动时的正前方Related demo script: cmd_pos_world_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# 初始化ROS节点
rospy.init_node('cmd_pose_world_publisher')
# 创建发布者
cmd_pose_world_pub = rospy.Publisher('/cmd_pose_world', Twist, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_pose_world_msg = Twist()
cmd_pose_world_msg.linear.x = 0.3 # 世界系 x 方向位置 (m)
cmd_pose_world_msg.linear.y = 0.0 # 世界系 y 方向位置 (m)
cmd_pose_world_msg.linear.z = 0.0 # 增量高度
cmd_pose_world_msg.angular.z = 0.0 # 基于当前位置旋转(偏航)的角度,单位为弧度 (radian)
# 发布消息
cmd_pose_world_pub.publish(cmd_pose_world_msg)
print("cmd_pose_world 消息已发布")5. /lb_leg_traj - Leg Joint Control
Message type: sensor_msgs/JointState
Function description: Publishes joint leg trajectory control commands, used to control the robot's leg joint motion.
Notes:
- The degrees of freedom is 4; a dimension error triggers an error print and the command is not executed. Unit: degrees;
- Priority is the same as
/cmd_lb_torso_pose; if mixed, they interrupt each other;
Field description:
Header header:
uint32 seq # 序列号,不起作用,可不设置
time stamp # 时间戳,不起作用,可不设置
string frame_id # 坐标系ID,不起作用,可不设置
string[] name # 关节名称数组,4个腿部关节,不起作用,可不设置
# ['joint1', 'joint2', 'joint3', 'joint4']
float64[] position # 关节位置数组,4个关节角度值(角度)
float64[] velocity # 关节速度数组,不起作用,可不设置
float64[] effort # 关节力矩数组,不起作用,可不设置Related demo script: cmd_leg_joint_test.py
Usage example
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
import time
# 初始化ROS节点
rospy.init_node('cmd_leg_joint_publisher')
# 创建发布者
cmd_leg_joint_pub = rospy.Publisher('/lb_leg_traj', JointState, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建JointState消息对象
cmd_leg_joint_msg = JointState()
cmd_leg_joint_msg.header.stamp = rospy.Time.now()
cmd_leg_joint_msg.position = [14.90, -32.01, 18.03, 0.0] # 腿部关节角度 (度)
# 发布消息
cmd_leg_joint_pub.publish(cmd_leg_joint_msg)
print("cmd_leg_joint 消息已发布")6. /cmd_lb_torso_pose - Torso Pose Relative to the Base Control
Message type: geometry_msgs/Twist
Function description: Controls the robot torso's 6DOF pose (3 positions + 3 attitude angles), based on the chassis coordinate system.
Notes:
- This robot has no y and roll degrees of freedom; setting them has no effect;
- Priority is the same as
/lb_leg_traj; if mixed, they interrupt each other; - Position is relative to the base coordinate system, attitude is relative to the torso coordinate system;
- When in the same tick as
/cmd_torso_vel//cmd_torso_delta, this topic (absolute pose) has higher priority; - During software pause (
/enable_control false), new messages are discarded;
Field description:
geometry_msgs/Vector3 linear:
float64 x # 躯干X位置(米),相对于基座坐标系
float64 y # 躯干Y位置(米),相对于基座坐标系,不起作用,可不设置
float64 z # 躯干Z位置(米),相对于基座坐标系
geometry_msgs/Vector3 angular:
float64 x # 躯干Roll角度(弧度),绕X轴旋转,不起作用,可不设置
float64 y # 躯干Pitch角度(弧度),绕Y轴旋转,正值前倾
float64 z # 躯干Yaw角度(弧度),绕Z轴旋转,正值左转Related demo script: cmd_torso_pose_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import time
# 初始化ROS节点
rospy.init_node('cmd_torso_pose_publisher')
# 创建发布者
cmd_torso_pose_pub = rospy.Publisher('/cmd_lb_torso_pose', Twist, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_torso_pose_msg = Twist()
cmd_torso_pose_msg.linear.x = 0.3 # 躯干 x 方向位置 (m)
cmd_torso_pose_msg.linear.y = 0.0 # 躯干 y 方向位置 (m)
cmd_torso_pose_msg.linear.z = 1.4 # 躯干 z 方向位置 (m)
cmd_torso_pose_msg.angular.x = 0.0 # 滚转角 (rad)
cmd_torso_pose_msg.angular.y = 0.0
cmd_torso_pose_msg.angular.z = -1.57 # 偏航角 (rad)
# 发布消息
cmd_torso_pose_pub.publish(cmd_torso_pose_msg)
print("cmd_torso_pose 消息已发布")7. /cmd_torso_vel - Torso Velocity Control
Message type: geometry_msgs/Twist
Function description: Sends torso instantaneous velocity control commands. The receiving side, RM, performs sticky integration: while non-zero velocity keeps being received, the pose accumulates; it stops after receiving zero velocity or on a 0.3s timeout.
Notes:
- The G12/BT2 remote controller's torso control mode issues joystick velocity commands via this topic (it does not publish
/cmd_torso_delta) /cmd_lb_torso_poseis absolute pose control, writing directly to the open-loop target (it acts on the samecmdTorsoPose_as vel/delta; they do not interrupt each other)- Handle reset goes through the service
/mobile_manipulator_reset_torso, not this topic - During software pause (
/enable_control false), new commands are discarded and the sticky velocity is cleared to zero
Field description:
geometry_msgs/Vector3 linear:
float64 x # 躯干X前后速度,m/s
float64 z # 躯干Z升降速度,m/s
geometry_msgs/Vector3 angular:
float64 y # 躯干Pitch前倾速度,rad/s
float64 z # 躯干Yaw角速度,rad/sUsage example
import rospy
from geometry_msgs.msg import Twist
pub = rospy.Publisher('/cmd_torso_vel', Twist, queue_size=1)
msg = Twist()
msg.linear.z = 0.05 # 躯干以 0.05 m/s 升高
pub.publish(msg)
# 停止:
msg.linear.z = 0.0
pub.publish(msg)8. /cmd_torso_delta - Torso Incremental Control
Message type: geometry_msgs/Twist
Function description: Sends a one-shot relative torso displacement (oneshot). Each message's increment is consumed once and then cleared.
Typical source: 5W single-hand teleoperation A/B button edges (yaw ±π). The G12/BT2 controller's torso mode currently only publishes /cmd_torso_vel, not this topic.
Field description:
geometry_msgs/Vector3 linear:
float64 x # 躯干X前后增量,m
float64 z # 躯干Z升降增量,m
geometry_msgs/Vector3 angular:
float64 z # 躯干Yaw增量,rad
float64 y # 躯干Pitch增量,radUsage example
import rospy
from geometry_msgs.msg import Twist
pub = rospy.Publisher('/cmd_torso_delta', Twist, queue_size=1)
msg = Twist()
msg.angular.z = 1.57 # 躯干左转 90°
pub.publish(msg)9. /cmd_head_vel - Head Angular Velocity Control
Message type: kuavo_msgs::robotHeadMotionData
Function description: Sends head instantaneous angular velocity control commands (deg/s). The receiving side, CDM/WBC, performs sticky integration, with a 0.3s timeout that automatically clears it to zero.
Notes:
- H12/G12 remote controller head control is issued via this topic
- Limits: yaw ±88°, pitch ±25°
Field description:
float64[] joint_data # 长度为2
joint_data[0] # 头部偏航角速度(yaw),deg/s
joint_data[1] # 头部俯仰角速度(pitch),deg/sUsage example
import rospy
from kuavo_msgs.msg import robotHeadMotionData
pub = rospy.Publisher('/cmd_head_vel', robotHeadMotionData, queue_size=1)
msg = robotHeadMotionData()
msg.joint_data = [30.0, 0.0] # 头部以 30°/s 右转
pub.publish(msg)10. /cmd_head_delta - Head Incremental Control
Message type: kuavo_msgs::robotHeadMotionData
Function description: Sends a one-shot relative head displacement (deg). Oneshot semantics.
Field description:
float64[] joint_data # 长度为2
joint_data[0] # 头部偏航增量(yaw),deg
joint_data[1] # 头部俯仰增量(pitch),degimport rospy
from kuavo_msgs.msg import robotHeadMotionData
pub = rospy.Publisher('/cmd_head_delta', robotHeadMotionData, queue_size=1)
msg = robotHeadMotionData()
msg.joint_data = [-15.0, 0.0] # 头部左转 15°
pub.publish(msg)11. /kuavo_arm_traj - Arm Joint Control
Message type: sensor_msgs/JointState
Function description: Publishes joint arm trajectory control commands, used to control the robot's arm joint motion.
Notes:
- The degrees of freedom is 14; a dimension error triggers an error print and the command is not executed. Unit: degrees;
- Priority is the same as /mm/two_arm_hand_pose_cmd; if mixed, they interrupt each other;
Field description:
Header header:
uint32 seq # 序列号,不起作用,可不设置
time stamp # 时间戳,不起作用,可不设置
string frame_id # 坐标系ID,不起作用,可不设置
string[] name # 关节名称数组,14个关节,不起作用,可不设置
# ['joint1', 'joint2', ..., 'joint14']
# 前7个为左臂关节,后7个为右臂关节
float64[] position # 关节位置数组,14个关节角度值(角度)
float64[] velocity # 关节速度数组,不起作用,可不设置
float64[] effort # 关节力矩数组,不起作用,可不设置Related demo script: cmd_arm_joint_test.py
Usage example
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
import time
import sys
import os
# 添加父目录到路径以便导入 lb_ctrl_api
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import lb_ctrl_api as ct
# 初始化ROS节点
rospy.init_node('cmd_arm_joint_publisher')
# 创建发布者
cmd_arm_joint_pub = rospy.Publisher('/kuavo_arm_traj', JointState, queue_size=10)
# 等待发布器建立连接
time.sleep(1)
# 设置控制模式为 ArmOnly (模式1)
ct.set_control_mode(1)
# 创建JointState消息对象
cmd_arm_joint_msg = JointState()
cmd_arm_joint_msg.header.stamp = rospy.Time.now()
cmd_arm_joint_msg.name = [f'joint{i}' for i in range(1, 15)] # 14 个关节名称
cmd_arm_joint_msg.position = [-30, 20, 15, -45, 25, 10, -35,
-30,-20,-15, -45,-25,-10, -35] # 14 个关节角度 (度)
# 发布消息
cmd_arm_joint_pub.publish(cmd_arm_joint_msg)
print("cmd_arm_joint 消息已发布")12. /mm/two_arm_hand_pose_cmd - Dual-arm hand Cartesian pose control
Message type: kuavo_msgs/twoArmHandPoseCmd
Description: Controls the pose of the hands on both arms.
Notes:
- Setting IK parameters is not supported;
- Sending commands in the world frame, local frame, and joint-space frame is supported; switch between them via frame, and construct the data via hand_poses;
- The priority is the same as /kuavo_arm_traj, and the two can interrupt each other.
Field description:
twoArmHandPose hand_poses: # 双臂手部位姿数据
Header header: # 消息头,不使用,可不设置
uint32 seq
time stamp
string frame_id
armHandPose left_pose: # 左臂位姿
float64[3] pos_xyz # 位置 [x, y, z] (米)
float64[4] quat_xyzw # 姿态四元数 [x, y, z, w]
float64[3] elbow_pos_xyz # 肘部位置 [x, y, z] (米),暂不支持,可不设置
float64[7] joint_angles # 7个关节角度 (度)
armHandPose right_pose: # 右臂位姿
float64[3] pos_xyz # 位置 [x, y, z] (米)
float64[4] quat_xyzw # 姿态四元数 [x, y, z, w]
float64[3] elbow_pos_xyz # 肘部位置 [x, y, z] (米),暂不支持,可不设置
float64[7] joint_angles # 7个关节角度 (度)
bool use_custom_ik_param # 是否使用自定义IK参数,暂不支持,可不设置
bool joint_angles_as_q0 # 关节角度是否作为IK求解初值,暂不支持,可不设置
ikSolveParam ik_param # IK 逆解参数配置,暂不支持,可不设置
int32 frame # 坐标系选择,与人形兼容,但仅支持部分
# 0: 保持当前坐标系 (keep current frame)
# 1: 世界坐标系 (world frame, based on odom)
# 2: 本地坐标系 (local frame)
# 5: 关节空间坐标系 (Joint Space frame)Related demo scripts:
-
cmd_arm_ee_world_test.py- Example of end-effector pose control in the world frame (frame = 1) -
cmd_arm_ee_local_test.py- Example of end-effector pose control in the local frame (frame = 2) -
cmd_arm_ee_joint_test.py- Example of joint angle control (frame = 5) -
Usage example
#!/usr/bin/env python import rospy import numpy as np from std_msgs.msg import Header from kuavo_msgs.msg import twoArmHandPoseCmd, twoArmHandPose, armHandPose, ikSolveParam import tf.transformations as tf_trans import time import os import sys # 添加父目录到路径以便导入 lb_ctrl_api sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import lb_ctrl_api as ct # 初始化ROS节点 rospy.init_node('cmd_arm_ee_publisher') # 创建发布者 cmd_arm_ee_pub = rospy.Publisher('/mm/two_arm_hand_pose_cmd', twoArmHandPoseCmd, queue_size=10) # 等待发布器建立连接 time.sleep(1) # 设置控制模式为 ArmOnly (模式1) ct.set_control_mode(1) # 构建手部位姿函数 def build_hand_pose(x, y, z, yaw, pitch, roll): """根据 x,y,z,yaw,pitch,roll 构造 armHandPose""" pose = armHandPose() pose.pos_xyz = [x, y, z] quat = tf_trans.quaternion_from_euler(np.radians(roll), np.radians(pitch), np.radians(yaw)) quat_norm = quat / np.linalg.norm(quat) if np.linalg.norm(quat) > 1e-8 else [0, 0, 0, 1] pose.quat_xyzw = quat_norm.tolist() pose.elbow_pos_xyz = [0.0, 0.0, 0.0] pose.joint_angles = [0.0] * 7 return pose # 构建IK参数 def build_ik_param(): """构造默认 IK 参数""" p = ikSolveParam() p.major_optimality_tol = 1e-6 p.major_feasibility_tol = 1e-6 p.minor_feasibility_tol = 1e-6 p.major_iterations_limit = 1000 p.oritation_constraint_tol = 0.01 p.pos_constraint_tol = 0.01 p.pos_cost_weight = 1.0 return p # 创建双臂手部位姿命令消息 cmd_arm_ee_msg = twoArmHandPoseCmd() cmd_arm_ee_msg.hand_poses = twoArmHandPose() cmd_arm_ee_msg.hand_poses.header = Header(stamp=rospy.Time.now(), frame_id="base_link") # 左手位置: [x, y, z, yaw, pitch, roll] cmd_arm_ee_msg.hand_poses.left_pose = build_hand_pose(0.0, 0.4, 0.0, 0.0, 0.0, 0.0) # 右手位置: [x, y, z, yaw, pitch, roll] cmd_arm_ee_msg.hand_poses.right_pose = build_hand_pose(0.0, -0.4, 0.0, 0.0, 0.0, 0.0) cmd_arm_ee_msg.use_custom_ik_param = True cmd_arm_ee_msg.joint_angles_as_q0 = False cmd_arm_ee_msg.ik_param = build_ik_param() cmd_arm_ee_msg.frame = 2 # local frame (2=local, 1=world) # 发布消息 cmd_arm_ee_pub.publish(cmd_arm_ee_msg) print("cmd_arm_ee 消息已发布")
Subscribed Topics
1. /lb_cmd_pose_reach_time - Chassis pose reach time feedback
Message type: std_msgs/Float32
Description: When a new cmd_pose or cmd_pose_world message is issued, the time required for execution is published at the same time.
Field description:
float32 data # 预计到达时间(秒),假如收到2,则表示2秒后执行完成Related demo scripts:
-
cmd_pos_base_test.py -
cmd_pos_world_test.pyUsage example
#!/usr/bin/env python import rospy from geometry_msgs.msg import Twist from std_msgs.msg import Float32 import time # 全局变量 reachTime = 0.0 def time_callback(msg): """时间回调函数""" global reachTime reachTime = msg.data print(f"reach_time is {reachTime:.3f} s") # 初始化ROS节点 rospy.init_node('cmd_pose_reach_time_subscriber', anonymous=True) # 创建发布者 cmd_pose_pub = rospy.Publisher('/cmd_pose', Twist, queue_size=10) # 创建订阅者 time_sub = rospy.Subscriber('/lb_cmd_pose_reach_time', Float32, time_callback) # 等待发布器和订阅器建立连接 time.sleep(1) # 创建Twist消息对象 cmd_pose_msg = Twist() cmd_pose_msg.linear.x = 0.5 # 基于当前位置的 x 方向值 (m) cmd_pose_msg.linear.y = 0.0 # 基于当前位置的 y 方向值 (m) cmd_pose_msg.linear.z = 0.0 # 增量高度 cmd_pose_msg.angular.z = 0.0 # 基于当前位置旋转(偏航)的角度,单位为弧度 (radian) # 发布消息 cmd_pose_pub.publish(cmd_pose_msg) print("cmd_pose 消息已发布,开始订阅 /lb_cmd_pose_reach_time 话题...") # 保持节点运行 rospy.spin()
2. /lb_leg_joint_reach_time - Lower-limb joint command reach time feedback
Message type: std_msgs/Float32
Description: When a new lb_leg_traj message is issued, the time required for execution is published at the same time.
Field description:
float32 data # 预计到达时间(秒),假如收到2,则表示2秒后执行完成Related demo scripts:
cmd_leg_joint_test.py
Usage example
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Float32
import time
# 全局变量
reachTime = 0.0
def time_callback(msg):
"""时间回调函数"""
global reachTime
reachTime = msg.data
print(f"reach_time is {reachTime:.3f} s")
# 初始化ROS节点
rospy.init_node('cmd_leg_joint_reach_time_subscriber', anonymous=True)
# 创建发布者
cmd_leg_joint_pub = rospy.Publisher('/lb_leg_traj', JointState, queue_size=10)
# 创建订阅者
time_sub = rospy.Subscriber('/lb_leg_joint_reach_time', Float32, time_callback)
# 等待发布器和订阅器建立连接
time.sleep(1)
# 创建JointState消息对象
cmd_leg_joint_msg = JointState()
cmd_leg_joint_msg.header.stamp = rospy.Time.now()
cmd_leg_joint_msg.position = [14.90, -32.01, 18.03, 0.0] # 腿部关节角度 (度)
# 发布消息
cmd_leg_joint_pub.publish(cmd_leg_joint_msg)
print("cmd_leg_joint 消息已发布,开始订阅 /lb_leg_joint_reach_time 话题...")
# 保持节点运行
rospy.spin()3. /lb_torso_pose_reach_time - Torso Cartesian pose reach time feedback
Message type: std_msgs/Float32
Description: When a new cmd_lb_torso_pose message is issued, the time required for execution is published at the same time.
Field description:
float32 data # 预计到达时间(秒),假如收到2,则表示2秒后执行完成Related demo scripts:
cmd_torso_pose_test.py
Usage example
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from std_msgs.msg import Float32
import time
# 全局变量
reachTime = 0.0
def time_callback(msg):
"""时间回调函数"""
global reachTime
reachTime = msg.data
print(f"reach_time is {reachTime:.3f} s")
# 初始化ROS节点
rospy.init_node('cmd_torso_pose_reach_time_subscriber', anonymous=True)
# 创建发布者
cmd_torso_pose_pub = rospy.Publisher('/cmd_lb_torso_pose', Twist, queue_size=10)
# 创建订阅者
time_sub = rospy.Subscriber('/lb_torso_pose_reach_time', Float32, time_callback)
# 等待发布器和订阅器建立连接
time.sleep(1)
# 创建Twist消息对象
cmd_torso_pose_msg = Twist()
cmd_torso_pose_msg.linear.x = 0.196123 # 躯干 x 方向位置 (m)
cmd_torso_pose_msg.linear.y = 0.0005 # 躯干 y 方向位置 (m)
cmd_torso_pose_msg.linear.z = 0.789919 # 躯干 z 方向位置 (m)
cmd_torso_pose_msg.angular.x = 0.0 # 滚转角 (rad)
cmd_torso_pose_msg.angular.y = 0.0 # 俯仰角 (rad)
cmd_torso_pose_msg.angular.z = 0.0 # 偏航角 (rad)
# 发布消息
cmd_torso_pose_pub.publish(cmd_torso_pose_msg)
print("cmd_torso_pose 消息已发布,开始订阅 /lb_torso_pose_reach_time 话题...")
# 保持节点运行
rospy.spin()4. /lb_arm_joint_reach_time - Upper-Limb Joint Command Reach Time Feedback
Message type: std_msgs/Float32
Function description: When joint-space control is issued on the new kuavo_arm_traj topic or the /mm/two_arm_hand_pose_cmd topic, the time required for execution is published at the same time.
Field description:
float32 data # 预计到达时间(秒),假如收到2,则表示2秒后执行完成Related demo scripts:
cmd_arm_joint_test.pycmd_arm_ee_joint_test.py
Usage example
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Float32
import time
import sys
import os
# 添加父目录到路径以便导入 lb_ctrl_api
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import lb_ctrl_api as ct
# 全局变量
reachTime = 0.0
def time_callback(msg):
"""时间回调函数"""
global reachTime
reachTime = msg.data
print(f"reach_time is {reachTime:.3f} s")
# 初始化ROS节点
rospy.init_node('cmd_arm_joint_reach_time_subscriber', anonymous=True)
# 创建发布者
cmd_arm_joint_pub = rospy.Publisher('/kuavo_arm_traj', JointState, queue_size=10)
# 创建订阅者
time_sub = rospy.Subscriber('/lb_arm_joint_reach_time', Float32, time_callback)
# 等待发布器和订阅器建立连接
time.sleep(1)
# 设置控制模式为 ArmOnly (模式1)
ct.set_control_mode(1)
# 创建JointState消息对象
cmd_arm_joint_msg = JointState()
cmd_arm_joint_msg.header.stamp = rospy.Time.now()
cmd_arm_joint_msg.name = [f'joint{i}' for i in range(1, 15)] # 14 个关节名称
cmd_arm_joint_msg.position = [-30, 20, 15, -45, 25, 10, -35,
-30,-20,-15, -45,-25,-10, -35] # 14 个关节角度 (度)
# 发布消息
cmd_arm_joint_pub.publish(cmd_arm_joint_msg)
print("cmd_arm_joint 消息已发布,开始订阅 /lb_arm_joint_reach_time 话题...")
# 保持节点运行
rospy.spin()5. /lb_arm_ee_reach_time - Dual-Arm Hand Cartesian Pose Reach Time Feedback
Message type: std_msgs/Float32
Function description: When world-frame or local-frame control is issued on the new /mm/two_arm_hand_pose_cmd topic, the time required for execution is published at the same time.
Field description:
float32 data # 预计到达时间(秒),假如收到2,则表示2秒后执行完成Related demo scripts:
cmd_arm_ee_world_test.pycmd_arm_ee_local_test.py
Usage example
#!/usr/bin/env python
import rospy
import numpy as np
from std_msgs.msg import Header, Float32
from kuavo_msgs.msg import twoArmHandPoseCmd, twoArmHandPose, armHandPose, ikSolveParam
import tf.transformations as tf_trans
import os
import sys
# 添加父目录到路径以便导入 lb_ctrl_api
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import lb_ctrl_api as ct
# 全局变量
reachTime = 0.0
def time_callback(msg):
"""时间回调函数"""
global reachTime
reachTime = msg.data
print(f"reach_time is {reachTime:.3f} s")
# 初始化ROS节点
rospy.init_node('cmd_arm_ee_reach_time_subscriber', anonymous=True)
# 创建发布者
cmd_arm_ee_pub = rospy.Publisher('/mm/two_arm_hand_pose_cmd', twoArmHandPoseCmd, queue_size=10)
# 创建订阅者
time_sub = rospy.Subscriber('/lb_arm_ee_reach_time', Float32, time_callback)
# 等待发布器和订阅器建立连接
rospy.sleep(1.0)
# 设置控制模式为 ArmOnly (模式1)
ct.set_control_mode(1)
# 构建手部位姿函数
def build_hand_pose(x, y, z, yaw, pitch, roll):
"""根据 x,y,z,yaw,pitch,roll 构造 armHandPose"""
pose = armHandPose()
pose.pos_xyz = [x, y, z]
quat = tf_trans.quaternion_from_euler(np.radians(roll), np.radians(pitch), np.radians(yaw))
quat_norm = quat / np.linalg.norm(quat) if np.linalg.norm(quat) > 1e-8 else [0, 0, 0, 1]
pose.quat_xyzw = quat_norm.tolist()
pose.elbow_pos_xyz = [0.0, 0.0, 0.0]
pose.joint_angles = [0.0] * 7
return pose
# 构建IK参数
def build_ik_param():
"""构造默认 IK 参数"""
p = ikSolveParam()
p.major_optimality_tol = 1e-6
p.major_feasibility_tol = 1e-6
p.minor_feasibility_tol = 1e-6
p.major_iterations_limit = 1000
p.oritation_constraint_tol = 0.01
p.pos_constraint_tol = 0.01
p.pos_cost_weight = 1.0
return p
# 创建双臂手部位姿命令消息
cmd_arm_ee_msg = twoArmHandPoseCmd()
cmd_arm_ee_msg.hand_poses = twoArmHandPose()
cmd_arm_ee_msg.hand_poses.header = Header(stamp=rospy.Time.now(), frame_id="base_link")
# 左手位置: [x, y, z, yaw, pitch, roll]
cmd_arm_ee_msg.hand_poses.left_pose = build_hand_pose(0.0, 0.4, 0.0, 0.0, 0.0, 0.0)
# 右手位置: [x, y, z, yaw, pitch, roll]
cmd_arm_ee_msg.hand_poses.right_pose = build_hand_pose(0.0, -0.4, 0.0, 0.0, 0.0, 0.0)
cmd_arm_ee_msg.use_custom_ik_param = True
cmd_arm_ee_msg.joint_angles_as_q0 = False
cmd_arm_ee_msg.ik_param = build_ik_param()
cmd_arm_ee_msg.frame = 2 # local frame (2=local, 1=world)
# 发布消息
cmd_arm_ee_pub.publish(cmd_arm_ee_msg)
print("cmd_arm_ee 消息已发布,开始订阅 /lb_arm_ee_reach_time 话题...")
# 保持节点运行
rospy.spin()6. /mobile_manipulator/lb_mpc_control_mode - Feedback of the Current Control Mode of the Wheeled-Arm MPC
Message type: std_msgs/Int8
Function description: Publishes the current MPC control mode of the wheeled-arm robot at 50 Hz.
Field description:
Int8 data # MPC模式,分别包括: 1. ArmOnly, 2. BaseOnly, 3. BaseArm, 4. ArmEeOnly
# 0: NoControl - 无控制
# 1: ArmOnly - 仅控制手臂,基座固定
# 2: BaseOnly - 仅控制基座,手臂固定
# 3: BaseArm - 同时控制基座和手臂
# 4: ArmEeOnly - 仅控制手臂末端7. /mobile_manipulator/currentMpcTarget/state - The Cost-Expected State of the Wheeled-Arm MPC at the Current Moment
Message type: std_msgs::Float64MultiArray
Function description: Stores the position references for the base, lower-limb, and upper-limb joints. Depending on the control mode, they may be ignored when the corresponding part is not enabled.
Field description:
Float64MultiArray data # 数据格式(共3+4+14自由度):[base位姿(x, y, yaw)(3), 下肢关节位置(4), 上肢关节位置(14)]Usage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int8
def control_mode_callback(msg):
"""控制模式回调函数"""
mode = msg.data
mode_names = {
0: "NoControl - 无控制",
1: "ArmOnly - 仅控制手臂,基座固定",
2: "BaseOnly - 仅控制基座,手臂固定",
3: "BaseArm - 同时控制基座和手臂",
4: "ArmEeOnly - 仅控制手臂末端"
}
mode_name = mode_names.get(mode, f"未知模式({mode})")
print(f"当前MPC控制模式: {mode} - {mode_name}")
# 初始化ROS节点
rospy.init_node('sub_lb_mpc_control_mode', anonymous=True)
# 创建订阅者
control_mode_sub = rospy.Subscriber(
'/mobile_manipulator/lb_mpc_control_mode',
Int8,
control_mode_callback
)
print("开始订阅 /mobile_manipulator/lb_mpc_control_mode 话题...")
# 保持节点运行
rospy.spin()8. /mobile_manipulator/currentMpcTarget/input - The Cost-Expected Input of the Wheeled-Arm MPC at the Current Moment
Message type: std_msgs::Float64MultiArray
Function description: Stores the velocity references for the base, lower-limb, and upper-limb joints. Depending on the control mode, they may be ignored when the corresponding part is not enabled.
Field description:
Float64MultiArray data # 数据格式(共3+4+14自由度):[base速度(x, y, yaw)(3), 下肢关节速度(4), 上肢关节速度(14)]
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def mpc_target_state_callback(msg):
"""MPC目标状态回调函数"""
data = msg.data
if len(data) != 21:
print(f"警告: 数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_pose = data[0:3] # base位姿(x, y, yaw) - 3个
leg_joints = data[3:7] # 下肢关节位置 - 4个
arm_joints = data[7:21] # 上肢关节位置 - 14个
print("=" * 60)
print("MPC目标状态 (currentMpcTarget/state):")
print(f" 底盘位姿 (x, y, yaw): [{base_pose[0]:.4f}, {base_pose[1]:.4f}, {base_pose[2]:.4f}]")
print(f" 下肢关节位置 (4个): {[f'{x:.4f}' for x in leg_joints]}")
print(f" 上肢关节位置 (14个): {[f'{x:.4f}' for x in arm_joints]}")
# 初始化ROS节点
rospy.init_node('sub_current_mpc_target_state', anonymous=True)
# 创建订阅者
mpc_target_state_sub = rospy.Subscriber(
'/mobile_manipulator/currentMpcTarget/state',
Float64MultiArray,
mpc_target_state_callback
)
print("开始订阅 /mobile_manipulator/currentMpcTarget/state 话题...")
# 保持节点运行
rospy.spin()9. /mobile_manipulator/torso_target_6D - The Cartesian Torso Target of the Wheeled-Arm MPC at the Current Moment
Message type: std_msgs::Float64MultiArray
Function description: Stores the 6D Cartesian torso target. Depending on the control mode, it may be ignored when not enabled.
Field description:
Float64MultiArray data # 数据格式(共6自由度):[躯干位姿(x, y, z, yaw, pitch, roll)]
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def torso_target_6d_callback(msg):
"""躯干6D目标回调函数"""
data = msg.data
if len(data) != 6:
print(f"警告: 数据长度不正确,期望6,实际{len(data)}")
return
# 解析数据: [x, y, z, yaw, pitch, roll]
x = data[0]
y = data[1]
z = data[2]
yaw = data[3]
pitch = data[4]
roll = data[5]
print("=" * 60)
print("躯干6D目标 (torso_target_6D):")
print(f" 位置 (x, y, z): [{x:.4f}, {y:.4f}, {z:.4f}]")
print(f" 姿态 (yaw, pitch, roll): [{yaw:.4f}, {pitch:.4f}, {roll:.4f}]")
print(f" 姿态 (度): [{yaw*180/3.14159:.2f}°, {pitch*180/3.14159:.2f}°, {roll*180/3.14159:.2f}°]")
# 初始化ROS节点
rospy.init_node('sub_torso_target_6d', anonymous=True)
# 创建订阅者
torso_target_6d_sub = rospy.Subscriber(
'/mobile_manipulator/torso_target_6D',
Float64MultiArray,
torso_target_6d_callback
)
print("开始订阅 /mobile_manipulator/torso_target_6D 话题...")
# 保持节点运行
rospy.spin()10. /mobile_manipulator/ee_target_6D/point - Cartesian end-effector setpoint of the wheeled-arm MPC for the current moment
Message type: std_msgs::Float64MultiArray
Description: Stores the Cartesian setpoints for both arm end effectors. Depending on the control mode, they may be ignored when not enabled.
Note: An index must be appended after point; currently point0 and point1 are supported, corresponding to the left arm and right arm respectively.
Field description:
Float64MultiArray data # 数据格式(共6自由度):[末端位姿(x, y, z, yaw, pitch, roll)]
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataExample usage
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
# 存储最新的数据
left_arm_data = None
right_arm_data = None
def ee_target_6d_callback(msg, arm_name):
"""手臂末端6D目标回调函数"""
global left_arm_data, right_arm_data
data = msg.data
if len(data) != 6:
print(f"警告: {arm_name}数据长度不正确,期望6,实际{len(data)}")
return
# 解析数据: [x, y, z, yaw, pitch, roll]
x = data[0]
y = data[1]
z = data[2]
yaw = data[3]
pitch = data[4]
roll = data[5]
# 保存数据
if arm_name == "左臂":
left_arm_data = data
else:
right_arm_data = data
print("=" * 60)
print(f"{arm_name}末端6D目标 (ee_target_6D):")
print(f" 位置 (x, y, z): [{x:.4f}, {y:.4f}, {z:.4f}]")
print(f" 姿态 (yaw, pitch, roll): [{yaw:.4f}, {pitch:.4f}, {roll:.4f}]")
print(f" 姿态 (度): [{yaw*180/3.14159:.2f}°, {pitch*180/3.14159:.2f}°, {roll*180/3.14159:.2f}°]")
def left_arm_callback(msg):
"""左臂回调函数"""
ee_target_6d_callback(msg, "左臂")
def right_arm_callback(msg):
"""右臂回调函数"""
ee_target_6d_callback(msg, "右臂")
# 初始化ROS节点
rospy.init_node('sub_ee_target_6d', anonymous=True)
# 创建订阅者 - 左臂 (point0)
left_arm_sub = rospy.Subscriber(
'/mobile_manipulator/ee_target_6D/point0',
Float64MultiArray,
left_arm_callback
)
# 创建订阅者 - 右臂 (point1)
right_arm_sub = rospy.Subscriber(
'/mobile_manipulator/ee_target_6D/point1',
Float64MultiArray,
right_arm_callback
)
print("开始订阅手臂末端6D目标话题...")
print(" - /mobile_manipulator/ee_target_6D/point0 (左臂)")
print(" - /mobile_manipulator/ee_target_6D/point1 (右臂)")
# 保持节点运行
rospy.spin()11. /mobile_manipulator_wbc_observation - Raw sensor data received by the robot
Message type: std_msgs::Float64MultiArray
Description: Raw sensor data received by the robot.
Note: Append /state or /input after /mobile_manipulator_wbc_observation to denote state and input respectively.
Field description:
Float64 time # MPC 模块内部时间
int64 mode # MPC 的步态,不是人形,无效,不需要注意
Float64MultiArray state # 数据格式(共3+4+14自由度):[base位姿(x, y, yaw)(3), 下肢关节位置(4), 上肢关节位置(14)]
Float64MultiArray input # 数据格式(共3+4+14自由度):[base速度(x, y, yaw)(3), 下肢关节速度(4), 上肢关节速度(14)]Example usage
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
# 存储最新的数据
state_data = None
input_data = None
def wbc_observation_state_callback(msg):
"""WBC观测状态回调函数"""
global state_data
data = msg.data
state_data = data
if len(data) != 21:
print(f"警告: state数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_pose = data[0:3] # base位姿(x, y, yaw) - 3个
leg_joints = data[3:7] # 下肢关节位置 - 4个
arm_joints = data[7:21] # 上肢关节位置 - 14个
print("=" * 60)
print("WBC观测状态 (mobile_manipulator_wbc_observation/state):")
print(f" 底盘位姿 (x, y, yaw): [{base_pose[0]:.4f}, {base_pose[1]:.4f}, {base_pose[2]:.4f}]")
print(f" 下肢关节位置 (4个): {[f'{x:.4f}' for x in leg_joints]}")
print(f" 上肢关节位置 (14个): {[f'{x:.4f}' for x in arm_joints]}")
def wbc_observation_input_callback(msg):
"""WBC观测输入回调函数"""
global input_data
data = msg.data
input_data = data
if len(data) != 21:
print(f"警告: input数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_vel = data[0:3] # base速度(x, y, yaw) - 3个
leg_joint_vel = data[3:7] # 下肢关节速度 - 4个
arm_joint_vel = data[7:21] # 上肢关节速度 - 14个
print("=" * 60)
print("WBC观测输入 (mobile_manipulator_wbc_observation/input):")
print(f" 底盘速度 (x, y, yaw): [{base_vel[0]:.4f}, {base_vel[1]:.4f}, {base_vel[2]:.4f}]")
print(f" 下肢关节速度 (4个): {[f'{x:.4f}' for x in leg_joint_vel]}")
print(f" 上肢关节速度 (14个): {[f'{x:.4f}' for x in arm_joint_vel]}")
# 初始化ROS节点
rospy.init_node('sub_wbc_observation', anonymous=True)
# 创建订阅者 - state
wbc_state_sub = rospy.Subscriber(
'/mobile_manipulator_wbc_observation/state',
Float64MultiArray,
wbc_observation_state_callback
)
# 创建订阅者 - input
wbc_input_sub = rospy.Subscriber(
'/mobile_manipulator_wbc_observation/input',
Float64MultiArray,
wbc_observation_input_callback
)
print("开始订阅WBC观测话题...")
print(" - /mobile_manipulator_wbc_observation/state (状态)")
print(" - /mobile_manipulator_wbc_observation/input (输入)")
# 保持节点运行
rospy.spin()12. /mobile_manipulator_mpc_observation - Raw sensor data (filtered) fed into the wheeled-arm MPC
Message type: ocs2_msgs/mpc_observation
Description: Raw sensor data fed into the wheeled-arm MPC, temporally filtered with kinemicLimitFilter, second-order continuous.
Field description:
Float64 time # MPC 模块内部时间
ocs2_msgs/mpc_state state
float32[] value # 数据格式(共3+4+14自由度):[base位姿(x, y, yaw)(3), 下肢关节位置(4), 上肢关节位置(14)]
ocs2_msgs/mpc_input input
float32[] value # 数据格式(共3+4+14自由度):[base速度(x, y, yaw)(3), 下肢关节速度(4), 上肢关节速度(14)]
int8 mode # MPC 的步态,不是人形,无效,不需要注意Example usage
#!/usr/bin/env python
import rospy
from ocs2_msgs.msg import mpc_observation
def mpc_observation_callback(msg):
"""MPC观测回调函数"""
time = msg.time
mode = msg.mode
state = msg.state.value
input_data = msg.input.value
# 检查数据长度
if len(state) != 21:
print(f"警告: state数据长度不正确,期望21,实际{len(state)}")
return
if len(input_data) != 21:
print(f"警告: input数据长度不正确,期望21,实际{len(input_data)}")
return
# 解析state数据
base_pose = state[0:3] # base位姿(x, y, yaw) - 3个
leg_joints = state[3:7] # 下肢关节位置 - 4个
arm_joints = state[7:21] # 上肢关节位置 - 14个
# 解析input数据
base_vel = input_data[0:3] # base速度(x, y, yaw) - 3个
leg_joint_vel = input_data[3:7] # 下肢关节速度 - 4个
arm_joint_vel = input_data[7:21] # 上肢关节速度 - 14个
print("=" * 60)
print(f"MPC观测 (mobile_manipulator_mpc_observation) - 时间: {time:.4f}s, 模式: {mode}")
print("-" * 60)
print("状态 (state):")
print(f" 底盘位姿 (x, y, yaw): [{base_pose[0]:.4f}, {base_pose[1]:.4f}, {base_pose[2]:.4f}]")
print(f" 下肢关节位置 (4个): {[f'{x:.4f}' for x in leg_joints]}")
print(f" 上肢关节位置 (14个): {[f'{x:.4f}' for x in arm_joints]}")
print("-" * 60)
print("输入 (input):")
print(f" 底盘速度 (x, y, yaw): [{base_vel[0]:.4f}, {base_vel[1]:.4f}, {base_vel[2]:.4f}]")
print(f" 下肢关节速度 (4个): {[f'{x:.4f}' for x in leg_joint_vel]}")
print(f" 上肢关节速度 (14个): {[f'{x:.4f}' for x in arm_joint_vel]}")
# 初始化ROS节点
rospy.init_node('sub_mpc_observation', anonymous=True)
# 创建订阅者
mpc_observation_sub = rospy.Subscriber(
'/mobile_manipulator_mpc_observation',
mpc_observation,
mpc_observation_callback
)
print("开始订阅 /mobile_manipulator_mpc_observation 话题...")
print("(输入到轮臂MPC的原生传感器数据,经过滤波)")
# 保持节点运行
rospy.spin()13. /humanoid_wheel/optimizedState_mrt - State setpoint of the native MRT output by the MPC
Message type: std_msgs/Float64MultiArray
Description: The state setpoint computed by the MPC and output after interpolation by the MRT module.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataExample usage
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def optimized_state_mrt_callback(msg):
"""MPC优化状态MRT回调函数"""
data = msg.data
if len(data) != 21:
print(f"警告: 数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_pose = data[0:3] # base位姿(x, y, yaw) - 3个
leg_joints = data[3:7] # 下肢关节位置 - 4个
arm_joints = data[7:21] # 上肢关节位置 - 14个
print("=" * 60)
print("MPC优化状态MRT (humanoid_wheel/optimizedState_mrt):")
print("(MPC计算并通过MRT模块插值后输出的state期望)")
print(f" 底盘位姿 (x, y, yaw): [{base_pose[0]:.4f}, {base_pose[1]:.4f}, {base_pose[2]:.4f}]")
print(f" 下肢关节位置 (4个): {[f'{x:.4f}' for x in leg_joints]}")
print(f" 上肢关节位置 (14个): {[f'{x:.4f}' for x in arm_joints]}")
# 初始化ROS节点
rospy.init_node('sub_optimized_state_mrt', anonymous=True)
# 创建订阅者
optimized_state_mrt_sub = rospy.Subscriber(
'/humanoid_wheel/optimizedState_mrt',
Float64MultiArray,
optimized_state_mrt_callback
)
print("开始订阅 /humanoid_wheel/optimizedState_mrt 话题...")
print("(MPC输出的原生MRT的state期望)")
# 保持节点运行
rospy.spin()14. /humanoid_wheel/optimizedInput_mrt - Desired input of the native MRT output by MPC
Message type: std_msgs/Float64MultiArray
Function description: The desired input computed by MPC and output after interpolation by the MRT module.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def optimized_input_mrt_callback(msg):
"""MPC优化输入MRT回调函数"""
data = msg.data
if len(data) != 21:
print(f"警告: 数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_vel = data[0:3] # base速度(x, y, yaw) - 3个
leg_joint_vel = data[3:7] # 下肢关节速度 - 4个
arm_joint_vel = data[7:21] # 上肢关节速度 - 14个
print("=" * 60)
print("MPC优化输入MRT (humanoid_wheel/optimizedInput_mrt):")
print("(MPC计算并通过MRT模块插值后输出的input期望)")
print(f" 底盘速度 (x, y, yaw): [{base_vel[0]:.4f}, {base_vel[1]:.4f}, {base_vel[2]:.4f}]")
print(f" 下肢关节速度 (4个): {[f'{x:.4f}' for x in leg_joint_vel]}")
print(f" 上肢关节速度 (14个): {[f'{x:.4f}' for x in arm_joint_vel]}")
# 初始化ROS节点
rospy.init_node('sub_optimized_input_mrt', anonymous=True)
# 创建订阅者
optimized_input_mrt_sub = rospy.Subscriber(
'/humanoid_wheel/optimizedInput_mrt',
Float64MultiArray,
optimized_input_mrt_callback
)
print("开始订阅 /humanoid_wheel/optimizedInput_mrt 话题...")
print("(MPC输出的原生MRT的input期望)")
# 保持节点运行
rospy.spin()15. /humanoid_wheel/optimizedState_mrt_kinemicLimit - Desired state of the MRT after kinematic limit filtering
Message type: std_msgs/Float64MultiArray
Function description: The desired state computed by MPC and output after interpolation by the MRT module, filtered with KinemicLimitFilter to ensure second-order continuity.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def optimized_state_mrt_kinemic_limit_callback(msg):
"""MPC优化状态MRT运动学限制滤波回调函数"""
data = msg.data
if len(data) != 21:
print(f"警告: 数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_pose = data[0:3] # base位姿(x, y, yaw) - 3个
leg_joints = data[3:7] # 下肢关节位置 - 4个
arm_joints = data[7:21] # 上肢关节位置 - 14个
print("=" * 60)
print("MPC优化状态MRT运动学限制滤波 (humanoid_wheel/optimizedState_mrt_kinemicLimit):")
print("(经过运动学限制滤波的MRT的state期望,保证二阶连续)")
print(f" 底盘位姿 (x, y, yaw): [{base_pose[0]:.4f}, {base_pose[1]:.4f}, {base_pose[2]:.4f}]")
print(f" 下肢关节位置 (4个): {[f'{x:.4f}' for x in leg_joints]}")
print(f" 上肢关节位置 (14个): {[f'{x:.4f}' for x in arm_joints]}")
# 初始化ROS节点
rospy.init_node('sub_optimized_state_mrt_kinemic_limit', anonymous=True)
# 创建订阅者
optimized_state_mrt_kinemic_limit_sub = rospy.Subscriber(
'/humanoid_wheel/optimizedState_mrt_kinemicLimit',
Float64MultiArray,
optimized_state_mrt_kinemic_limit_callback
)
print("开始订阅 /humanoid_wheel/optimizedState_mrt_kinemicLimit 话题...")
print("(经过运动学限制滤波的MRT的state期望)")
# 保持节点运行
rospy.spin()16. /humanoid_wheel/optimizedInput_mrt_kinemicLimit - Desired input of the MRT after kinematic limit filtering
Message type: std_msgs/Float64MultiArray
Function description: The desired input computed by MPC and output after interpolation by the MRT module, filtered with KinemicLimitFilter to ensure second-order continuity.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] data]Usage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def optimized_input_mrt_kinemic_limit_callback(msg):
"""MPC优化输入MRT运动学限制滤波回调函数"""
data = msg.data
if len(data) != 21:
print(f"警告: 数据长度不正确,期望21,实际{len(data)}")
return
# 解析数据
base_vel = data[0:3] # base速度(x, y, yaw) - 3个
leg_joint_vel = data[3:7] # 下肢关节速度 - 4个
arm_joint_vel = data[7:21] # 上肢关节速度 - 14个
print("=" * 60)
print("MPC优化输入MRT运动学限制滤波 (humanoid_wheel/optimizedInput_mrt_kinemicLimit):")
print("(经过运动学限制滤波的MRT的input期望,保证二阶连续)")
print(f" 底盘速度 (x, y, yaw): [{base_vel[0]:.4f}, {base_vel[1]:.4f}, {base_vel[2]:.4f}]")
print(f" 下肢关节速度 (4个): {[f'{x:.4f}' for x in leg_joint_vel]}")
print(f" 上肢关节速度 (14个): {[f'{x:.4f}' for x in arm_joint_vel]}")
# 初始化ROS节点
rospy.init_node('sub_optimized_input_mrt_kinemic_limit', anonymous=True)
# 创建订阅者
optimized_input_mrt_kinemic_limit_sub = rospy.Subscriber(
'/humanoid_wheel/optimizedInput_mrt_kinemicLimit',
Float64MultiArray,
optimized_input_mrt_kinemic_limit_callback
)
print("开始订阅 /humanoid_wheel/optimizedInput_mrt_kinemicLimit 话题...")
print("(经过运动学限制滤波的MRT的input期望)")
# 保持节点运行
rospy.spin()17. /humanoid_wheel/bodyAcc - Chassis acceleration solved by WBC
Message type: std_msgs/Float64MultiArray
Function description: The chassis acceleration output by the WBC module.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def body_acc_callback(msg):
"""底盘加速度回调函数"""
data = msg.data
if len(data) < 3:
print(f"警告: 数据长度不正确,期望至少3,实际{len(data)}")
return
# 解析数据: [base加速度(x, y, yaw)(3)]
acc_x = data[0]
acc_y = data[1]
acc_yaw = data[2]
print("=" * 60)
print("WBC底盘加速度 (humanoid_wheel/bodyAcc):")
print(f" 底盘加速度 (x, y, yaw): [{acc_x:.4f}, {acc_y:.4f}, {acc_yaw:.4f}]")
# 如果有额外的数据,也显示出来
if len(data) > 3:
print(f" 额外数据 ({len(data)-3}个): {[f'{x:.4f}' for x in data[3:]]}")
# 初始化ROS节点
rospy.init_node('sub_body_acc', anonymous=True)
# 创建订阅者
body_acc_sub = rospy.Subscriber(
'/humanoid_wheel/bodyAcc',
Float64MultiArray,
body_acc_callback
)
print("开始订阅 /humanoid_wheel/bodyAcc 话题...")
print("(WBC求解的底盘的加速度)")
# 保持节点运行
rospy.spin()18. /humanoid_wheel/jointAcc - Joint accelerations solved by WBC (including lower and upper limbs)
Message type: std_msgs/Float64MultiArray
Function description: The joint accelerations output by the WBC module.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def joint_acc_callback(msg):
"""关节加速度回调函数"""
data = msg.data
if len(data) != 18:
print(f"警告: 数据长度不正确,期望18,实际{len(data)}")
return
# 解析数据: [下肢加速度(4), 上肢加速度(14)]
leg_joint_acc = data[0:4] # 下肢关节加速度 - 4个
arm_joint_acc = data[4:18] # 上肢关节加速度 - 14个
print("=" * 60)
print("WBC关节加速度 (humanoid_wheel/jointAcc):")
print("(WBC求解的关节加速度,包括下肢和上肢)")
print(f" 下肢关节加速度 (4个): {[f'{x:.4f}' for x in leg_joint_acc]}")
print(f" 上肢关节加速度 (14个): {[f'{x:.4f}' for x in arm_joint_acc]}")
# 初始化ROS节点
rospy.init_node('sub_joint_acc', anonymous=True)
# 创建订阅者
joint_acc_sub = rospy.Subscriber(
'/humanoid_wheel/jointAcc',
Float64MultiArray,
joint_acc_callback
)
print("开始订阅 /humanoid_wheel/jointAcc 话题...")
print("(WBC求解的关节加速度,包括下肢和上肢)")
# 保持节点运行
rospy.spin()19. /humanoid_wheel/torque - Joint torques solved by WBC (including lower and upper limbs)
Message type: std_msgs/Float64MultiArray
Function description: The joint accelerations output by the WBC module.
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def torque_callback(msg):
"""关节扭矩回调函数"""
data = msg.data
if len(data) != 18:
print(f"警告: 数据长度不正确,期望18,实际{len(data)}")
return
# 解析数据: [下肢扭矩(4), 上肢扭矩(14)]
leg_joint_torque = data[0:4] # 下肢关节扭矩 - 4个
arm_joint_torque = data[4:18] # 上肢关节扭矩 - 14个
print("=" * 60)
print("WBC关节扭矩 (humanoid_wheel/torque):")
print("(WBC求解的关节扭矩,包括下肢和上肢)")
print(f" 下肢关节扭矩 (4个): {[f'{x:.4f}' for x in leg_joint_torque]}")
print(f" 上肢关节扭矩 (14个): {[f'{x:.4f}' for x in arm_joint_torque]}")
# 初始化ROS节点
rospy.init_node('sub_torque', anonymous=True)
# 创建订阅者
torque_sub = rospy.Subscriber(
'/humanoid_wheel/torque',
Float64MultiArray,
torque_callback
)
print("开始订阅 /humanoid_wheel/torque 话题...")
print("(WBC求解的关节扭矩,包括下肢和上肢)")
# 保持节点运行
rospy.spin()20. /humanoid_wheel/eePoses - 6D Pose of Both Arm End Effectors in the World Frame
Message type: std_msgs/Float64MultiArray
Description: 6D pose feedback of both arm end effectors in the world frame. Pose format: [x, y, z, yaw, pitch, roll]
Field description:
std_msgs/MultiArrayLayout layout
std_msgs/MultiArrayDimension[] dim #一个维度描述数组,每个元素描述一个维度
string label #维度的名称
uint32 size #维度的大小
uint32 stride #步长
uint32 data_offset #数据在 data数组中的起始偏移量
float64[] dataUsage example
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64MultiArray
def ee_poses_callback(msg):
"""双臂末端6D位姿回调函数"""
data = msg.data
if len(data) != 12:
print(f"警告: 数据长度不正确,期望12,实际{len(data)}")
return
# 解析数据: [左臂位姿(6), 右臂位姿(6)]
# 每个位姿格式: [x, y, z, yaw, pitch, roll]
left_arm_pose = data[0:6] # 左臂位姿 - 6个
right_arm_pose = data[6:12] # 右臂位姿 - 6个
print("=" * 60)
print("双臂末端6D位姿 (humanoid_wheel/eePoses):")
print("(双臂末端的世界坐标系6D位姿反馈)")
print("-" * 60)
print("左臂位姿:")
print(f" 位置 (x, y, z): [{left_arm_pose[0]:.4f}, {left_arm_pose[1]:.4f}, {left_arm_pose[2]:.4f}]")
print(f" 姿态 (yaw, pitch, roll): [{left_arm_pose[3]:.4f}, {left_arm_pose[4]:.4f}, {left_arm_pose[5]:.4f}]")
print(f" 姿态 (度): [{left_arm_pose[3]*180/3.14159:.2f}°, {left_arm_pose[4]*180/3.14159:.2f}°, {left_arm_pose[5]*180/3.14159:.2f}°]")
print("-" * 60)
print("右臂位姿:")
print(f" 位置 (x, y, z): [{right_arm_pose[0]:.4f}, {right_arm_pose[1]:.4f}, {right_arm_pose[2]:.4f}]")
print(f" 姿态 (yaw, pitch, roll): [{right_arm_pose[3]:.4f}, {right_arm_pose[4]:.4f}, {right_arm_pose[5]:.4f}]")
print(f" 姿态 (度): [{right_arm_pose[3]*180/3.14159:.2f}°, {right_arm_pose[4]*180/3.14159:.2f}°, {right_arm_pose[5]*180/3.14159:.2f}°]")
# 初始化ROS节点
rospy.init_node('sub_ee_poses', anonymous=True)
# 创建订阅者
ee_poses_sub = rospy.Subscriber(
'/humanoid_wheel/eePoses',
Float64MultiArray,
ee_poses_callback
)
print("开始订阅 /humanoid_wheel/eePoses 话题...")
print("(双臂末端的世界坐标系6D位姿反馈)")
# 保持节点运行
rospy.spin()ROS Service Interfaces
Called Services
1. /enable_lb_arm_quick_mode - Joint Quick Mode Switching
Service type: std_srvs/SetBool
Description:
Enable or disable arm quick mode.
- When lower-limb quick mode is enabled, the lower-limb motors take commands directly from
lb_leg_trajinstead of from the MPC. - When upper-limb quick mode is enabled, the arm motors take commands directly from
kuavo_arm_trajinstead of from the MPC.
Request fields:
bool data # 模式切换类型(true:开启,false:关闭)Response fields:
bool success # 操作是否成功
string message # 状态消息Related demo scripts:
cmd_arm_joint_test.pycmd_leg_joint_test.py
Usage example
#!/usr/bin/env python
import rospy
from std_srvs.srv import SetBool
def call_enable_arm_quick_mode(enable):
"""调用手臂快速模式切换服务"""
try:
# 等待服务可用
rospy.loginfo(f"等待服务 /enable_lb_arm_quick_mode 可用...")
rospy.wait_for_service('/enable_lb_arm_quick_mode', timeout=5.0)
# 创建服务客户端
service_client = rospy.ServiceProxy('/enable_lb_arm_quick_mode', SetBool)
# 调用服务
rospy.loginfo(f"调用服务: {'启用' if enable else '禁用'}手臂快速模式")
response = service_client(enable)
# 处理响应
if response.success:
rospy.loginfo(f"✓ 成功{'启用' if enable else '禁用'}手臂快速模式")
if response.message:
rospy.loginfo(f" 消息: {response.message}")
return True
else:
rospy.logwarn(f"✗ 服务调用失败")
if response.message:
rospy.logwarn(f" 消息: {response.message}")
return False
except rospy.ROSException as e:
rospy.logerr(f"服务不可用: {e}")
return False
except rospy.ServiceException as e:
rospy.logerr(f"服务调用异常: {e}")
return False
# 初始化ROS节点
rospy.init_node('call_enable_arm_quick_mode', anonymous=True)
# 等待一下确保节点初始化完成
rospy.sleep(0.5)
# 示例:启用快速模式
print("=" * 60)
print("示例1: 启用手臂快速模式")
print("=" * 60)
call_enable_arm_quick_mode(True)
rospy.sleep(1.0)
# 示例:禁用快速模式
print("\n" + "=" * 60)
print("示例2: 禁用手臂快速模式")
print("=" * 60)
call_enable_arm_quick_mode(False)
print("\n" + "=" * 60)
print("服务调用完成")
print("=" * 60)2. /mobile_manipulator_mpc_control - MPC Control Mode Switching
Service type: kuavo_msgs/changeTorsoCtrlMode
Description: Switch the MPC control mode of the mobile manipulator robot to control the coordinated operation of different body parts.
Request fields:
int32 control_mode # 控制模式选择
# 0: NoControl - 无控制
# 1: ArmOnly - 仅控制手臂,基座固定
# 2: BaseOnly - 仅控制基座,手臂固定
# 3: BaseArm - 同时控制基座和手臂
# 4: ArmEeOnly - 仅控制手臂末端Response fields:
bool result # 切换是否成功
string message # 状态消息Related demo scripts:
lb_ctrl_api.py
Control mode details:
- Mode 0 (NoControl): Disables all MPC control; the robot enters a passive state.
- Mode 1 (ArmOnly): Controls only the dual-arm motion with the base held fixed; suitable for manipulation tasks at a fixed location.
- Mode 2 (BaseOnly): Controls only the base motion with the arms held at their current positions; suitable for navigation tasks.
- Mode 3 (BaseArm): Coordinates base and arm control to achieve mobile manipulation; suitable for complex mobile grasping tasks.
- Mode 4 (ArmEeOnly): Controls only the arm end effectors, optimizing end-effector trajectory tracking.
Related demo scripts: lb_ctrl_api.py
Usage example
#!/usr/bin/env python
import rospy
from kuavo_msgs.srv import changeTorsoCtrlMode
# 控制模式定义
MODES = {
0: "NoControl - 无控制",
1: "ArmOnly - 仅控制手臂,基座固定",
2: "BaseOnly - 仅控制基座,手臂固定",
3: "BaseArm - 同时控制基座和手臂",
4: "ArmEeOnly - 仅控制手臂末端"
}
def call_mpc_control(control_mode):
"""调用MPC控制模式切换服务"""
if control_mode not in MODES:
rospy.logerr(f"无效模式号 {control_mode},允许值 {list(MODES.keys())}")
return False
try:
# 等待服务可用
rospy.loginfo(f"等待服务 /mobile_manipulator_mpc_control 可用...")
rospy.wait_for_service('/mobile_manipulator_mpc_control', timeout=5.0)
# 创建服务客户端
service_client = rospy.ServiceProxy('/mobile_manipulator_mpc_control', changeTorsoCtrlMode)
# 调用服务
rospy.loginfo(f"调用服务: 切换到模式 {control_mode} - {MODES[control_mode]}")
response = service_client(control_mode=control_mode)
# 处理响应
if response.result:
rospy.loginfo(f"✓ 成功切换到模式 {control_mode}: {MODES[control_mode]}")
if response.message:
rospy.loginfo(f" 消息: {response.message}")
if hasattr(response, 'mode'):
rospy.loginfo(f" 当前模式: {response.mode}")
return True
else:
rospy.logwarn(f"✗ 服务调用失败")
if response.message:
rospy.logwarn(f" 消息: {response.message}")
return False
except rospy.ROSException as e:
rospy.logerr(f"服务不可用: {e}")
return False
except rospy.ServiceException as e:
rospy.logerr(f"服务调用异常: {e}")
return False
# 初始化ROS节点
rospy.init_node('call_mpc_control', anonymous=True)
# 等待一下确保节点初始化完成
rospy.sleep(0.5)
# 示例:切换到不同模式
print("=" * 60)
print("示例1: 切换到 ArmOnly 模式 (仅控制手臂)")
print("=" * 60)
call_mpc_control(1)
rospy.sleep(1.0)
print("\n" + "=" * 60)
print("示例2: 切换到 BaseArm 模式 (同时控制基座和手臂)")
print("=" * 60)
call_mpc_control(3)
rospy.sleep(1.0)
print("\n" + "=" * 60)
print("示例3: 切换到 BaseOnly 模式 (仅控制基座)")
print("=" * 60)
call_mpc_control(2)
print("\n" + "=" * 60)
print("服务调用完成")
print("=" * 60)
print("\n可用模式列表:")
for mode_id, mode_desc in MODES.items():
print(f" {mode_id}: {mode_desc}")3. /enable_control - Software Pause/Resume
Service type: std_srvs/SetBool
Description: Software pause (soft emergency stop) and resume.
false: software pause. The whole body freezes in the planned posture at the instant of pausing; during the pause, motion-related topic commands (such as/cmd_vel,/cmd_lb_torso_pose,/kuavo_arm_traj, etc.) are discarded, and motion-related service requests are rejected (returningRejected: control disabled.)true: resume. After resuming, the robot remains in the frozen posture without moving; motion commands must be sent again before it starts moving.
Notes:
- Pausing and resuming each have a transition protection window (about 0.5s). Pause/resume requests within the window are rejected (
success=false) — this is expected behavior, not a fault; simply resend the request later when you need to switch; - Duplicate requests are also rejected (pausing again while already paused, resuming again while running), which is likewise expected behavior;
- The service returning
success=trueonly means the request has been accepted: pausing takes effect immediately; full resumption takes effect according to the status topic below; - The current state is authoritative via the latched topic
/enable_control_state(std_msgs/Bool):true= fully resumed and running,false= paused or in transition. Clients should subscribe to this topic to determine the state rather than assuming the service call has taken effect immediately.
Request fields:
bool data # true:恢复,false:软件暂停Response fields:
bool success # 请求是否被受理(false = 保护窗口内或重复请求被拒,属预期行为,可稍后重发)
string message # 状态消息Related demo scripts: manual_enable_control_test.py
Usage example
#!/usr/bin/env python
import rospy
from std_srvs.srv import SetBool
from std_msgs.msg import Bool
enable_state = True # 以 /enable_control_state 话题为准同步
def on_enable_state(msg):
global enable_state
enable_state = msg.data
def call_enable_control(enable):
"""调用软件暂停/恢复服务。被拒(保护窗口/重复请求)属预期,可稍后重发"""
try:
rospy.wait_for_service('/enable_control', timeout=5.0)
response = rospy.ServiceProxy('/enable_control', SetBool)(enable)
if response.success:
rospy.loginfo(f"✓ {'恢复' if enable else '软件暂停'}请求已受理")
return True
else:
rospy.logwarn(f"请求被拒(预期行为,稍后重发): {response.message}")
return False
except rospy.ServiceException as e:
rospy.logerr(f"服务调用异常: {e}")
return False
rospy.init_node('call_enable_control', anonymous=True)
rospy.Subscriber('/enable_control_state', Bool, on_enable_state, queue_size=1)
# 示例:软件暂停
call_enable_control(False)
rospy.sleep(1.0)
# 示例:恢复(恢复后需重新发送运动指令才开始动作)
call_enable_control(True)