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

Fixed wrapping issue. #5

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions rosplane/src/estimator_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ float radians(float degrees)
return M_PI*degrees/180.0;
}

double wrap_within_180(double fixed_heading, double wrapped_heading) {
// wrapped_heading - number_of_times_to_wrap * 2pi
return wrapped_heading - floor((wrapped_heading - fixed_heading) / (2 * M_PI) + 0.5) * 2 * M_PI;
}

estimator_example::estimator_example() :
estimator_base(),
xhat_a_(Eigen::Vector2f::Zero()),
Expand Down Expand Up @@ -237,17 +242,15 @@ void estimator_example::estimate(const params_s &params, const input_s &input, o

P_p_ = (A_d_*P_p_*A_d_.transpose() + Q_p_*pow(params.Ts/N_, 2));
}

while(xhat_p_(3) > radians(180.0f)) xhat_p_(3) = xhat_p_(3) - radians(360.0f);
while(xhat_p_(3) < radians(-180.0f)) xhat_p_(3) = xhat_p_(3) + radians(360.0f);

xhat_p_(3) = wrap_within_180(0.0, xhat_p_(3));
if(xhat_p_(3) > radians(180.0f) || xhat_p_(3) < radians(-180.0f))
{
RCLCPP_WARN(this->get_logger(), "Course estimate not wrapped from -pi to pi");
xhat_p_(3) = 0;
}

while(xhat_p_(6) > radians(180.0f)) xhat_p_(6) = xhat_p_(6) - radians(360.0f);
while(xhat_p_(6) < radians(-180.0f)) xhat_p_(6) = xhat_p_(6) + radians(360.0f);
xhat_p_(6) = wrap_within_180(0.0, xhat_p_(6));
if(xhat_p_(6) > radians(180.0f) || xhat_p_(6) < radians(-180.0f))
{
RCLCPP_WARN(this->get_logger(), "Psi estimate not wrapped from -pi to pi");
Expand Down Expand Up @@ -290,8 +293,9 @@ void estimator_example::estimate(const params_s &params, const input_s &input, o
//wrap course measurement
float gps_course = fmodf(input.gps_course, radians(360.0f));

while (gps_course - xhat_p_(3) > radians(180.0f)) gps_course = gps_course - radians(360.0f);
while (gps_course - xhat_p_(3) < radians(-180.0f)) gps_course = gps_course + radians(360.0f);
xhat_p_(3) = wrap(xhat_p_(3), gps_course);
// while (gps_course - xhat_p_(3) > radians(180.0f)) gps_course = gps_course - radians(360.0f);
iandareid marked this conversation as resolved.
Show resolved Hide resolved
// while (gps_course - xhat_p_(3) < radians(-180.0f)) gps_course = gps_course + radians(360.0f);
h_p_ = xhat_p_(3);

C_p_ = Eigen::VectorXf::Zero(7);
Expand Down
Loading