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

Navigation: fix calculations of ground speeds and navigation progress #2532

Merged
merged 3 commits into from
May 26, 2020
Merged

Navigation: fix calculations of ground speeds and navigation progress #2532

merged 3 commits into from
May 26, 2020

Conversation

joezie
Copy link
Contributor

@joezie joezie commented May 24, 2020

  • add fabs and explicit type conversion respectively to fix calculation errors

Fixes issue #2531

…f ground speeds and navigation progress

- add fabs and explicit type conversion respectively to fix calculation errors

Fixes issue #2531
@@ -170,7 +170,7 @@ static void compute_ground_speed(float airspeed,
/* g^2 -2 scal g + c = 0 */
float scal = wind_east * cos(alpha) + wind_north * sin(alpha);
float delta = 4 * (scal * scal - c);
ground_speeds[i] = scal + sqrt(delta) / 2.;
ground_speeds[i] = scal + sqrt(fabs(delta)) / 2.;

Choose a reason for hiding this comment

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

This is not the proper way I think. The navigation routine should just fail if delta is negative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the latest commit, I changed to return false on calculation failure.

@@ -592,7 +592,7 @@ void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
INT32_VECT2_RSHIFT(pos_diff, pos_diff, INT32_POS_FRAC);
uint32_t leg_length2 = Max((wp_diff.x * wp_diff.x + wp_diff.y * wp_diff.y), 1);
nav_leg_length = int32_sqrt(leg_length2);
nav_leg_progress = (pos_diff.x * wp_diff.x + pos_diff.y * wp_diff.y) / nav_leg_length;
nav_leg_progress = (pos_diff.x * wp_diff.x + pos_diff.y * wp_diff.y) / (int32_t)nav_leg_length;

Choose a reason for hiding this comment

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

good catch

@gautierhattenberger gautierhattenberger merged commit 4f62afe into paparazzi:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants