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

GPS Rescue using MSP is not getting Velocity to Home #13639

Merged
merged 1 commit into from
May 16, 2024

Conversation

AZDane
Copy link
Contributor

@AZDane AZDane commented May 15, 2024

When doing GPS Rescue using MSP, the quad was acting very erratically. Looking at the Blackbox data it was discovered that Velocity to home was not updating.

Examining the code it was discovered that calculateNavInterval() was not called when setting MSP for GPS.

Solution:
Added calculateNavInterval() function call into MSP GPS logic in src/main/io/gps.c and moved function calculateNavInterval() to above the call. Needed to update gpsSol.navIntervalMs so velocity to home can get calculated.

New code has been tested on quad with successful rescue.

code correction in collaboration with @ctzsnooze

Added calculateNavInterval() function call into MSP GPS logic. Needed to update gpsSol.navIntervalMs so velocity to home can get calculated.
Copy link

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13639 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@haslinghuis haslinghuis added this to the 4.6 milestone May 15, 2024
@ctzsnooze
Copy link
Member

Thanks @AZDane, great to work with you on this. Fantastic to find people who can find a problem, make a series of tests, find for a solution, and implement it via a PR.

Ps - I can’t figure how an MSP connected GPS rescue could have worked before this change?

@haslinghuis
Copy link
Member

Should we remove calculateNavInterval() from line 2199 as now it is called twice in same function (2204 in this PR)?

@AZDane
Copy link
Contributor Author

AZDane commented May 15, 2024

Should we remove calculateNavInterval() from line 2199 as now it is called twice in same function (2204 in this PR)?

The calls are in different cases of the switch statement where gpsSol.time is updated. If you put it outside the switch it will run even when gpsSol.time has not been updated. Don't know if there are unintended consequences by doing so.

@haslinghuis haslinghuis requested a review from a team May 15, 2024 23:27
@haslinghuis
Copy link
Member

Yes might no longer needed in second [switch] case - avoiding duplication and reducing overhead.

@AZDane
Copy link
Contributor Author

AZDane commented May 15, 2024

Yes might no longer needed in second [switch] case - avoiding duplication and reducing overhead.

But if you put it outside the switch it runs in every case, even when not needed, so what is the best approach? 2 of the cases renders different results of calculateNavInterval() because one case is based on gpsSol.time = ubxRcvMsgPayload.ubxNavPosllh.time and the other gpsSol.time = ubxRcvMsgPayload.ubxNavPvt.time

@ctzsnooze
Copy link
Member

There could be some refactoring to put the call to calculate the time delta at the very end of the sequence, after new data, MSP or otherwise, is received.

With this PR we put the call to calculate the time delta in each place where we receive a new time stamp with a new packet of data, ie:

  • line 2204 when we parse a new MSG_NAV_PVT packet (m10 type modules)
  • line 2152 when we parse a new MSG_NAV_POSLLH packet (earlier modules that don't support Nav_pvt)
  • and now at 1386 when we parse a new MSP packet.

Since we only get time updates with these specific elements, it seems to me that this is the correct approach.

A more substantial refactoring would require significant testing, and I think this bug fix should not be delayed by that.

@haslinghuis haslinghuis merged commit 9d4ebda into betaflight:master May 16, 2024
24 checks passed
haslinghuis pushed a commit to haslinghuis/betaflight that referenced this pull request May 16, 2024
Update gps.c

Added calculateNavInterval() function call into MSP GPS logic. Needed to update gpsSol.navIntervalMs so velocity to home can get calculated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants