Skip to content

Commit

Permalink
Fix WPNav terrain following
Browse files Browse the repository at this point in the history
  • Loading branch information
lthall committed Sep 28, 2024
1 parent 7347692 commit dfec4e4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions libraries/AC_WPNav/AC_WPNav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ bool AC_WPNav::set_wp_destination(const Vector3f& destination, bool terrain_alt)
if (terrain_alt) {
// new destination is alt-above-terrain, previous destination was alt-above-ekf-origin
_origin.z -= origin_terr_offset;
_pos_control.set_pos_offset_z_cm(_pos_control.get_pos_offset_z_cm() + origin_terr_offset);
_pos_control.init_pos_terrain_cm(origin_terr_offset);
} else {
// new destination is alt-above-ekf-origin, previous destination was alt-above-terrain
_origin.z += origin_terr_offset;
_pos_control.set_pos_offset_z_cm(_pos_control.get_pos_offset_z_cm() - origin_terr_offset);
_pos_control.init_pos_terrain_cm(0.0);
}
}

Expand Down Expand Up @@ -532,11 +532,6 @@ bool AC_WPNav::advance_wp_target_along_track(float dt)
target_accel *= sq(vel_scaler_dt);
target_accel += accel_offset;

// convert final_target.z to altitude above the ekf origin
target_pos.z += _pos_control.get_pos_offset_z_cm();
target_vel.z += _pos_control.get_vel_offset_z_cms();
target_accel.z += _pos_control.get_accel_offset_z_cmss();

// pass new target to the position controller
_pos_control.set_pos_vel_accel(target_pos.topostype(), target_vel, target_accel);

Expand Down Expand Up @@ -782,11 +777,11 @@ bool AC_WPNav::set_spline_destination(const Vector3f& destination, bool terrain_
if (terrain_alt) {
// new destination is alt-above-terrain, previous destination was alt-above-ekf-origin
_origin.z -= origin_terr_offset;
_pos_control.set_pos_offset_z_cm(_pos_control.get_pos_offset_z_cm() + origin_terr_offset);
_pos_control.init_pos_terrain_cm(origin_terr_offset);
} else {
// new destination is alt-above-ekf-origin, previous destination was alt-above-terrain
_origin.z += origin_terr_offset;
_pos_control.set_pos_offset_z_cm(_pos_control.get_pos_offset_z_cm() - origin_terr_offset);
_pos_control.init_pos_terrain_cm(0.0);
}
}

Expand Down

0 comments on commit dfec4e4

Please sign in to comment.