Poll Mavlink2rest interface via Python

I would like to output sensor data, heading, depth, pitch and roll.

  • We will use EIVA NaviPac/NaviScan for online data acquisition, have support for a range of telegrams, see attached. In general, comma separated ASCII terminated with should be fine. Some preferences below, tried to keep it to the simple telegrams.

  • Serial Port or UDP output OK. We can add moxa nport-server for adding serial ports to topside laptop if required. Probably easiest for us with with serial port outputs, to avoid network VLAN issues as we operate online system in another VLAN.

  • Proposed telegrams:

    • Depth: Preferred: Digiquartz format outputting absolute pressure in PSI (not tared). If not possible/to complex, custom telegram with depth in meters: DEPTH, xx.x

    • Heading: NMEA HDT

    • Roll, Pitch: TSS DMS

    • Other information available, such as turns interesting but not high priority

Hi @stevejrov - welcome to the forums!

Obtaining the data you’re after from the Mavlink2Rest interface is easy! You can see an example of how to do that for yaw in this extension.

Generally, you’ll need to change the address of the vehicle -

yaw_url= 'http://host.docker.internal/mavlink2rest/mavlink/vehicles/1/components/1/messages/ATTITUDE'

replace host.docker.internal with your vehicle IP address, or if running from the terminal, 127.0.0.1 should work. The host.docker.internal address is used when the code is packaged in an extension docker container.

The Attitude message contains the Roll, Pitch, and Heading. Depth can be found at another address, likely Pressure. This code extracts the Yaw from the Attitude message, and formats it in degrees.

        yaw_response = requests.get(yaw_url)
...
            yaw_data = yaw_response.json()['message']
...
            yawRad = yaw_data['yaw']
...
            yawDeg = math.degrees(yawRad)
...
            yaw = round(((yawDeg + 360) % 360),2)

To review the json format of these messages, simply open the Mavlink2Rest interface from the Available Services menu in BlueOS. ChatGPT helped me generate the python code to parse these as desired!

Once your script is getting the data you require from Mavlink2Rest, you can send it by whatever method and in whatever format you may desire- as a UDP packet is going to be more straight forward than sending it from a serial port on the Navigator, however this is possible! I’m not familiar with “Digiquartz” format but I imagine a LLM AI can help generate the code necessary to send messages in this or whatever format.

When developing, running your python script from the BlueOS terminal, or a instance of Visual Studio code connected via SSH to the vehicle is easy! Keep in mind if running from within Blue-OS, you’ll need to take the red-pill to get out of the Docker container and have access to Mavlink2Rest.

Thanks Tony