Set gps data via pymavlink

Hello BlueRobotics! I have some problems with setting gps data via mavlink message. I want to send gps data to my controller, and after it, I want to see them on qgc, or just by calling message for getting during coordinates.
Also I want to ackent on this. After I install image of companion computer to raspberry pi, I connect it to the internet via wifi, and started execution of script called setup.sh which have to download and build all additional software. I add configuration to file mavproxy.param, so I could sent data from host machine to another port “–out udpbcast:192.168.2.255:14560”

I also saw string --load-module=‘GPSInput,DepthOutput’, I can’t found what DepthOutput is, and for what it is needed?

As alternative I think to use c++ mavlink, maybe there are some mistakes in pymavlink.
But I have some problems with c++ mavlink library, I tried to compile example, and I get this:
gcc -std=c99 -I …/…/include/common -o mavlink_udp mavlink_udp.c
mavlink_udp.c:54:21: fatal error: mavlink.h: No such file or directory
#include <mavlink.h>
^
compilation terminated.

But i found 4 reference of it, but only for pymavlink:
/home/pi/companion/submodules/mavlink/pymavlink/generator/C/include_v1.0/test/mavlink.h
/home/pi/companion/submodules/mavlink/pymavlink/generator/C/include_v0.9/test/mavlink.h
/home/pi/mavlink/pymavlink/generator/C/include_v1.0/test/mavlink.h
/home/pi/mavlink/pymavlink/generator/C/include_v0.9/test/mavlink.h

So, I have questions:

  1. How to transfer GPS data to pixhawk controller via mavlink (I saw in example wich have to work in auto mode. I try to run it with sitl, sitl of UAV has stopped, like there is no gnss data for it, like it has conflikt with sitl gnss, and mine, it could be). Never the less, I want to set gnss data to pixhawk, and receive the same data.
    Pymavlink · GitBook

  2. QGC have to use show data via mavlink console, but it shows nothing. Is it correct? If not, how to fix that?

  3. I want to use m64 acoustick modem, for transfering data to mavproxy, GNSS, and maybe mission for example. Maybe with setup.sh some prerequired packages are installed, or there is some example for it?

GPSInput accepts NMEA strings and translates them to GPS_INPUT messages that the autopilot consumes.

I agree that this is probably due to the SITL internal positioning. I’m not sure if that can be turned off.
You can experiment setting SIM_GPS_DISABLE to 1, and setting the GPS_TYPE to mavlink.

IIRC that was used to connect to the NuttX console. It probably won’t work at all now the Ardupilot used ChibiOS.

We don’t have anything ready on that front, but it should be doable. Just be aware that the bandwidth is limited, which means you will have to carefully pick the mavlink messages you send both ways.

Thank you Wiliiam.
But I have some added questions,

  1. There are some acoustic gnss driver in companion, would it work correct?
  2. I install python library for m64 modem, so I can transfer data via this library and pack it to gps command in pymavlink. Why setting gps, as was shown in example doesn’t work? Or how can I check it?
    Pelase, can you show me some python example for it. I saw the reference which you provide to pymavlink, for now I don’t understand how to create message correctly

For now, with companion I run script for setting gps data :

 import time
from pymavlink import mavutil

def wait_conn():
    """
    Sends a ping to stabilish the UDP communication and awaits for a response
    """
    msg = None
    while not msg:
        master.mav.ping_send(
            int(time.time()), # Unix time
            0, # Ping number
            0, # Request ping of all systems
            0 # Request ping of all components
        )
        msg = master.recv_match()
        time.sleep(0.5)
master = mavutil.mavlink_connection('udpout:0.0.0.0:9000')
wait_conn()

# Set some information !
while True:
    time.sleep(0.2)
    master.mav.gps_input_send(
        0,  # Timestamp (micros since boot or Unix epoch)
        0,  # ID of the GPS for multiple GPS inputs
        # Flags indicating which fields to ignore (see GPS_INPUT_IGNORE_FLAGS enum).
        # All other fields must be provided.
        8 | 16 | 32,
        0,  # GPS time (milliseconds from start of GPS week)
        0,  # GPS week number
        3,  # 0-1: no fix, 2: 2D fix, 3: 3D fix. 4: 3D with DGPS. 5: 3D with RTK
        0,  # Latitude (WGS84), in degrees * 1E7
        0,  # Longitude (WGS84), in degrees * 1E7
        60,  # Altitude (AMSL, not WGS84), in m (positive for up)
        1,  # GPS HDOP horizontal dilution of position in m
        1,  # GPS VDOP vertical dilution of position in m
        0,  # GPS velocity in m/s in NORTH direction in earth-fixed NED frame
        0,  # GPS velocity in m/s in EAST direction in earth-fixed NED frame
        0,  # GPS velocity in m/s in DOWN direction in earth-fixed NED frame
        0,  # GPS speed accuracy in m/s
        0,  # GPS horizontal accuracy in m
        0,  # GPS vertical accuracy in m
        7   # Number of satellites visible.
    )

