跳到主要内容

Motion API

#include <latentos/sdk/motion/motion_client.h>
find_package(latentos_sdk_motion CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE latentos::sdk_motion)

类:latentos::sdk::motion::MotionClient

explicit MotionClient(core::Session& session);

CommandResult SwitchGroup(std::string target_group,
std::string policy,
CommandOptions options);
CommandResult SwitchCurrentPolicy(std::string policy,
CommandOptions options);
MotionControlState QueryMotionControlState(QueryOptions options);
CommandResult QueryPolicyOperation(std::string operation_id,
CommandOptions options);
CommandResult SetVelocitySmoothing(bool enabled, CommandOptions options);
CommandResult SetRemoteVelocityControl(bool enabled, CommandOptions options);
void SendVelocity(double x, double y, double yaw);
std::string VelocityCandidateTopic() const;

模块 Client 的命令方法需要显式传入 Options,可用 {} 使用默认值。

方法

方法说明
SwitchGroup切换 Group;需要 Policy 的 Group 必须同时传入
SwitchCurrentPolicy在当前 Group 内切换 Policy
QueryMotionControlState查询当前/目标 Group 与是否正在切换
QueryPolicyOperation使用 operation_id 查询异步 Policy 操作
SetVelocitySmoothing启用或关闭速度平滑
SetRemoteVelocityControl启用或关闭遥控速度输入
SendVelocity发送 SE(2) 速度:xy 为 m/s,yaw 为 rad/s
VelocityCandidateTopic返回速度 Publisher 的只读 Topic 元数据,不能用于修改发送目标

SendVelocity() 应按控制周期持续调用。操作机器人前请先确认 Group、控制权、速度范围和现场安全条件。

CommandOptions

字段类型默认值说明
timeout_msint1000等待回复的超时时间
forceboolfalse请求强制执行;目标端仍可拒绝
expected_groupstd::string可选的当前 Group 前置条件
command_idstd::string可选命令 ID;为空时由 SDK 生成

CommandResult

字段说明
ok是否成功收到并解析回复
accepted目标端是否接受命令
result_codeMotionResultCode
operation_stateMotionOperationState
completed操作是否已经完成
message可读结果信息
command_id / operation_id命令及异步操作标识
current_group回复时的当前 Group
effective_target_group实际目标 Group
current_policy回复时的当前 Policy
effective_target_policy实际目标 Policy

MotionResultCode

UnknownOkAcceptedRejectedInvalidArgumentBusyTransitionConflictUnsupportedCommandInternalErrorDuplicatedCommand

MotionOperationState

UnknownAcceptedInProgressSucceededFailed

不要只判断 ok:命令成功通常至少要求 ok && accepted;需要同步完成的业务还应检查 completedoperation_state

QueryOptions 与 MotionControlState

QueryOptions

字段类型默认值说明
timeout_msint1000查询超时
request_idstd::string可选请求 ID

MotionControlState

字段说明
ok查询是否成功
result_codeMotionQueryResultCode
message / request_id结果说明和请求标识
current_group / target_group当前和目标 Group
is_transitioning是否正在切换 Group

MotionQueryResultCode 包含 UnknownOkInvalidArgumentDecodeFailedSchemaVersionUnsupportedInternalError

完整使用流程见 Group 与 Policy运动示例