Skip to content

Feature/split body joint trajectory action - #137

Merged
legubiao merged 6 commits into
mainfrom
feature/split-body-joint-trajectory-action
Nov 12, 2026
Merged

legubiao merged 6 commits into
mainfrom
feature/split-body-joint-trajectory-action

Conversation

@Zachary359

Copy link
Copy Markdown
Contributor

1. 逻辑变更

轨迹执行

  • 分体 body 控制器注册关节轨迹 Action,复用公共 StateMoveJ 的规划、反馈、取消和结果处理。
  • 删除旧关节轨迹 Service 的注册、处理逻辑和消息定义。
  • 全部目标已满足且无需运动或停留时,立即成功返回,planned_duration 为 0。

时间分配

将时间模式配置统一到 Goal 层,支持:

  1. 总时长模式:指定 movej_trajectory_duration,按各段关节空间距离分配时间。
  2. 逐点时间模式:指定每个 waypoint 的 time_from_start,表示相对真实轨迹起点的累计到达时间。
  3. 默认时间模式:两种时间输入均未指定时,使用控制器当前 movej_trajectory_duration。

正值 Goal 总时长会在实际规划时持久更新同名 ROS 参数,后续未指定时间的轨迹沿用该值,不自动恢复。

约束模式仅支持 DOUBLES。linear/tanh 或包含非零时间输入的约束模式请求会明确拒绝。

重复路点与停留段

  • 未指定逐点时间时,合并相邻重复位置。
  • 显式时间相同、位置相同时,跳过重复点。
  • 显式时间相同、位置不同时,拒绝请求。
  • 显式时间增加、位置相同时,执行停留。

DOUBLES 将包含停留的轨迹拆为连续运动块和停留块:
运动块内部保留 blending,停留边界不做转接。

转接比例

新增 Goal 级 use_waypoint_blend_ratio 开关:

  • false:在实际规划开始时读取控制器 movej_trajectory_blend_ratio,作为本次轨迹的默认比例。
  • true:使用各 waypoint 的 blend_ratio_percent,包括显式的 0。

逐点比例只影响本次请求,不修改 ROS 参数。该行为与使用总时长还是逐点时间无关。

只有 DOUBLES 使用转接比例;linear/tanh 不新增 blending 能力。

2. 接口变化

接口 变化
JointTrajectory.srv 删除定义及对应 Service 注册
JointTrajectory.action 增加 Goal 级 time_mode、movej_trajectory_duration、use_waypoint_blend_ratio
JointWaypoint.msg 删除逐点 time_mode、total_time,新增 builtin_interfaces/Duration time_from_start
轨迹 Topic 保留 trajectory_msgs/msg/JointTrajectory 消息格式和现有注册

本次为消息接口不兼容变更,需要同步迁移并重建客户端。

3. Action 传参说明

Goal 参数

参数 是否必填 含义
joint_names 是 非空关节名称列表,各点位置按此顺序排列
waypoints 是 至少一个目标点,控制器以实际当前位置作为轨迹起点
time_mode 需明确设置 true 为时间模式;false 为 DOUBLES 约束模式
movej_trajectory_duration 否 总时长,单位秒;0 表示未指定,正值持久更新同名 ROS 参数
use_waypoint_blend_ratio 否,默认 false false 使用控制器默认比例;true 使用各路点比例

原生 ROS 消息的 bool 默认值为 false,因此时间模式请求需要明确设置 time_mode=true。

Waypoint 参数

参数 是否必填 含义
position 是 目标关节位置,长度必须等于 joint_names 数量
time_from_start 否 相对真实轨迹起点的累计到达时间;全部为零表示未指定
blend_ratio_percent 条件使用 Goal 开关为 true 时使用,范围 [0, 1],省略时为 0
max_velocity 否 空数组使用控制器默认速度限制
max_acceleration 否 空数组使用控制器默认加速度限制
max_jerk 否 空数组使用控制器默认 jerk 限制
velocity 否 保留字段,本次关节位置轨迹无需填写

