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 1 commit
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
22 changes: 15 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(double fixed_heading, double wrapped_heading) {
iandareid marked this conversation as resolved.
Show resolved Hide resolved
// 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,19 @@ 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(0.0, xhat_p_(3));
// while(xhat_p_(3) > radians(180.0f)) xhat_p_(3) = xhat_p_(3) - radians(360.0f);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would remove these commented out lines, since we won't be needing them anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Of course, I didn't realize they weren't deleted!

// while(xhat_p_(3) < radians(-180.0f)) xhat_p_(3) = xhat_p_(3) + radians(360.0f);
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(0.0, xhat_p_(6));
// 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);
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 +297,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