主题
遥控器全部通道
读取摇杆和 CH1~CH16 的归一化输入。
运行前提
只读取输入,不控制机器人运动。 同一设备只运行一个读取程序;退出上下文时释放连接。
运行
安装 SDK 后,在文档与示例目录中执行:
bash
python hw1/12_remote.py下载单文件后,也可在文件所在目录执行 python 12_remote.py。
完整代码
python
"""读取航模遥控器状态, 不会使能或控制机器人运动部件."""
from libark.robot.hw1.remote import RemoteControl
def main() -> None:
with RemoteControl() as remote:
state = remote.get_state()
print("在线:", state.online)
print("失控保护:", state.failsafe)
print("左摇杆:", state.left_x, state.left_y)
print("右摇杆:", state.right_x, state.right_y)
if state.channels is not None:
for index, value in enumerate(state.channels, start=1):
print(f"CH{index}:", value)
print("通信故障:", state.fault)
if __name__ == "__main__":
main()