49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from uas.uas_control.base_controller import BaseUASController
|
|||
|
|
from uas.uas_control.command import Command, CommandResult, CommandType, Commands
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ═════════════════════════════════════════════════════════════════
|
|||
|
|
# 扩展示例:自定义无人船控制器(演示扩展性)
|
|||
|
|
# ═════════════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
class USVController(BaseUASController):
|
|||
|
|
"""
|
|||
|
|
无人水面艇(USV)控制器 — 扩展示例
|
|||
|
|
|
|||
|
|
演示如何通过继承 BaseUASController 快速接入新设备类型。
|
|||
|
|
只需实现 device_type 和设备专有 API,
|
|||
|
|
底层协议由 Adapter 屏蔽(可复用 MAVLink / ROS / 自定义 SDK)。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
@property
|
|||
|
|
def device_type(self) -> str:
|
|||
|
|
return "usv"
|
|||
|
|
|
|||
|
|
def set_throttle(self, left: float, right: float) -> CommandResult:
|
|||
|
|
"""差速推进(左/右推进器油门,-1.0~1.0)"""
|
|||
|
|
return self.send(Commands.custom(
|
|||
|
|
self.device_id, "set_throttle",
|
|||
|
|
left=left, right=right,
|
|||
|
|
))
|
|||
|
|
|
|||
|
|
def anchor(self) -> CommandResult:
|
|||
|
|
"""抛锚(原地保持)"""
|
|||
|
|
return self.send(Commands.custom(
|
|||
|
|
self.device_id, "anchor"
|
|||
|
|
))
|
|||
|
|
|
|||
|
|
def patrol(self, waypoints: list) -> CommandResult:
|
|||
|
|
"""水面巡逻"""
|
|||
|
|
return self.send(Command(
|
|||
|
|
command_type = CommandType.FOLLOW_ROUTE,
|
|||
|
|
target_id = self.device_id,
|
|||
|
|
params = {"waypoints": waypoints, "mode": "patrol"},
|
|||
|
|
))
|
|||
|
|
|
|||
|
|
@property
|
|||
|
|
def device_type(self) -> str:
|
|||
|
|
return "usv"
|
|||
|
|
|