Servers by jDrones

Reading mavlink mesage GPS_RAW_INT with python

``Hello all,
I have been going through the documentation on the mavlink web site. I copied and pasted the code below. when I run it the except case it always used. If I comment this out I get key error ‘GPS_RAW_INT’.

Has anyone else had this problem before its on there web site maybe something is outdated. `
altitude=the_connection.messages[‘GPS_RAW_INT’].alt # Note, you can access message fields as attributes!
print(‘No GPS_RAW_INT message received’)

I’ve just tried it in SITL and it works if you put a time delay in:

from pymavlink import mavutil
import time

# Start a connection listening to a UDP port
the_connection = mavutil.mavlink_connection('udpin:localhost:14550')

# Wait for the first heartbeat 
#   This sets the system and component ID of remote system for the link
print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_system))

# Wait for the vehicle to send GPS_RAW_INT message

    altitude=the_connection.messages['GPS_RAW_INT'].alt  # Note, you can access message fields as attributes!
    print("Altitude is " + str(altitude))
    print("Time is " + str(timestamp))
    print('No GPS_RAW_INT message received')

Thank you very much for the doing this. I will give this a try. I am running arduplane sitl sim_vehicle too.

Hello again,
So I just copied and pasted your code into a new python script. I have it connect to the arduplane SITL on 14550 as you have done and I get the no GPS message found.

I also tried it with arducopter.
In addition I tried the code with a real pixhawk

bummer, I will keep looking into this

Servers by jDrones