And I receive it with script on host machine:

from pymavlink import mavutil

master = mavutil.mavlink_connection('udpin:0.0.0.0:14550')
#Why I need this?
master.wait_heartbeat()
# Get some information !
while True:
    try:
        altitude = master.messages['GPS_RAW_INT'].alt  # Note, you can access message fields as attributes!
        timestamp = master.time_since('GPS_RAW_INT')
        print(altitude)
    except:
        print('No GPS_RAW_INT message received')

I want to admit, that this script is working if I run it with sitl, so when sitl emulated data, I can recieve them via this script.

I also saw this article about GPS
https://www.ardusub.com/developers/developers/pymavlink.md

But can’t understand how it should be used, I want to send data to GNSS to pixhawk, and also recive them. So as a next step, I cpuld connect m64 python driver to it.

It should be doable. We have a driver for the Waterlinked Underwater GPS.
I was mistaken when I said the GPSInput module takes NMEA, it actually takes json objects.

Your code looks right, but I wouldn’t send the 0,0 cordinates as they could be (erroneously) used for checking for a valid gps signal.

Your code should be sending the GPS coordinate to the autopilot with mav.gps_input_send() and then listening for GLOBAL_POSITION_INT messages back from the autopilot.

Thank you!
I also want to try m64 waterlink for control of rov, as was shown on one of yours posts. Controll via acoustic modem.
P.s. can you tell me how to write this messages with examples, I mean receive, or where can see documentation for them. In mavlink site, I only saw some poor examples with python, and most of infromation about enums commands, and messages. How to call them with python scripts, there is no reference.
For now, I’m just lerning python, I saw your refernce, but this file somewhere in depths of library.
There also some reference in ardusub site GPS:
https://www.ardusub.com/developers/developers/pymavlink.md
But it tells, I need some autopilot configuration. Also I want to ask, is it possible with working mavlink server to send data primary to pixhawk via ttyACM0? Or what the technology for that? And I need some terminal for finding what happened with pixhawk, to see, what is inside.

I want to understand how to use api of this library with reference to mavlink documentation. And check is it work correct or not.

What should I change in my during files?

Also I saw python driver for underwater-gnss. I saw, that it transfer data to qgc , before of it , it has lines as
system(‘screen -S mavproxy -p 0 -X stuff “param set GPS_TYPE 14^M”’)
May be I incorrectly set parameters to server?
–master=/dev/autopilot,115200
–out udpin:localhost:5050
–load-module=‘GPSInput,DepthOutput’
–source-system=200
–cmd=“set heartbeat 0”
–out udpin:localhost:9000
–out udpout:localhost:9002
–out udpin:0.0.0.0:14660
–out udpbcast:192.168.2.255:14550
–out udpbcast:192.168.2.255:14560
–mav20
–aircraft telemetry
–streamrate 10

At , the end. I add this line --cmd=“param set GPS_TYPE 14”, Also I want to note, that I have no devices connected to pixhawk, except raspberry pi.

I debuged mavproxy library, and saw that it transfer message to pixhawk, but I can’t receive seted parameters, pixhawl sends only zeros to me.

Can you provide to me some working scripts? I don’t know what to do for now.

I reflashed pixhawk with nuttx os from qgc, now it can take lat and lon, but it shows me alt = 0, independent for what kind of alt I set to it. (positive or negative, I used my previous script).

I reflashed pixhawk, now it can take lat and lon, but it showed me alt = 0, independent for what king of alt I set to it. But I get the same parameters, if I use GPS_RAW_INT.
What the difference, how I can transfer alt for pixhawk with interested flags?

Hi @YuryArnaut,
The depth is probably coming from the Bar30. IIRC there is a ALT_SOURCE parameter for chosing the source of altitude information for the ekf. Try setting that to 1 (GPS)

Thank you! I have installed m64-modem library for communication. Before of that I run script setup.sh on raspbian, provided by your company. It installed pymavlink, after that I installed m64 library, this 2 libraries depend on different type of python, 2.7 and 3.6. I want to connect them and try to transfer information. Can you give some help for that, because I saw an example how you make control with acoustic modem to bluerow.

William I can’t understand how to set to IIRC ALT_SOURCE parameter, I mean what kind of message I should use to set it.

Hi @YuryArnaut,

Check the EK2_ALT_SOURCE parameter using QGroundControl. Default behavior is to use the Baro altitude.