16个版本 (9个重大变更)

0.10.0 2020年11月6日
0.8.0 2020年7月4日
0.5.0 2020年3月23日
0.2.0 2019年11月10日

#139 in WebSocket

Download history 4/week @ 2024-02-22 3/week @ 2024-02-29 73/week @ 2024-03-28 35/week @ 2024-04-04

每月51次下载

MIT 许可证

42KB
676

Mavlink2Rest

Build Test Cargo download Crate info Documentation

mavlink2rest 创建一个REST服务器,从MAVLink源提供MAVLink信息。

当前版本支持 ardupilotmega 方言,包括 commonicarousuavionix

安装 ⚡

  • ⚙️ Cargo 安装: cargo install mavlink2rest

下载 📦

持续构建:

对于其他或不同的版本,请检查发布菜单

端点

页面

  • 主页面: GET /
    • 提供有关mavlink2rest和可用消息的信息。

API

  • MAVLink JSON
    • GET /mavlink|/mavlink/*. 输出是一个JSON,你可以单独获取每个嵌套键,例如

    • POST /mavlink的消息信息结构。将消息发送到特定车辆。

    • GET /helper/message/MAVLINK_MESSAGE_NAME:辅助端点,用于创建与JSON兼容的MAVLink消息,其中MAVLINK_MESSAGE_NAME是MAVLink消息名称。例如

      • http://0.0.0.0:8088/helper/message/COMMAND_LONG
        {
            "header": {
                "system_id": 255,
                "component_id": 0,
                "sequence": 0
            },
            "message": {
                "type": "COMMAND_LONG",
                "param1": 0.0,
                "param2": 0.0,
                "param3": 0.0,
                "param4": 0.0,
                "param5": 0.0,
                "param6": 0.0,
                "param7": 0.0,
                "command": {
                    "type": "MAV_CMD_NAV_WAYPOINT" // Random value
                },
                "target_system": 0,
                "target_component": 0,
                "confirmation": 0
            }
        }
        

示例

获取所有消息
curl --request GET http://0.0.0.0:8088/mavlink\?pretty\=true
# The output is huge, you can get it here: https://gist.github.com/patrickelectric/26a407c4e7749cdaa58d06b52212cb1e
获取姿态
curl --request GET http://0.0.0.0:8088/mavlink/ATTITUDE?pretty=true
{
  "message_information": {
    "counter": 46460,
    "frequency": 7.966392517089844,
    "time": {
      "first_message": "2020-03-28T12:47:52.315383-03:00",
      "last_message": "2020-03-28T14:25:04.905914-03:00"
    }
  },
  "pitch": 0.004207547288388014,
  "pitchspeed": 0.0010630330070853233,
  "roll": 0.004168820567429066,
  "rollspeed": 0.0009180732304230332,
  "time_boot_ms": 6185568,
  "type": "ATTITUDE",
  "yaw": -1.5562472343444824,
  "yawspeed": 0.0009576341835781932
}
获取最后一个ATTITUDE消息的时间
curl --request GET http://0.0.0.0:8088/mavlink/ATTITUDE/message_information/time/last_message?pretty=true
"2020-03-28T14:28:51.577853-03:00"
获取一个消息结构示例
curl --request GET http://0.0.0.0:8088/helper/message/ATTITUDE\?pretty\=true
{
  "header": {
    "system_id": 255,
    "component_id": 0,
    "sequence": 0
  },
  "message": {
    "type": "ATTITUDE",
    "time_boot_ms": 0,
    "roll": 0.0,
    "pitch": 0.0,
    "yaw": 0.0,
    "rollspeed": 0.0,
    "pitchspeed": 0.0,
    "yawspeed": 0.0
  }
}
请求车辆武装
# ARM: param1 is 1.0
curl --request POST http://0.0.0.0:8088/mavlink -H "Content-Type: application/json" --data \
'{
  "header": {
    "system_id": 1,
    "component_id": 1,
    "sequence": 0
  },
  "message": {
    "type":"COMMAND_LONG",
    "param1":1.0,
    "param2":0.0,"param3":0.0,"param4":0.0,"param5":0.0,"param6":0.0,"param7":0.0,
    "command":{
      "type":"MAV_CMD_COMPONENT_ARM_DISARM"
    },
    "target_system":0,
    "target_component":0,
    "confirmation":0
  }
}'
请求车辆解除武装
# ARM: param1 is 0.0
curl --request POST http://0.0.0.0:8088/mavlink -H "Content-Type: application/json" --data \
'{
  "header": {
    "system_id": 1,
    "component_id": 1,
    "sequence": 0
  },
  "message": {
    "type":"COMMAND_LONG",
    "param1":0.0,
    "param2":0.0,"param3":0.0,"param4":0.0,"param5":0.0,"param6":0.0,"param7":0.0,
    "command":{
      "type":"MAV_CMD_COMPONENT_ARM_DISARM"
    },
    "target_system":0,
    "target_component":0,
    "confirmation":0
  }
}'

注意:对于任何无效的GET,您将收到一个包含错误信息的404响应。注意:允许使用GET并返回JSON输出的端点,也允许使用布尔值truefalse的查询参数pretty,例如:http://0.0.0.0:8088/helper/message/COMMAND_LONG?pretty=true

WebSocket

还可以通过以下路径连接多个WebSocket:/ws/mavlink,该端点也接受查询参数filter,筛选值应该是匹配MAVLink消息名称的正则表达式,例如:对于所有消息的/ws/mavlink?filter=.*,对于匹配RC_.*/ws/mavlink?filter=RC_.*将匹配RC_CHANNELS_RAWRC_CHANNELS,产生以下输出

