主题
遥控器状态
RemoteControl 独立读取航模遥控器,不会直接控制底盘或其他运动部件:
python
from libark.robot.hw1.remote import RemoteControl
with RemoteControl() as remote:
state = remote.get_state()
print(state.online, state.failsafe)
print(state.left_x, state.left_y, state.right_x, state.right_y)
if state.channels is not None:
print("CH5:", state.channels[4])
for index, value in enumerate(state.channels, start=1):
print(f"CH{index}: {value}")状态字段
get_state() 返回 RemoteState:
| 字段 | 含义 |
|---|---|
timestamp_ns | 单调时钟纳秒时间戳,不是日历时间 |
online | 是否有可用的接收数据;不代表输入可用于运动 |
failsafe | 接收机失控保护标志,未收到有效帧时为 None |
frame_lost | 接收帧的丢帧标志,未收到有效帧时为 None |
left_x / left_y | 左摇杆横向 / 纵向输入 |
right_x / right_y | 右摇杆横向 / 纵向输入 |
channels | CH1~CH16 的固定 16 维元组;缺数据为 None |
fault | 异常说明,正常时为 None |
通道与状态
channels 包含 CH1~CH16,按通道编号排列:channels[0] 为 CH1,channels[15] 为 CH16。 默认摇杆映射为 CH1 右横、CH2 右纵、CH3 左纵、CH4 左横。可操作的通道取决于遥控器配置; 数字 CH17、CH18 不在当前公开状态中。四个摇杆轴和 channels 使用 -1.0~1.0。通信中断时 online=False,摇杆和通道字段为 None,原因见 fault;旧输入不会继续保留。failsafe=True 时不得将当前值作为运动目标。 当前遥控器不是完整 HW1() 的必需组件,整机对象不提供 robot.remote。