Altitude control using baro

Dear all,
I have a question about altitude control using baro (without gps or sonar, lidar). I use postition_estimator_inav module and see a line of code as follows:
/* publish local position */
local_pos.xy_valid = can_estimate_xy;
local_pos.v_xy_valid = can_estimate_xy;
local_pos.xy_global = local_pos.xy_valid && use_gps_xy;
local_pos.z_global = local_pos.z_valid && use_gps_z;
local_pos.x = x_est[0];
local_pos.vx = x_est[1];
local_pos.y = y_est[0];
local_pos.vy = y_est[1];
local_pos.z = z_est[0];
local_pos.vz = z_est[1];
local_pos.yaw = att.yaw;
local_pos.dist_bottom_valid = dist_bottom_valid;
local_pos.eph = eph;
local_pos.epv = epv;
I think local_pos.z is the target height value calculated (or corrected) by barometer; however, when I extract this value using flightplot, the unit in the Y axis can be negative, so my question is what is the unit of this value ( I presume it should be in ‘meters’), why it can be negative?
Furthermore, is baro data converted into meters in the firmware?

Z points downward in the Local frame.
Baro altitude is published in meters in the sensor_combined topic.
Beware that baro altitude is AMSL (above mean sea level) so it will be positive unless you’re on the ground in New Orleans :slight_smile:

Thanks for the reply. As you have said, I can understand Z could be negative since it represents AMSL, and points downward in the axis. My question then is how the base point, I mean, (0,0,0) is determined? Z value only makes sense when there exists a base point, am I right?

The 0 point is calculated as the average of first several hundreds of barometer values.
If you search “wait_baro” in the cpp file, you will find more details.
Hope this correct.

1 Like

Thanks for the quick reply.
Yeah, I see wait_baro variable in the file, and I also understand the calculation of average baro values, but I do not see any evidence that says this average value is regarded as the 0 point in the axis. This value, I think, is the initial value before flight, or precisely speaking, before the copter is armed. Any ideas?

This average is stored in baro_offset.
When the baro is used, this would be subtracted from the barometer value.
corr_baro = baro_offset - sensor.baro_alt_meter - z_est[0];
Isn’t it?

Oh, you are right. Zero Z is regarded as the baro_offset point, but the actual baro_offset value is not 0; it is the AMSL value, and z_est[0] is the actual flight height in meters. Am I right?

The z_est in the inav module should be regarded as the height w.r.t where you start the system, no matter how the ground changes during the flight.