AC_WPNav: protect from divide by zero especially when using CH6 tuning of WP speed #18560
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes a few cosmetic fixes to AC_WPNav:
.. and one real fix to avoid a divide-by-zero if ch6 tuning is being used to change the WP speed inflight. The reason the divide-by-zero could happen was that channel 6 tuning would call AC_WPNav::set_speed_xy() before AC_WPNav::wp_and_spline_init() was called. This means that _wp_desired_speed_xy_cms was still zero and led to the divide-by-zero.
This has been tested in SITL both before and after this change. Below is a screenshot of the ch6 tuning knob being used to set the WPNAV_SPEED value. Before this fix the simulator would crash and report the divide-by-zero.
![image](https://user-images.githubusercontent.com/1498098/131963736-ae0dc0d4-f6c6-4927-a3f3-72cf1aeac0e9.png)
This issue was discovered as part of the Copter-4.1.0-beta report, "Ch6 tuning of WP speed broken" on the 4.1 issues list and was reported here on the forums.