max_* 约束规划由 DOUBLES 支持,本次不为 linear/tanh 新增相同保证。

时间输入规则

配置 行为
time_mode=true,指定正总时长 按距离分配总时间,并持久更新同名 ROS 参数
time_mode=true,指定非零累计时间 按各点累计到达时间规划
同时指定正总时长和非零累计时间 拒绝请求
time_mode=true,两者均未指定 沿用控制器当前总时长
time_mode=false DOUBLES 根据位移及 max_* 约束计算时间,不接受非零时间输入

time_from_start 必须非负、非递减;相同时间仅允许相同位置。

4. 传参示例

以下位置仅用于说明消息构造。

示例一:逐点指定时间,关闭转接

第一段 2 秒、第二段 4 秒、第三段 10 秒,对应累计时间 2、6、16 秒。

goal = JointTrajectory.Goal(
    joint_names=["left_joint1", "left_joint2"],
    time_mode=True,
    use_waypoint_blend_ratio=True,
)

positions = [
    [0.2, 0.1],
    [0.5, 0.3],
    [0.1, 0.0],
]
arrival_times = [2.0, 6.0, 16.0]

for position, arrival in zip(positions, arrival_times):
    goal.waypoints.append(
        JointWaypoint(
            position=position,
            time_from_start=Duration(seconds=arrival).to_msg(),
            blend_ratio_percent=0.0,
        )
    )

此请求不修改总时长或转接比例 ROS 参数。

示例二:指定总时长,沿用控制器转接比例

goal = JointTrajectory.Goal(
    joint_names=["left_joint1", "left_joint2"],
    time_mode=True,
    movej_trajectory_duration=16.0,
    use_waypoint_blend_ratio=False,
    waypoints=[
        JointWaypoint(position=[0.2, 0.1]),
        JointWaypoint(position=[0.5, 0.3]),
        JointWaypoint(position=[0.1, 0.0]),
    ],
)

此请求会将控制器 movej_trajectory_duration 更新为 16.0,
转接比例读取实际规划开始时的 movej_trajectory_blend_ratio。

示例三:指定各路点转接比例

goal = JointTrajectory.Goal(
    joint_names=["left_joint1", "left_joint2"],
    time_mode=True,
    movej_trajectory_duration=16.0,
    use_waypoint_blend_ratio=True,
    waypoints=[
        JointWaypoint(
            position=[0.2, 0.1],
            blend_ratio_percent=0.0,
        ),
        JointWaypoint(
            position=[0.5, 0.3],
            blend_ratio_percent=0.3,
        ),
        JointWaypoint(
            position=[0.1, 0.0],
            blend_ratio_percent=0.0,
        ),
    ],
)

逐点比例不会修改 movej_trajectory_blend_ratio。
DOUBLES 的非零转接可能影响中间点经过情况及实际规划时长,应查看 planned_duration。

- Updated the JointTrajectory Goal to utilize a new time_mode and movej_trajectory_duration for trajectory planning.
- Removed the previous point-wise time_mode and movej_trajectory_duration, ensuring compatibility with the new Action structure.
- Introduced explicit validation for trajectory timing, ensuring non-negative and non-decreasing time_from_start values.
- Updated StateMoveJ to handle Action-based trajectory requests, replacing the previous service-based approach.
- Modified JointTrajectoryManager to accommodate new timing parameters and ensure proper planning of single and multi-point trajectories.
- Enhanced documentation to reflect changes in the Action interface and timing mechanisms.
- Deprecated old JointTrajectory Service types and ensured that all consumers are updated to the new Action-based structure.
@Zachary359
Zachary359 requested a review from legubiao November 12, 2026 03:32
@legubiao
legubiao merged commit 15a0033 into main Nov 12, 2026
@legubiao
legubiao deleted the feature/split-body-joint-trajectory-action branch November 12, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants