Skip to content

Commit

Permalink
vtol: always check for EKF2 resets, not just when QC is checked
Browse files Browse the repository at this point in the history
Signed-off-by: Silvan Fuhrer <[email protected]>
  • Loading branch information
sfuhrer committed Nov 23, 2023
1 parent eae939d commit a99a7d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/modules/vtol_att_control/vtol_att_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ VtolAttitudeControl::Run()
_air_density = air_data.rho;
}

_vtol_type->handleEkfResets();

// check if mc and fw sp were updated
const bool mc_att_sp_updated = _mc_virtual_att_sp_sub.update(&_mc_virtual_att_sp);
const bool fw_att_sp_updated = _fw_virtual_att_sp_sub.update(&_fw_virtual_att_sp);
Expand Down
15 changes: 9 additions & 6 deletions src/modules/vtol_att_control/vtol_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ bool VtolType::isFrontTransitionAltitudeLoss()
{
bool result = false;

// check if there is a reset in the z-direction, and if so, shift the transition start z as well
if (_local_pos->z_reset_counter != _altitude_reset_counter) {
_local_position_z_start_of_transition += _local_pos->delta_z;
_altitude_reset_counter = _local_pos->z_reset_counter;
}

// only run if param set, altitude valid and controlled, and in transition to FW or within 5s of finishing it.
if (_param_vt_qc_t_alt_loss.get() > FLT_EPSILON && _local_pos->z_valid && _v_control_mode->flag_control_altitude_enabled
&& (_common_vtol_mode == mode::TRANSITION_TO_FW || hrt_elapsed_time(&_trans_finished_ts) < 5_s)) {
Expand All @@ -318,6 +312,15 @@ bool VtolType::isFrontTransitionAltitudeLoss()
return result;
}

void VtolType::handleEkfResets()
{
// check if there is a reset in the z-direction, and if so, shift the transition start z as well
if (_local_pos->z_reset_counter != _altitude_reset_counter) {
_local_position_z_start_of_transition += _local_pos->delta_z;
_altitude_reset_counter = _local_pos->z_reset_counter;
}
}

bool VtolType::isPitchExceeded()
{
// fixed-wing maximum pitch angle
Expand Down
6 changes: 6 additions & 0 deletions src/modules/vtol_att_control/vtol_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ class VtolType : public ModuleParams
*/
void resetTransitionStates();

/**
* @brief Handle EKF position resets.
*
*/
void handleEkfResets();

protected:
VtolAttitudeControl *_attc;
mode _common_vtol_mode;
Expand Down

0 comments on commit a99a7d2

Please sign in to comment.