-
Notifications
You must be signed in to change notification settings - Fork 12
YAML Reference
项目存在三类 YAML:遥控器映射、状态机系统配置和 Mod 清单。
主文件:
src/remote_controller/config/xbox_default.yaml
顶层结构:
inputs:
selection: {}
sources: {}
curves: {}
controls: {}
outputs: {}
system: {}
system_mutexes: {}
system_reset_motion_after: []| 字段 | 含义 |
|---|---|
scan_interval_ms |
扫描候选设备的周期 |
promote_stable_ms |
高优先级设备持续可用多久后允许抢占 |
每个 source group 声明一个候选设备:
sources:
gamepad:
type: joystick
device: /dev/input/jsBattleDragon
priority: 50
ready_timeout_ms: 1000
loss_timeout_ms: 300
cooldown_ms: 1000
signals:
gamepad.left_y: {from: js.axis.3}内置 type 包含 joystick、keyboard 和 crsf。自定义类型需注册输入驱动工厂。
通用字段:type、priority、ready_timeout_ms、loss_timeout_ms、cooldown_ms、signals。设备专有字段由对应 driver 解析。
curves:
stick:
type: expo
deadzone: 0.03
expo: 0.0
limit: [-1.0, 1.0]
calibration:
input: [-1.0, 0.0, 1.0]
output: [-1.0, 0.0, 1.0]支持 analog、bool 和 enum。control 把多个设备输入统一成业务控制量,输入规则可带 source、direction、curve、when、value 等字段。条件支持 pressed、released、equals、范围以及 all/any 组合。
完整语法和实例见 遥控器 YAML 配置。
outputs:
conflict_policy: first_wins
publish_on_change: true
analog:
vx: move.vx
edge:
- output: btn_10=8
when:
any:
- [keyboard.wave_event]
- [gamepad.a_event]conflict_policy 可为 first_wins、last_wins 或 error。publish_on_change 控制是否仅在消息变化时发布。analog 连续写值,level 保持条件结果,edge 只在进入条件时产生脉冲;最终字段写入 MotionCommands。
主文件:
src/bxi_example_py_elf3/config/elf3_state_machine.yaml
| 字段 | 必需 | 含义 |
|---|---|---|
initial_state |
是 | 完整初始状态名 |
mod_paths |
否 | 额外 Mod 搜索根列表 |
graph.validate |
否 | 是否验证状态图 |
graph.export.dot |
否 | DOT 导出路径 |
graph.export.mermaid |
否 | Mermaid 导出路径 |
default_transition |
否 | 未指定边的默认过渡 |
transition_profiles |
否 | 系统共享过渡 profile |
states、remote_events 和 speed_profiles 由 Mod 合成,不应写入此文件。
Transition 是源状态与目标状态之间的切换策略,决定切换期间怎样生成电机 qpos/kp/kd。它的主要作用是处理两边输出不连续的问题,避免直接换帧造成突跳;instant 表示明确选择不做中间处理。
instantholdentry_gain_ramprunning_blendsequence
| 字段 | 必需 | 含义 |
|---|---|---|
schema |
是 | 当前固定为 1
|
id |
是 | 全局唯一、带命名空间的 Mod id |
name |
是 | 面向用户的非空 Mod 名称 |
version |
是 | 数字点版本,如 1.0.0
|
api |
是 | 当前固定为 1
|
enable |
是 | 是否启用此 Mod,必须是布尔值 |
entrypoint |
是 | 高级插件的 module:function;约定式加载显式写 null
|
visibility |
是 |
public 或发布工具识别的 protected
|
requires |
是 | Mod 依赖及版本约束;没有依赖时写 []
|
conflicts |
是 | 不能同时启用的 Mod id 列表;没有冲突时写 []
|
python_exports |
是 | 暂时导出的顶层 Python 包;没有时写 []
|
events |
否 | 遥控槽位到事件的映射 |
speed_profiles |
否 | Mod 私有速度 profile |
transition_profiles |
否 | Mod 私有过渡 profile |
states |
否 | 本地状态声明;资源 Mod 可省略或使用 {}
|
routes |
否 | 状态图中的状态切换边 |
actions |
否 | 不切换状态的事件 action |
nodes |
否 | Mod 内置的 Python ROS 节点 |
描述 Mod 身份和装载行为的以上 11 个字段必须全部显式填写,加载器也会拒绝未知顶层字段。例如约定式公共 Mod 的头部为:
schema: 1
id: com.example.wave
name: 挥手示例
version: 1.0.0
api: 1
enable: true
entrypoint: null
visibility: public
requires: []
conflicts: []
python_exports: []requires:
- com.example.shared
- id: com.bxi.basic_actions
version: ">=1,<2"conflicts:
- com.example.legacy_wave冲突声明只需由一方给出;如果两个 Mod 都处于启用状态,加载器会在执行任何 Mod 代码前拒绝启动。未安装或已禁用的冲突对象不影响加载。Mod 不能声明与自身冲突。
python_exports:
- customer_commonMod 根目录必须存在 customer_common/__init__.py。导出名必须是合法且全局唯一的 Python 包名。
events:
activate: {slot: btn_10, value: 8}
any_change: {slot: btn_9}slot 必须是合法标识符,value 若存在必须是整数。事件必须至少被一条 route 或 action 使用。
states:
wave:
factory: state:WaveState
id: 12345
label: 示例
priority: 100
group: Customer
icon: waves
confirm: true
confirm_message: 请确认安全
speed_profile: walk
params:
amplitude: 0.4factory: module:Class 用于 entrypoint: null 的约定加载。状态 id 是可选 int32。priority 是界面顺序优先级,必须是整数,数值越大越靠前,默认 0;相同 priority 按完整状态名升序排列。加载器据此自动生成非负、唯一的 manifest.index。
index 仍可作为高级固定位置选项显式配置;两个显式 index 重复会报错退出。label/priority/index/group/icon/confirm/confirm_message 均可直接写,也可放在 manifest 中,但不能同时给出冲突值。params 的类型和允许字段由类的 dataclass Params 或显式插件工厂决定。
routes:
- from: com.bxi.basic_actions/normal
event: activate
to: wave
transition: soft_switch
- from: wave
event: stop
to: com.bxi.basic_actions/zero_torque
transition: {profile: safe_exit, duration: 0.5}
delay: 0.2字段:from、event、to、transition、delay。每条 route 都必须包含 to,不能包含 action。
actions:
- from: wave
event: toggle_pause
action: toggle_pause
manifest:
label: 暂停/继续字段:from、event、action、manifest。manifest.label 是必需的非空字符串;action 只调用当前状态的 action handler,不发生状态切换,也不能配置 to/transition/delay。
加载器会规范化 from/event,并把 action 元数据发布到 state_machine_info.graph.actions[]。与状态快照相同,manifest 字段会在发布对象中展开,例如上例发布为 {from: ..., event: ..., action: toggle_pause, label: 暂停/继续}。
nodes:
depth_camera:
entrypoint: camera_node:create_node
execution: process
lifecycle: state
states: [normal_depth]
manifest:
label: 深度相机发布器
params:
output_topic: /camera/depth/image_36x48
restart:
max_attempts: 3
delay: 1.0entrypoint 必须指向 Mod 目录中的 Python module:function。工厂接收公共 API NodeBuildContext 并返回 rclpy.node.Node:
from bxi_example_py_elf3.mod_api import NodeBuildContext
def create_node(context: NodeBuildContext):
return DepthCameraNode(
context.node_name,
output_topic=str(context.params["output_topic"]),
)-
execution可为in_process(默认,加入控制器的MultiThreadedExecutor)或process(独立 Python 子进程)。 -
lifecycle可为mod(默认,Mod 启用期间常驻)或state。 -
lifecycle: state必须给出非空states;框架在目标状态on_prepare()前启动节点,在过渡取消或离开最后一个关联状态后停止。多个状态共享一个节点时使用引用计数。 -
manifest.label必须是非空字符串;params原样传给NodeBuildContext。 -
restart控制独立进程异常退出后的有限重启,默认最多3次、间隔1.0秒。
节点状态发布在 state_machine_info.nodes[]。Mod 生命周期节点启动失败会使框架启动失败并回滚;State 生命周期节点启动失败会取消本次状态切换并保留当前状态。
speed_profiles:
walk:
vx_scale: 1.0
vx_min: -1.0
vx_max: 1.0
vy_scale: 0.5
yaw_scale: 1.5与系统 profile 结构相同,但运行时自动命名为 mod-id/local-name。
- 不含
/的 state、event、node state reference、speed profile 和 Mod transition profile 名称属于当前 Mod。 - 包含
/的值视为完整名称。 - 资源键始终必须显式写完整命名空间。
- 跨 Mod 引用应同时出现在
requires中。
完整加载和校验行为见 Mod 系统。