mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-25 03:56:38 +08:00
Added vehicle_local_position.ref_surface_timestamp to track surface level changes. Reference altitude updated continuosly when sonar available.
This commit is contained in:
@@ -235,7 +235,7 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[])
|
||||
const float pos_ctl_dz = 0.05f;
|
||||
|
||||
float ref_alt_prev = 0.0f;
|
||||
hrt_abstime ref_alt_prev_t = 0;
|
||||
hrt_abstime ref_surface_prev_t = 0;
|
||||
uint64_t local_ref_timestamp = 0;
|
||||
|
||||
PID_t xy_pos_pids[2];
|
||||
@@ -345,11 +345,10 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[])
|
||||
if (control_mode.flag_control_manual_enabled) {
|
||||
/* manual control */
|
||||
/* check for reference point updates and correct setpoint */
|
||||
if (local_pos.ref_timestamp != ref_alt_prev_t) {
|
||||
if (ref_alt_prev_t != 0) {
|
||||
/* reference alt changed, don't follow large ground level changes in manual flight */
|
||||
local_pos_sp.z -= local_pos.ref_alt - ref_alt_prev;
|
||||
}
|
||||
if (local_pos.ref_surface_timestamp != ref_surface_prev_t) {
|
||||
/* reference alt changed, don't follow large ground level changes in manual flight */
|
||||
mavlink_log_info(mavlink_fd, "[mpc] update z sp %.2f -> %.2f = %.2f", ref_alt_prev, local_pos.ref_alt, local_pos.ref_alt - ref_alt_prev);
|
||||
local_pos_sp.z += local_pos.ref_alt - ref_alt_prev;
|
||||
|
||||
// TODO also correct XY setpoint
|
||||
}
|
||||
@@ -476,6 +475,7 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[])
|
||||
} else {
|
||||
local_pos_sp.z = local_pos.ref_alt - global_pos_sp.altitude;
|
||||
}
|
||||
|
||||
att_sp.yaw_body = global_pos_sp.yaw;
|
||||
|
||||
mavlink_log_info(mavlink_fd, "[mpc] new sp: %.7f, %.7f (%.2f, %.2f)", (double)sp_lat, sp_lon, (double)local_pos_sp.x, (double)local_pos_sp.y);
|
||||
@@ -675,7 +675,7 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* track local position reference even when not controlling position */
|
||||
ref_alt_prev_t = local_pos.ref_timestamp;
|
||||
ref_surface_prev_t = local_pos.ref_surface_timestamp;
|
||||
ref_alt_prev = local_pos.ref_alt;
|
||||
|
||||
/* reset altitude controller integral (hovering throttle) to manual throttle after manual throttle control */
|
||||
|
||||
Reference in New Issue
Block a user