传统控制 gRPC 接口说明
高层运动控制通过 gRPC 接口实现。传统控制(MPC)客户端为独立程序,与控制程序分离部署;服务端随机器人控制程序运行,不支持二次开发。
使用前请先完成机器人快速开始。本服务提供 Python 与 C++ 两种交互式客户端示例及可复用的 API 封装;完整工程将发布于 pnd_grpc。
| 项目 |
说明 |
| 服务端口 |
6666(固定,请勿修改) |
| 连接地址 |
本机 localhost:6666;远程 <机器人 IP>:6666 |
| 配置方式 |
编辑 ip_config.json 中的 ip / port,修改后 C++ 客户端无需重新编译 |
| 调用流程 |
GetRobotState → 检查 *_enable_list → 下发指令 |
| 控制范式 |
通过 SetControlMode(domain_id=0) 切换至传统控制;详见 SetControlMode 取值参考 |
接口说明
adam_control.RobotControl
RobotControl 服务提供 Adam 高层运动控制的 gRPC 接口,客户端通过 Stub 调用下列 RPC。
| 服务名 |
RobotControl |
| 包名 |
adam_control |
| 默认端口 |
6666 |
接口定义(Proto)
syntax = "proto3";
package adam_control;
service RobotControl {
rpc SetMode (SetModeRequest) returns (SetModeResponse);
rpc SetStandMotion (SetStandMotionRequest) returns (SetStandMotionResponse);
rpc SetStandCarryBox(SetCarryBoxRequest) returns (SetCarryBoxResponse);
rpc SetStandAction (SetActionRequest) returns (SetActionResponse);
rpc SetStandDynamic (SetDynamicStandRequest) returns (SetDynamicStandResponse);
rpc SetSpeed (SetSpeedRequest) returns (SetSpeedResponse);
rpc AutoUnigaitCOM (SetUnigaitCOMRequest) returns (SetUnigaitCOMResponse);
rpc SetErrorClear (SetErrorClearRequest) returns (SetErrorClearResponse);
rpc GetStandList (GetStandListRequest) returns (GetStandListResponse);
rpc GetRobotState (GetRobotStateRequest) returns (GetRobotStateResponse);
rpc CloseProgram (CloseProgramRequest) returns (CloseProgramResponse);
rpc SetControlMode (SetControlModeRequest) returns (SetControlModeResponse);
rpc GetControlState (GetControlStateRequest) returns (GetControlStateResponse);
}
| 函数名 |
GetRobotState |
| 接口原型 |
rpc GetRobotState (GetRobotStateRequest) returns (GetRobotStateResponse) |
| 功能描述 |
获取机器人当前 FSM 状态、当前动作、姿态与速度反馈、动态平衡状态、当前控制范式,以及各类可执行能力列表。 |
| 参数 |
get_state_flag (bool):请求状态标志 |
| 返回值 |
GetRobotStateResponse:success (bool)、message (string)、fsm_name (string)、current_motion (string)、current_action_list (repeated string)、mode_enable_list (repeated string)、motion_enable_list (repeated string)、action_enable_list (repeated string)、carrybox_enable_list (repeated string)、balance_control_enable (string)、stand_pitch / stand_roll / stand_yaw / stand_height (double)、x_vel / y_vel / yaw_vel (double)、balance_control_state (bool)、motion_files_enable (bool)、current_control_mode (int32) |
| 备注 |
可在任意时刻调用。下发其他指令前应优先调用;各 *_enable_list 为动态列表,以本次返回为准。current_control_mode:0=Traditional,1=RL。 |
| 函数名 |
SetMode |
| 接口原型 |
rpc SetMode (SetModeRequest) returns (SetModeResponse) |
| 功能描述 |
切换机器人 FSM 状态。 |
| 参数 |
mode (string):目标模式,取值见下文「SetMode 模式取值参考」 |
| 返回值 |
SetModeResponse:success (bool)、message (string) |
| 备注 |
仅可切换到 mode_enable_list 中的模式,列表外的指令会被拒绝。典型流程:Start → Zero → Stand → Walk / Run → Stop。 |
| 函数名 |
SetStandMotion |
| 接口原型 |
rpc SetStandMotion (SetStandMotionRequest) returns (SetStandMotionResponse) |
| 功能描述 |
在 Stand 模式下执行预定义动作捕捉动作(如 Greeting)。 |
| 参数 |
motion (string):预定义动作名称 |
| 返回值 |
SetStandMotionResponse:success (bool)、message (string) |
| 备注 |
仅当目标动作出现在 motion_enable_list 中时可执行。可执行动作列表通过 GetStandList / GetRobotState 获取。 |
| 函数名 |
SetStandCarryBox |
| 接口原型 |
rpc SetStandCarryBox (SetCarryBoxRequest) returns (SetCarryBoxResponse) |
| 功能描述 |
在 Stand 模式下执行搬箱动作。 |
| 参数 |
carry_box (string):1=蹲下搬箱,2=站立搬箱,0=放下箱子 |
| 返回值 |
SetCarryBoxResponse:success (bool)、message (string) |
| 备注 |
仅当对应动作出现在 carrybox_enable_list 中时可执行。 |
| 函数名 |
SetStandAction |
| 接口原型 |
rpc SetStandAction (SetActionRequest) returns (SetActionResponse) |
| 功能描述 |
在 Stand 模式下进行姿态(pitch/roll/yaw)与蹲起高度控制。 |
| 参数 |
stand_pitch (double)、stand_roll (double)、stand_yaw (double)、stand_height (double),取值范围见下文「SetStandAction 姿态参数范围」 |
| 返回值 |
SetActionResponse:success (bool)、message (string) |
| 备注 |
仅当 action_enable_list 允许时可执行;参数超出范围会被拒绝。 |
| 函数名 |
SetStandDynamic |
| 接口原型 |
rpc SetStandDynamic (SetDynamicStandRequest) returns (SetDynamicStandResponse) |
| 功能描述 |
在 Stand 模式下开启/关闭动态平衡(自恢复站立)。 |
| 参数 |
dynamic_stand (bool):是否启用动态平衡 |
| 返回值 |
SetDynamicStandResponse:success (bool)、message (string) |
| 备注 |
当前动态平衡状态由 GetRobotState 的 balance_control_state 反馈;是否可用见 balance_control_enable。 |
| 函数名 |
SetSpeed |
| 接口原型 |
rpc SetSpeed (SetSpeedRequest) returns (SetSpeedResponse) |
| 功能描述 |
在 Walk / Run 模式下设置运动速度。 |
| 参数 |
x_speed (double):X 方向速度 y_speed (double):Y 方向速度 yaw_speed (double):转向速度 continous (bool):true 持续下发,否则持续 5 秒 |
| 返回值 |
SetSpeedResponse:success (bool)、message (string) |
| 备注 |
存在安全风险,生产环境建议使用手柄键控;客户端示例仅作接口演示。 |
| 函数名 |
AutoUnigaitCOM |
| 接口原型 |
rpc AutoUnigaitCOM (SetUnigaitCOMRequest) returns (SetUnigaitCOMResponse) |
| 功能描述 |
在 Walk / Run 模式下进行 COM X 方向偏置平衡。 |
| 参数 |
unigait_mode_com_x (bool):按下为 true |
| 返回值 |
SetUnigaitCOMResponse:success (bool)、message (string) |
| 备注 |
— |
| 函数名 |
SetErrorClear |
| 接口原型 |
rpc SetErrorClear (SetErrorClearRequest) returns (SetErrorClearResponse) |
| 功能描述 |
清除驱动错误,无需关电重启。 |
| 参数 |
error_clear_flag (bool):是否执行错误清除 |
| 返回值 |
SetErrorClearResponse:success (bool)、message (string) |
| 备注 |
一般在 Stop 状态下调用。 |
| 函数名 |
GetStandList |
| 接口原型 |
rpc GetStandList (GetStandListRequest) returns (GetStandListResponse) |
| 功能描述 |
获取固定动作 / 模式列表。 |
| 参数 |
mode_list_req (bool):请求模式列表标志 |
| 返回值 |
GetStandListResponse:success (bool)、message (string)、mode_list (repeated string)、motion_list (repeated string)、action_list (repeated string)、carrybox_list (repeated string)、balance_control (string) |
| 备注 |
可在任意时刻调用。mode_list 如 Start Zero Stand Walk Run Stop;motion_list 如 Greeting / Chest Expansion / Stretching / Gentleman's Salute。 |
| 函数名 |
SetControlMode |
| 接口原型 |
rpc SetControlMode (SetControlModeRequest) returns (SetControlModeResponse) |
| 功能描述 |
切换控制范式(Traditional / RL),经 DDS rt/control_mode_cmd 下发。 |
| 参数 |
domain_id (int32):0=Traditional,1=RL |
| 返回值 |
SetControlModeResponse:success (bool)、message (string)、current_mode (int32) |
| 备注 |
服务端立即返回,硬件实际切换需数秒;客户端会轮询 GetControlState(默认 30s 超时)确认是否生效。超时返回上次已知状态。 |
| 函数名 |
GetControlState |
| 接口原型 |
rpc GetControlState (GetControlStateRequest) returns (GetControlStateResponse) |
| 功能描述 |
查询当前控制范式(DDS rt/control_mode_state 反馈)。 |
| 参数 |
无(GetControlStateRequest 为空消息) |
| 返回值 |
GetControlStateResponse:success (bool)、message (string)、domain_id (int32) |
| 备注 |
domain_id=-1 表示尚未收到状态反馈。 |
| 函数名 |
CloseProgram |
| 接口原型 |
rpc CloseProgram (CloseProgramRequest) returns (CloseProgramResponse) |
| 功能描述 |
关闭机器人控制程序。 |
| 参数 |
close_flag (bool):是否关闭程序 |
| 返回值 |
CloseProgramResponse:success (bool)、message (string) |
| 备注 |
proto 中已定义,示例客户端默认未暴露,可按需自行封装。 |
接口一览表
| 函数名 |
功能描述 |
调用参数 |
赋值示例 |
GetRobotState |
查询机器人状态与可执行能力 |
get_state_flag |
true |
SetMode |
切换 FSM 模式 |
mode |
"Zero", "Stand", "Walk", "Stop" |
SetStandMotion |
Stand 下执行预定义动作 |
motion |
"Greeting" |
SetStandCarryBox |
Stand 下搬箱动作 |
carry_box |
"1"(蹲下搬箱) |
SetStandAction |
Stand 下姿态与蹲起高度 |
stand_pitch, stand_roll, stand_yaw, stand_height |
0.0, 0.0, 0.0, -0.1 |
SetStandDynamic |
Stand 下动态平衡开/关 |
dynamic_stand |
true |
SetSpeed |
Walk / Run 下设置速度 |
x_speed, y_speed, yaw_speed, continous |
0.2, 0.0, 0.0, false |
AutoUnigaitCOM |
Walk / Run 下 COM 偏置平衡 |
unigait_mode_com_x |
true |
SetErrorClear |
清除驱动错误 |
error_clear_flag |
true |
GetStandList |
获取固定动作/模式列表 |
mode_list_req |
true |
SetControlMode |
切换控制范式 |
domain_id |
0(Traditional), 1(RL) |
GetControlState |
查询控制范式 |
无 |
— |
CloseProgram |
关闭控制程序 |
close_flag |
true |
FSM 模式说明
| 模式 |
说明 |
可下发接口 |
Start |
启动 |
SetMode |
Zero |
零位校准 |
SetMode |
Stand |
站立 |
SetStandMotion, SetStandCarryBox, SetStandAction, SetStandDynamic |
Walk |
行走 |
SetSpeed, AutoUnigaitCOM |
Run |
奔跑 |
SetSpeed, AutoUnigaitCOM |
SingleStand |
单腿站立 |
SetMode |
Stop |
急停 |
SetErrorClear |
模式切换说明
可切换的目标模式由机器人侧授权决定,实际以 GetRobotState().mode_enable_list 为准。下发动作 / 速度类指令前,请先 GetRobotState 确认目标动作位于对应的 *_enable_list 中,否则会被客户端或服务端拒绝。
SetMode 模式取值参考
| 取值 |
说明 |
Start |
启动 |
Zero |
零位校准 |
Stand |
站立 |
Walk |
行走 |
Run |
奔跑 |
SingleStand |
单腿站立 |
Stop |
急停 |
SetStandAction 姿态参数范围
| 参数 |
范围 |
| Pitch |
[-0.1, 0.1] |
| Roll |
[-0.06, 0.06] |
| Yaw |
[-0.25, 0.25] |
| Base Height |
[-0.2, 0.0] |
SetControlMode 取值参考
domain_id |
说明 |
0 |
Traditional(传统控制) |
1 |
RL 控制 |
-1 |
仅出现在 GetControlState 响应,表示尚未收到反馈 |
注意事项
- 启动顺序:先启动机器人控制程序,再启动客户端。
- 先查状态再下发:通过
GetRobotState 检查各类 *_enable_list,仅当目标模式/动作在对应列表中时才可执行。
- 速度控制安全:
SetSpeed 存在安全风险,生产环境建议用手柄键控;客户端示例仅作接口演示。
- 姿态参数范围:
SetStandAction 的 pitch/roll/yaw 与蹲起高度需在允许范围内,超出会被拒绝。
- 控制范式切换:
SetControlMode 后硬件切换需数秒,可通过 GetControlState 确认;若超时请检查 DDS 服务。
- 实时上肢控制:见 手臂控制例程(DDS);灵巧手见 灵巧手控制说明。
相关文档