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

Magnetometer & Sun Vector Attitude Filter Implementation #194

Merged
merged 27 commits into from
May 1, 2020

Conversation

kylekrol
Copy link
Member

@kylekrol kylekrol commented Apr 28, 2020

Magnetometer & Sun Vector Attitude Filter Implementation

Fixes #190.

Summary of changes

  • Added GRP attitude representation utility functions to convert to and from utility functions (deferring intensive unit testing to Unit Tests for the GRP Conversion Functions #193).
  • Added double and float interfaces for all environment functions (this is helpful for switching between floats and doubles in the filter implementation itself).
  • Updated the q_eci_perifocal constant to fix the sun vector model; appropriate unit tests were fixed as well.
  • Initial attitude filter implementation when we have both magnetometer and sun sensor readings.
  • Simple testcase for the attitude filter with magnetometer + sun sensor readings.

On the surface, the attitude filter seems to work. It's difficult to write good test cases using just PIO because numerical precision, at least so far, has been as issue. For example, the Frobenius norm of the update state covariance matrix is only accurate to two significant digits. Also, we currently only have a single testcase.

There are multiple tickets open to track the work on the attitude filter going forward: #187, #188, #189, #191, #193, and #197. This work includes:

  • Developing more testcase and looking at long term filter behavior in MATLAB.
  • Improving/verifying numerical stability specifically
  • Implementing the magnetometer only Kalman gain update step.
  • Adding GRP utility function testcases.

Ptest Effects

NA

Testing

See the added unit test cases and tickets listed above for further testing improvements to come.

Constants

Constant Location
gnc::constant::ukf_sigma_v src/gnc_attitude_estimator.cpp
gnc::constant::ukf_sigma_u sr/gnc_attitude_estimator.cpp
gnc::constant::ukf_sigma_b src/gnc_attitude_estimator.cpp
gnc::constant::ukf_sigma_s src/gnc_attitude_estimator.cpp
dt_thresh (local scope) src/gnc_attitude_estimator.cpp
q_factor (local scope) src/gnc_attitude_estimator.cpp
var_q (local scope) src/gnc_attitude_estimator.cpp
var_g (local scope) src/gnc_attitude_estimator.cpp
init_state (local scope) src/gnc_attitude_estimator.cpp

Documentation Evidence

See inline documentation and the paper mentioned in the file documentation in include/gnc/attitude_estimator.hpp.

@kylekrol kylekrol force-pushed the kkrol/attitude-estimator-impl branch from b7cc7e7 to d949b97 Compare April 28, 2020 05:22
@kylekrol kylekrol changed the title Initial Attitude Filter Implementation Magnetometer & Sun Vector Attitude Filter Implementation Apr 29, 2020
@kylekrol kylekrol marked this pull request as ready for review April 29, 2020 02:22
@kylekrol kylekrol requested review from srutiv and shihaocao April 29, 2020 18:48
include/gnc/constants.hpp Outdated Show resolved Hide resolved
include/gnc/utilities.hpp Outdated Show resolved Hide resolved
include/gnc/utilities.hpp Outdated Show resolved Hide resolved
include/gnc/utilities.hpp Outdated Show resolved Hide resolved
!lin::all(lin::isfinite(data.w_body)) ||
!lin::isfinite(data.t)) {
// Set the state and estimate to be invalid
state = AttitudeEstimatorState();
Copy link
Member

@nhz2 nhz2 Apr 30, 2020

Choose a reason for hiding this comment

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

Can the filter just propagate without sensor readings? Or does the state need to be reset.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can't just propagate without sensor readings, at least that's how it's coded now. In terms of our use case however, there won't be a cc where we don't have at least magnetometer and gyroscope data. If for some reason we don't have that information, we have bigger problems than our attitude filter too lol


// Calculate this steps measurement
UkfVector5 z_new {
lin::atan(data.s_body(1) / data.s_body(0)),
Copy link
Member

Choose a reason for hiding this comment

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

This can be NAN if s_body(0)==0

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a little concerning... However, in cxx a finite float over zero results in plus or minus infinity (IEEE floats at least) and according to the documentation the std::atan function (which is what lin::atan essentially calls) returns pi/2 and -pi/2 for inf and -inf respectively. In theory we should be alright.
This code will get replaced when the new sun vector variance handling scheme is incorporated (issue for that coming soon).

Links:
https://en.cppreference.com/w/cpp/numeric/math/atan
https://stackoverflow.com/questions/4745311/c-division-by-0

Copy link
Member

@tanishqaggarwal tanishqaggarwal left a comment

Choose a reason for hiding this comment

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

Just a couple of comments

src/gnc_environment.cpp Show resolved Hide resolved
src/gnc_environment.cpp Show resolved Hide resolved
@kylekrol kylekrol requested a review from nhz2 May 1, 2020 05:08
@kylekrol kylekrol merged commit 0906863 into master May 1, 2020
@kylekrol kylekrol deleted the kkrol/attitude-estimator-impl branch May 1, 2020 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Magnetometer and Sun Vector UKF Implementation
3 participants