{ // First message
  "chan10_raw": 0,
  "chan11_raw": 0,
  "chan12_raw": 0,
  "chan13_raw": 0,
  "chan14_raw": 0,
  "chan15_raw": 0,
  "chan16_raw": 0,
  "chan17_raw": 0,
  "chan18_raw": 0,
  "chan1_raw": 1500,
  "chan2_raw": 1500,
  "chan3_raw": 1500,
  "chan4_raw": 1500,
  "chan5_raw": 1500,
  "chan6_raw": 1500,
  "chan7_raw": 1500,
  "chan8_raw": 1500,
  "chan9_raw": 0,
  "chancount": 16,
  "message_information": {
    "counter": 3732,
    "frequency": 4.0,
    "time": {
      "first_message": "2020-09-01T20:36:24.088099-03:00",
      "last_message": "2020-09-01T20:51:57.278901-03:00"
    }
  },
  "rssi": 0,
  "time_boot_ms": 3122812,
  "type": "RC_CHANNELS"
}
{ // Second message
  "chan1_raw": 1500,
  "chan2_raw": 1500,
  "chan3_raw": 1500,
  "chan4_raw": 1500,
  "chan5_raw": 1500,
  "chan6_raw": 1500,
  "chan7_raw": 1500,
  "chan8_raw": 1500,
  "message_information": {
    "counter": 3732,
    "frequency": 4.0,
    "time": {
      "first_message": "2020-09-01T20:36:24.088310-03:00",
      "last_message": "2020-09-01T20:51:57.279438-03:00"
    }
  },
  "port": 0,
  "rssi": 0,
  "time_boot_ms": 3122812,
  "type": "RC_CHANNELS_RAW"
}

请查看示例文件夹中的示例进行演示:websocket_client.py

基准测试

以下基准测试是从连接到运行ArduSub的pixhawk的树莓派3中提取的。

  • 空闲。

    6% CPU usage
    
  • 1个客户端以10Hz请求所有MAVLink消息

    9% CPU usage
    
  • 1个客户端以100Hz请求所有MAVLink消息

    20% CPU usage (~5% each core)
    
  • 1个没有筛选器的WebSocket

    11% CPU usage
    
  • 5个没有筛选器的WebSocket

    24% CPU usage (14% @ 1 core, ~3% @ 3 cores)
    
  • 20个只筛选ATTITUDE消息(接收频率为10Hz)的WebSocket

    9% CPU usage
    
  • 20个只筛选NAMED_VALUE_FLOAT消息(接收频率为70Hz)的WebSocket

    17% CPU usage (9% @ 1 core, ~2% @ 3 cores)
    
  • 20个没有筛选器的WebSocket

    48% CPU usage (20% @ 1 core, ~9% @ 3 cores)
    
  • 1个客户端请求所有MAVLink消息1000次

    60% CPU usage (~15% each core)
    Time taken for tests      3.7 seconds
    Total requests            1000
    Successful requests       1000
    Failed requests           0
    Requests per second       273.60 [#/sec]
    Median time per request   3ms
    Average time per request  4ms
    
  • 10个客户端请求所有MAVLink消息,每个客户端100次请求。

    140% CPU usage (~46% each core)
    Time taken for tests      1.4 seconds
    Total requests            1000
    Successful requests       1000
    Failed requests           0
    Requests per second       733.14 [#/sec]
    Median time per request   13ms
    Average time per request  13ms
    Sample standard deviation 3ms
    
  • 100个客户端请求所有MAVLink消息,每个客户端1000次请求。

    140% CPU usage (~46% each core)
    Time taken for tests      13.8 seconds
    Total requests            10000
    Successful requests       10000
    Failed requests           0
    Requests per second       725.83 [#/sec]
    Median time per request   132ms
    Average time per request  137ms
    Sample standard deviation 54ms
    

依赖项

~30MB
~614K SLoC