动作播放模块
动作播放模块
Section titled “动作播放模块”动作播放模块(Motion Player,MP) 是 A2 机器人上用于管理动作播放的模块。它提供了一个 rpc 接口,能够接受动作播放相关的请求,如开始播放、暂停、停止、循环等命令。
本模块在基础款和旗舰款都位于 x86 开发板上,http 后端监听的端口为 56444。
RPC 接口
Section titled “RPC 接口”此模块通过 RPC 协议实现对动作播放的控制,支持发送包括动作播放、停止、暂停、循环等命令。下面是 motion_player 模块的协议说明:
SendMotionCommand 是 motion_player 模块的核心 RPC 命令,用于控制机器人的动作播放。
- 动作播放:根据给定的动作名称(
motion_id),开始播放特定的动作。 - 暂停和复位:通过
cmd_pause标志来暂停正在执行的动作,cmd_reset标志允许将动作恢复到初始姿态。 - 循环播放:通过
cmd_repeat标志设置动作为循环播放,直到外部命令停止。 - 自动结束:根据
cmd_end设置,动作可以在播放结束后自动复位或停留在最后一帧。
| 接口名 | 接口描述 | 请求消息类型 | 答复消息类型 | 备注 | 通信后端 |
|---|---|---|---|---|---|
pb:/aimdk.protocol.MotionCommandService/SendMotionCommand | 动作播放命令 | aimdk::protocol::MotionCommandRequest | aimdk::protocol::CommonResponse | http | |
pb:/aimdk.protocol.MotionCommandService/GetMotionStatus | 动作信息查询 | aimdk::protocol::CommonRequest | aimdk::protocol::MotionCommandResponse | http | |
pb:/aimdk.protocol.MotionCommandService/EnableMotionPlayer | 开启动作播放 | aimdk::protocol::CommonRequest | aimdk::protocol::CommonResponse | 与发送 cmd_pause=true 效果相同,但是不会在运控模块切换 Action 之后被重置,可以视为 motion_player 等同于被 aima em stop-app motion_player 停止,在 JOINT_SERVO 相关模式下会立即复位 | http |
pb:/aimdk.protocol.MotionCommandService/DisableMotionPlayer | 关闭动作播放 | aimdk::protocol::CommonRequest | aimdk::protocol::CommonResponse | 恢复 motion_player 的动作控制,如果在 JOINT_SERVO 相关模式下会立即复位 | http |
Protobuf 消息类型
Section titled “Protobuf 消息类型”aimdk::protocol::MotionCommandRequest
Section titled “aimdk::protocol::MotionCommandRequest”| 字段名称 | 类型 | 描述 |
|---|---|---|
| header | aimdk::protocol::RequestHeader | 请求头,包含请求的元数据。包括请求的唯一标识符、时间戳、请求类型等。 |
| motion_id | string | 动作名称,表示要执行的具体动作。动作名称为动作文件的绝对路径加动作名称。 |
| duration_ms | int64 | 设置动作最长运行时间,单位为毫秒。 |
| cmd_pause | bool | 动作暂停标志,true表示暂停,将暂停向机器人发送控制信号。 |
| cmd_reset | bool | 复位标志,true表示复位,false表示不复位。复位操作会将当前动作的状态重置至初始状态。 |
| cmd_repeat | bool | 该标志已弃用,为保持兼容性未做删除,请勿使用。 |
| cmd_end | bool | 是否在动作执行后自动恢复到初始姿态,true表示自动复位,false表示不自动复位。 |
aimdk::protocol::MotionCommandResponse
Section titled “aimdk::protocol::MotionCommandResponse”| 字段名称 | 类型 | 描述 |
|---|---|---|
| header | aimdk::protocol::RequestHeader | 请求头,包含请求的元数据。包括请求的唯一标识符、时间戳、请求类型等。 |
| time_to_end_ms | int64 | 当前正在播放的动作的剩余播放时间。 |
| status | aimdk::protocol::MotionCommandStatus | 当前的工作状态(分为空闲、开始、运行中和暂停)。 |
| is_neck_enable | bool | 指示当前是否使用 motion_player 控制头部运动。 |
| motion_id | string | 上一次触发播放的动作名称。 |
aimdk::protocol::MotionCommandStatus
Section titled “aimdk::protocol::MotionCommandStatus”| Name | Number | Description |
|---|---|---|
| MotionCommandStatus_IDLE | 0 | 空闲 |
| MotionCommandStatus_START | 1 | 开始执行 |
| MotionCommandStatus_OPERATING | 2 | 运行中 |
| MotionCommandStatus_PAUSE | 3 | 暂停 |
| MotionCommandStatus_STOP | 4 | 停止 |
下面是一个使用 SendMotionCommand 接口进行简单二次开发后发送动作命令的 bash 脚本示例,运行时在脚本的参数中指定动作名称。用户可以根据自己的需要使用任何其他类似的方式编写自定义的逻辑实现定制化的动作播放功能。
# 调用示例./send_motion_id.sh /agibot/data/resources/default/motion/motion_player/default/演讲10s/演讲10s注意以上动作位于 x86 上,如需使用其他动作请查看 x86 上动作文件夹下的所有动作文件,自定义动作请放置在 /agibot/data/var/rc/custom 目录中(需使用遥操作相关功能才可以录制自定义动作)。
#!/bin/bash
if [ $# -eq 0 ]; then echo "arg error, need motion_id, ./send_motion_id.sh motion_id, example: " echo ./send_motion_id.sh /agibot/data/resources/default/motion/motion_player/default/演讲10s/演讲10s exit 0fi
MC_ID="$1"
if [ "$MC_ID" == "停止动作" ]; then # 如果是“停止动作”,则 motion_id 为空,cmd_reset 设为 true DATA='{ "motion_id": "", "duration_ms": 10000, "cmd_end": true, "cmd_pause": false, "cmd_reset": true }'elif [ "$MC_ID" == "暂停播放器" ]; then # 如果是“暂停播放器”,则 motion_id 保持不变,cmd_pause 设为 true DATA='{ "motion_id": "", "duration_ms": 10000, "cmd_end": true, "cmd_pause": true, "cmd_reset": false }'elif [ "$MC_ID" == "下一个动作" ]; then # 如果是“下一个动作”,则 播放 list 中的下一个动作 DATA='{ "motion_id": "next_motion", "duration_ms": 10000, "cmd_end": true, "cmd_pause": false, "cmd_reset": false }'else # 如果不是“停止动作”或“暂停播放器”,保持原有逻辑 DATA='{ "motion_id": "'"$MC_ID"'", "duration_ms": 10000, "cmd_end": true, "cmd_pause": false, "cmd_reset": false }'fi
# 使用 curl 发送 POST 请求curl -i \ -H 'content-type:application/json' \ -H 'timeout: 1000' \ -X POST http://192.168.100.100:56444/rpc/aimdk.protocol.MotionCommandService/SendMotionCommand \ -d "$DATA"
# 打印发送的数据echo "$DATA"下面是使用 GetMotionStatus 接口进行动作状态查询的示例脚本。
# 调用示例./get_motion_status.sh#!/bin/bash
curl -i \ -H 'content-type:application/json' \ -H 'timeout: 1000' \ -X POST http://192.168.100.100:56444/rpc/aimdk.protocol.MotionCommandService/GetMotionStatus \ -d '{}'关于开启和关闭动作播放的示例:
# 开启动作播放curl -i \ -H 'content-type:application/json' \ -H 'timeout: 1000' \ -X POST http://192.168.100.100:56444/rpc/aimdk.protocol.MotionCommandService/EnableMotionPlayer \ -d '{}'
# 关闭动作播放curl -i \ -H 'content-type:application/json' \ -H 'timeout: 1000' \ -X POST http://192.168.100.100:56444/rpc/aimdk.protocol.MotionCommandService/DisableMotionPlayer \ -d '{}'默认动作列表
Section titled “默认动作列表”默认动作位于 /agibot/data/resources/default/motion/motion_player/default 目录下。
| 中文名称 | 英文名称 |
|---|---|
| 右手比心 | Finger heart_right hand |
| 左手握手_长 | Handshake_left hand_Long |
| 通用讲解动作_29s | General explanation actions_29s |
| 右手碰拳_长 | Bump fists_right hand_Long |
| 右手加油 | Come on_right hand |
| 左转头 | Turn head to the left |
| 左手握手 | Handshake_left hand |
| 右手点赞 | Like_right hand |
| 右手比耶 | Yeah_right hand |
| 点点头 | Nod head |
| 通用讲解动作_11s | General explanation actions_11s |
| 通用讲解动作_8s | General explanation actions_8s |
| 打太极拳 | Tai Chi |
| 通用讲解动作_22s | General explanation actions_22s |
| 通用讲解动作_25s | General explanation actions_25s |
| 右手碰拳 | Bump fists_right hand |
| 生活化敬礼 | Life-like salute |
| 右手握手 | Handshake_right hand |
| 左手比耶 | Yeah_left hand |
| 左手点赞 | Like_left hand |
| 左手挥手 | Wave hand_left hand |
| 右手挥手 | Wave hand_right hand |
| 右转头 | Turn head to the right |
| 右手握手_长 | Handshake_right hand_Long |
| 左手碰拳_长 | Bump fists_left hand_Long |
| 方向_向右欢迎 Welcome to the right_10s | |
| 方向_向左欢迎 | Welcome to the left_8s |
| 左手碰拳 | Bump fists_left hand |
| 双手点赞 | Like_both hands |
| 右手点赞_长 | Like_right hand_Long |
| 左手点赞_长 | Like_left hand_Long |
| 双手挥手 | Wave hand_both hands |
| 左手加油 | Come on_left hand |
| 双手加油 | Come on_both hands |
| 双手比耶 | Yeah_both hands |
| 双手向下比心 | Finger heart_both hands |
| 双手擦眼泪 | Wipe the tears |
| 击掌_长 | High-five_right hand_Long |
| 右手NO | NO_right hand |
| 右手OK | OK_right hand |
| 跳舞 | Dance |
| 摆拍_右手胸前比耶 | Pose_“V” sign in front of right chest |
| 摆拍_左手胸前比耶 | Pose_Both hands “V” sign |
| 摆拍_右手胸前点赞 | Pose_Thum-up in front of right chest |
| 摆拍_抬起右手 | Pose_Raise the right hand |
| 摆拍_双手咏春 | Pose_Wing Chun with both hands |
| 摆拍_我是大力士 | Posed_I’m a strongman |
| 摆拍_右手Pose_01 | Pose_Right hand_01 |
| 摆拍_右手Pose_02 | Pose_Right hand_02 |
| 摆拍_右手Pose_03 | Pose_Right hand_03 |
| 摆拍_右手Pose_04 | Pose_Right hand_04 |
| 摆拍_右手Pose_05 | Pose_Right hand_05 |
| 数字手势“1” | Number gesture”1” |
| 数字手势“2” | Number gesture”2” |
| 数字手势“3” | Number gesture”3” |
| 数字手势“4” | Number gesture”4” |
| 数字手势“5” | Number gesture”5” |
| 数字手势“6” | Number gesture”6” |
| 数字手势“7” | Number gesture”7” |
| 数字手势“8” | Number gesture”8” |
| 数字手势“9” | Number gesture”9” |
| 数字手势“10” | Number gesture”10” |
| 方向_向右上方指引 | Direction_upper right |
| 方向_向右下方指引 | Direction_lower right |
| 方向_向左上方指引 | Direction_upper left |
| 方向_向左下方指引 | Direction_lower left |
| 方向_右手指前方 | Direction_point to forward_right hand |
| 方向_左手指前方 | Direction_point to forward_left hand |
| 方向_右手指后方 | Direction_point to back_right hand |
| 方向_左手指后方 | Direction_point to back_left hand |
| 方向_指向当前位置 | Direction _ points to current position |
| 方向_指向右边 | Direction_point to the right |
| 方向_指向左边 | Direction_point to the left |
| 方向_右边示意 | Direction_Indicated on the right |
| 方向_左边示意 | Direction_Indicated on the left |
| 开篇打招呼_12s | Greeting at the beginning _12s |
| 个人介绍_7s | Personal Introduction _7s |
| 强调2大要点_12s | Highlight 2 key points - 12S |
| 强调3大要点_11s | Highlight 3 key points - 11s |
| 强调4大要点_16s | Highlight 4 key points - 16S |
| 快速强调5大要点_8s | Quickly highlight 5 key points - 8S |
| 对1个要点展开阐述_14s | Elaborate 1 key point _14s |
| 对2个要点展开阐述_18s | Elaborate 2 key points: 18S |
| 对3个要点展开阐述_15s | Elaborate 3 key points _15s |
| 简述6个要点_12s | Briefly describe 6 key points _12s |
| 做“自上而下”的示意_10s | ”Top-down” gesture_10s |
| 用手指强调信息_09s | Emphasize the key point with fingers_09s |
| 用握拳强调2组信息_12s | Make a fist and emphasize 2 key points _12s |
| 双手强调“全局”_08s | Both hands emphasize “the whole” _08s |
| 右手强调“核心”_10s | Right hand emphasize the “core”_10s |
| 讲解结束总结_9s | Summary after the lecture_9s |
| 结尾致谢_7s | Acknowledgements at the end _7s |
| 语音对话专属动作_01 | Exclusive actions in voice chat _01 |
| 语音对话专属动作_02 | Exclusive actions in voice chat _02 |
| 语音对话专属动作_03 | Exclusive actions in voice chat _03 |
| 语音对话专属动作_04 | Exclusive actions in voice chat _04 |
| 语音对话专属动作_05 | Exclusive actions in voice chat _05 |
| 语音对话专属动作_06 | Exclusive actions in voice chat _06 |
| 语音对话专属动作_07 | Exclusive actions in voice chat _07 |
| 语音对话专属动作_08 | Exclusive actions in voice chat _08 |
| 语音对话专属动作_09 | Exclusive actions in voice chat _09 |
| 语音对话专属动作_10 | Exclusive actions in voice chat _10 |
| 语音对话专属动作_11 | Exclusive actions in voice chat _11 |
| 语音对话专属动作_12 | Exclusive actions in voice chat _12 |
| 语音对话专属动作_13 | Exclusive actions in voice chat _13 |
| 语音对话专属动作_14 | Exclusive actions in voice chat _14 |
| 语音对话专属动作_15 | Exclusive actions in voice chat _15 |
| 语音对话专属动作_16 | Exclusive actions in voice chat _16 |
| 语音对话专属动作_17 | Exclusive actions in voice chat _17 |
| 语音对话专属动作_18 | Exclusive actions in voice chat _18 |
| 语音对话专属动作_19 | Exclusive actions in voice chat _19 |
| 右手握手收回 | Withdraw the right hand handshake. |