Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ekf2: cleanup output predictor init #20960

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dagar
Copy link
Member

@dagar dagar commented Jan 18, 2023

  • output predictor align also init _output_vert_new
  • output predictor reset handle all fields
  • output predictor resetQuaternion() normalize
  • output predictor calculateOutputStates() paranoid timestamp check
  • output predictor correctOutputStates() paranoid timestamp checks and explicitly pop delayed sample at correct time

@dagar dagar added the EKF2 label Jan 18, 2023
@dagar dagar requested a review from bresch January 18, 2023 19:37
@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch 5 times, most recently from 6bbfef5 to b4a313d Compare January 20, 2023 19:50
@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch from b4a313d to 284073f Compare January 27, 2023 16:03
@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch 3 times, most recently from e9003b7 to a5efedd Compare February 17, 2023 14:12
@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch from a5efedd to c32a89e Compare March 6, 2023 16:02
src/modules/ekf2/EKF/ekf_helper.cpp Outdated Show resolved Hide resolved
src/modules/ekf2/EKF/output_predictor.cpp Outdated Show resolved Hide resolved
src/modules/ekf2/EKF/output_predictor.cpp Outdated Show resolved Hide resolved
src/modules/ekf2/EKF/output_predictor.cpp Show resolved Hide resolved
 - output predictor align also init _output_vert_new
 - output predictor reset handle all fields
 - output predictor resetQuaternion() normalize
 - output predictor calculateOutputStates() paranoid timestamp check
 - output predictor correctOutputStates() paranoid timestamp checks and
explicitly pop delayed sample at correct time
@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch from c32a89e to b172705 Compare August 8, 2023 18:33
Copy link
Member

@bresch bresch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move on with that PR, could you rebase please?

@dagar dagar force-pushed the pr-ekf2_output_predictor_init_cleanup branch from edb8750 to 0290a61 Compare October 26, 2023 15:16
Comment on lines +352 to +374
// calculate the quaternion rotation delta from the EKF to output observer states at the EKF fusion time horizon
const Quatf q_delta((quat_state * output_delayed.quat_nominal.inversed()).normalized());
const Dcmf rot_change{q_delta};

// add the reset amount to the output observer buffered data
for (uint8_t i = 0; i < _output_buffer.get_length(); i++) {

_output_buffer[i].quat_nominal = (q_delta * _output_buffer[i].quat_nominal).normalized();

// apply change to velocity
_output_buffer[i].vel = rot_change * _output_buffer[i].vel;
_output_buffer[i].vel_alternative = rot_change * _output_buffer[i].vel_alternative;
}

// apply the change in attitude quaternion to our newest quaternion estimate
_output_new.quat_nominal = (q_delta * _output_new.quat_nominal).normalized();

// calculate a gain that provides tight tracking of the estimator attitude states and
// adjust for changes in time delay to maintain consistent damping ratio of ~0.7
const uint64_t time_latest_us = _time_last_update_states_us;
const float time_delay = fmaxf((time_latest_us - time_delayed_us) * 1e-6f, _dt_update_states_avg);
const float att_gain = 0.5f * _dt_update_states_avg / time_delay;

// calculate a corrrection to the delta angle
// that will cause the INS to track the EKF quaternions
_delta_angle_corr = delta_ang_error * att_gain;
_output_tracking_error(0) = delta_ang_error.norm();
// apply change to velocity
_output_new.vel = rot_change * _output_new.vel;
_output_new.vel_alternative = rot_change * _output_new.vel_alternative;

/*
* Loop through the output filter state history and apply the corrections to the velocity and position states.
* This method is too expensive to use for the attitude states due to the quaternion operations required
* but because it eliminates the time delay in the 'correction loop' it allows higher tracking gains
* to be used and reduces tracking error relative to EKF states.
*/
propagateVelocityUpdateToPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this exactly the same as in resetQuaternion?


// apply change to velocity
_output_buffer[i].vel = rot_change * _output_buffer[i].vel;
_output_buffer[i].vel_alternative = rot_change * _output_buffer[i].vel_alternative;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you're trying to do here, but why correcting the velocities here if they are anyway re-corrected just after?

const float vert_vel_err = (vel_state(2) - output_vert_delayed.vert_vel);
const float vert_vel_integ_err = (pos_state(2) - output_vert_delayed.vert_vel_integ);
// calculate the velocity and position deltas between the output and EKF at the EKF fusion time horizon
output_delayed.vel = q_delta.rotateVectorInverse(output_delayed.vel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use rotateVector(... or rot_change * ... here?
Also, it seems that this is only needed because the velocity is corrected during the quaternion correction above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 👀 In review/test
Development

Successfully merging this pull request may close these issues.

2 participants