目录
目录README.md

多协议无人系统管理平台

项目概述

本系统为多类型无人设备异构集成控制平台,基于抽象适配器架构实现跨协议设备接入,提供标准化的设备管理、指令下发与状态监控服务。系统遵循ISO 11898-1通信架构标准,支持MAVLink、ROS、AirSim等异构协议的设备接入与协议转换。

系统架构

uav/
├── app/
│   ├── init.py
│   ├── main.py                 # FastAPI 应用入口
│   ├── config/                 # 配置文件(数据库、redis相关配置)
│   ├── models/                 # 数据库模型
│   │   ├── init.py
│   │   └── uav.py              # 无人机模型
│   ├── flight_control/         # 无人机控制
│   │   ├── core_service/       # 
│   │       ├── router.py       # 协议路由逻辑
│   │       ├── converter.py    # 数据格式转换
│   │       ├── status_manager.py    # 状态管理
│   │       └── log_manager.py        # 日志管理   
│   │   ├── input_layer/
│   │       ├── parser.py         # 标准化输入解析
│   │       └── schemas.py        # 数据验证模型        
│   │   ├── protocols/
│   │       ├── base_adapter.py         # 适配器基类
│   │       ├── mavlink_adapter.py       
│   │       ├── airsim_adapter.py 
│   │       └── ros_adapter.py        # 数据验证模型 
│   │   └── util/               # 无人机控制工具   
│   ├── http_routers/           # restAPI 路由
│   │   ├── init.py
│   │   ├── models.py           # 无人机执行命令接口请求结构体
│   │   └── flight/             # 无人机执行飞行命令相关路由
│   │       ├── init.py
│   │       ├── endpoints.py    # 无人机执行命令入口
│   │       └── service/        # 业务逻辑
│   ├── websocket_routers/      # websocket 路由
│   │   └── flight/             # 无人机执行飞行命令相关路由
│   │       ├── init.py
│   │       └── drone_status_websocket.py    # 查询无人机状态接口 
│   └── tools/                  # 工具函数(redis、数据库管理)
├── requirements.txt            # 项目依赖
└── README.md                   # 项目说明

接口调用规范

统一指令执行接口

端点POST /execute 实现位置app.http_routers.flight.endpoints.execute_command()

请求体结构

{
    "drone_id": 1,
    "connection_str": "udpin:192.168.1.225:14540",
    "protocol": "mavlink/ros/airsim",
    "command_type": "takeoff/arm/disarm",
    "params": {
        "alt": 15.5
    }
}

参数说明

字段 类型 约束 描述
drone_id int Required 设备唯一标识符,用于系统内状态跟踪
connection_str string Required 设备连接字符串,遵循协议特定格式规范
protocol enum Required 目标设备通信协议标识符
command_type enum Required 预定义指令类型枚举值
params object Optional 协议相关指令参数键值对

执行流程

  1. 指令验证
    • 通过Pydantic模型校验参数有效性
    • 验证设备ID在注册中心的合法性
  2. 适配器路由
def execute_command(command: CommandModel):
    # 获取协议适配器实例
    adapter = ProtocolAdapter.get_adapter(
        protocol=command.protocol,
        drone_id=command.drone_id,
        connection_str=command.connection_str
    )
    
    # 参数格式转换
    converted_params = ProtocolConverter.convert(
        command_type=command.command_type,
        protocol=command.protocol,
        params=command.params
    )
    
    # 执行设备指令
    return adapter.execute_command(
        command_type=command.command_type,
        parameters=converted_params
    )
  1. 协议转换规则
    • 转换规则定义于ProtocolConverter类的CONVERSION_RULES属性
    • protocol+command_type组合键进行参数映射

扩展开发规范

适配器接口约束

所有协议适配器必须继承BaseAdapter并实现以下方法(方法后续还可增加):

class BaseAdapter(ABC):
    @abstractmethod
    def connect(self) -> ConnectionStatus: ...
    
    @abstractmethod
    def execute_command(self, command_type: str, parameters: dict) -> CommandResult: ...
    
    @abstractmethod
    def get_status(self) -> DeviceStatus: ...
    
    @abstractmethod
    def disconnect(self) -> None: ...

状态管理规范

  1. 设备状态数据查询: 请返回对象数据
class MAVLinkAdapter(BaseAdapter):
    def get_status(self):
        result = {}
        return result
  1. 状态数据结构(尽量)要求:
{
    "battery_level": 85,
    "altitude": 15.5,
    "velocity": 2.3,
    "timestamp": "2023-07-20T14:23:18Z",
    ...
}
关于
2.2 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号