Mavlink library function mavlink_msg_vfr_hud_get_alt returning wrong value on plane only

Hi, Not sure where to go with this one so in the hope Tridge might be willing to take a look, here goes:

I am working on the Mavlink->frsky telemetry project trying to get it fully functional with Plane (this is an old project, using a teensy Arduino board to convert mavlink messages into simulated FrSky Smartport sensors and these sensors’ data displayed in lua screen on the Taranis radio), and this works perfectly on Arducopter 3.3 and 3.4dev, but I have issues with barometric Altitude values returned when running this with Plane 3.5.3 (and 3.5.2). This is done when the arduino code calls the relevant function in the gsc_mavlink library:

`ap_bar_altitude = mavlink_msg_vfr_hud_get_alt(&msg) * 100;`

(this is line 468 in mavlink.ino for info) - the intention is to set ap_bar_altitude to the cm altitude (hence the *100) but the value returned by this call does not seem to represent barometric Altitude at all. the value returned (by mavlink_msg_vfr_hud_get_alt(&msg) before it is multiplied by 100) is a number in the 100’s and this keeps incrementing over time, even when the plane is stationary. Its as if the wrong value is being returned by the library call - this is supposed to represent Id 8 in Mavlink Msg #74. Sorry I’m new to all this so hoping what I have written makes sense to someone! I have reformatted the info here to hopefully make it more understandable.

The project is using the Mavlink v1.0 c++ common libraries included within the Teensy code project. Some project details:
Project link: https://github.com/Clooney82/MavLink_FrSkySPort
GCS_Mavlink libraries used by this project: https://github.com/Clooney82/MavLink_FrSkySPort/blob/s-c-l-v-rc-opentx2.1/libraries/GCS_MAVLink.zip

Just to reiterate - my query here is specific to Ardupilot Plane running on Pixhawk (its a Pixhawk Lite in my case), as the Altitude telemetry is read perfectly by the same Arduino code from a pixhawk running Copter 3.3.

Any help would be really appreciated. Cheers, Paul

I have been doing some more diags on this issue. It appears that the mavlink sensor info returned by the library call:

`mavlink_msg_vfr_hud_get_alt(&msg)`

to Plane 2.5, upon powering the flight controller (before a GPS fix is established), is the barometer altitude based on the home location. Then when a GPS fix is established, the value returned by this API call increases by an offset which relates to the GPS altitude for the current/home location (established from the 3D fix altitude value) - such that the value returned simulates the Altitude in relation to (MSL), rather than the home position. In my case the altitude increases by 200m once a GPS fix is obtained as my home location is 200m above sea level.

I don’t see this behavior using the same library call in Copter 3.3 (which returns the home altitude always), but I do in Plane 3.5 - so not sure if its always been this way in the Plane firmware, or if this is a new feature in 3.5.

In any case, I fixed this in the Mavlink->Smartport telemetry adapter by using the call:

`mavlink_msg_global_position_int_get_relative_alt(&msg)*0.001`

This instead takes the relative_alt value from Message #33 (based in mm) and divides this by 1000 to get the value in Metres.