-
Notifications
You must be signed in to change notification settings - Fork 12
State Machine Config
当前状态图由两部分合成:
-
config/elf3_state_machine.yaml:系统级配置。 - 每个 Mod 的
mod.yaml:状态、事件、速度、私有过渡 profile 和路由。
不要再把 states 或 remote_events 写进系统 YAML;加载器会用 Mod 贡献重新生成这些字段。
状态图中的 route 决定“什么事件把哪个状态切到哪个状态”,Transition 则决定“切换期间每个控制周期如何生成电机帧”。两个状态的 qpos/kp/kd 可能不连续,直接切换可能使机器人突然动作,因此系统提供保持、进入增益渐变和双状态运行混合等过渡;只有明确需要立即切换时,例如进入安全断力状态,才使用 instant。
initial_state: com.bxi.basic_actions/zero_torque
mod_paths:
- /opt/bxi/mods
graph:
validate: true
export:
dot: /tmp/elf3_state_machine.dot
mermaid: /tmp/elf3_state_machine.mmd
default_transition: instant
transition_profiles:
instant:
type: instant
soft_switch:
type: hold
duration: 0.02
first_frame_switch:
type: sequence
steps:
- {type: hold, duration: 0.02}
- type: entry_gain_ramp
duration: 1.0
kp_from: zero
kd_from: target
dual_running_blend:
type: running_blend
duration: 0.3
curve: smoothstep
sample_from: true
sample_to: true
advance_from: false
advance_to: falseinitial_state 必须使用完整状态名。mod_paths 只追加搜索根;安装包内置 mods/ 始终扫描。
events:
activate: {slot: btn_10, value: 8}
toggle_pause: {slot: btn_9, value: 1}运行时名称分别为 mod-id/activate 和 mod-id/toggle_pause。value 省略时表示槽位任意变化;通常推荐明确 value。
states:
wave:
id: 12345 # 可选;默认由完整名称稳定计算
manifest:
label: 波浪动作
index: 20
group: Customer
icon: waves
confirm: true
confirm_message: 请确认周围安全
speed_profile: walk
params:
amplitude: 0.4manifest.index 是界面排序号,不是状态机 id。重复 index 会自动重新分配并告警。params 必须由工厂的 StateBuildContext 完整消费。
speed_profiles:
walk:
vx_scale: 1.0
vx_min: -1.0
vx_max: 1.0
vy_scale: 0.5
yaw_scale: 1.5状态写 speed_profile: walk 时会自动解析成当前 Mod 的 mod-id/walk。状态代码通过 self.get_cmd_vel(ctx) 获取处理后的速度。
所有边放在 routes,不写进 states.*.transitions:
routes:
- from: com.bxi.basic_actions/normal
event: activate
to: wave
transition: soft_switch
- from: wave
event: com.bxi.basic_actions/normal
to: com.bxi.basic_actions/normal
transition:
profile: dual_running_blend
duration: 0.8
- from: wave
event: toggle_pause
action: toggle_pause
- from: wave
event: stop
to: com.bxi.basic_actions/zero_torque
delay: 0.2规则:
- 本地
from/event/to自动限定到当前 Mod。 - 包含
/的值视为完整名称。 - 一条 route 至少包含
to或action。 -
transition可为 profile 名、内联对象或{profile: ..., 覆盖字段...}。 - 同一源状态和同一事件只能有一条 route。
transition_profiles:
wave_entry:
type: entry_gain_ramp
duration: 0.6
kp_from: zero
kd_from: target运行时名称是 mod-id/wave_entry。当前 Mod route 中写 transition: wave_entry 会自动解析;其他 Mod 使用时写完整名称并声明依赖。
graph.validate: true 会在启动阶段验证目标、事件、过渡能力和图结构。导出文件可用于排查不可达状态或错误边:
sed -n '1,120p' /tmp/elf3_state_machine.mmd
dot -Tsvg /tmp/elf3_state_machine.dot -o /tmp/elf3_state_machine.svg当前最完整的生产示例是:
src/bxi_example_py_elf3/config/elf3_state_machine.yaml
src/bxi_example_py_elf3/mods/com.bxi.basic_actions/mod.yaml