Skip to content

Fence warn at the margins #28840

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

Merged
merged 21 commits into from
Apr 9, 2025
Merged

Conversation

andyp1per
Copy link
Collaborator

@andyp1per andyp1per commented Dec 11, 2024

This PR allows you to get a repeated warning when flying outside FENCE_MARGIN but inside the fence itself. Can be enabled by setting FENCE_OPTIONS=4. Multiple people have requested this because they are required to have a hard fence with failsafe action for regulatory reasons but want to know when they are close so they can avoid the action (typically when flying manually)

@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch from ce3674f to 9fbfa49 Compare December 12, 2024 14:05
@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch from 9fbfa49 to 336ea4e Compare December 13, 2024 20:44
@Hwurzburg Hwurzburg added the WikiNeeded needs wiki update label Dec 13, 2024
@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch from 336ea4e to 9fbfa49 Compare December 15, 2024 22:08
@Ryanf55
Copy link
Collaborator

Ryanf55 commented Dec 16, 2024

This PR allows you to get a repeated warning when flying outside FENCE_MARGIN but inside the fence itself. Can be enabled by setting FENCE_OPTIONS=4. Multiple people have requested this because they are required to have a hard fence with failsafe action for regulatory reasons but want to know when they are close so they can avoid the action (typically when flying manually)

Do you have any references to the specific regulatory requirements for fences?

tridge
tridge previously requested changes Dec 18, 2024
@rmackay9
Copy link
Contributor

Let's be careful about spamming the user when in Loiter mode and the user pushes the vehicle against the fence

@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch 2 times, most recently from 3248d57 to 5f08d05 Compare January 25, 2025 22:23
@andyp1per
Copy link
Collaborator Author

Getting the maths right on this was actually quite hard. Think I might have it now.

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Jan 25, 2025

Getting the maths right on this was actually quite hard. Think I might have it now.

Thoughts on unit tests to prove they are right?

@andyp1per
Copy link
Collaborator Author

Thoughts on unit tests to prove they are right?

I added a unit test, did you not see it?

@andyp1per
Copy link
Collaborator Author

Let's be careful about spamming the user when in Loiter mode and the user pushes the vehicle against the fence

So @rmackay9 what would you suggest here? If they have the option on and avoidance on and are in loiter mode, don't send the message?

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Jan 26, 2025

Thoughts on unit tests to prove they are right?

I added a unit test, did you not see it?

Totally missed it. Those look great. I'm guessing the choice of sphere approximation over something like ellipsoid with Vincenty's distance is because fences are usually small enough and with not enough accuracy that we can just neglect the difference?

@andyp1per
Copy link
Collaborator Author

Thoughts on unit tests to prove they are right?

I added a unit test, did you not see it?

Totally missed it. Those look great. I'm guessing the choice of sphere approximation over something like ellipsoid with Vincenty's distance is because fences are usually small enough and with not enough accuracy that we can just neglect the difference?

Yeah, I was relying on the reference @tpwrules sent me which shows that for small angles the haversine approximation is totally fine (the unit test demonstrates meter resolution). What wasn't fine was the original implementation which did not work at all for lat/lng 😛
It does make me wonder how accurate the current polyfence calculation is, but I haven't checked it.

@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch from 345f1f2 to 91d63c3 Compare January 26, 2025 19:35
@Ryanf55
Copy link
Collaborator

Ryanf55 commented Jan 26, 2025

Thoughts on unit tests to prove they are right?

I added a unit test, did you not see it?

Totally missed it. Those look great. I'm guessing the choice of sphere approximation over something like ellipsoid with Vincenty's distance is because fences are usually small enough and with not enough accuracy that we can just neglect the difference?

Yeah, I was relying on the reference @tpwrules sent me which shows that for small angles the haversine approximation is totally fine (the unit test demonstrates meter resolution). What wasn't fine was the original implementation which did not work at all for lat/lng 😛 It does make me wonder how accurate the current polyfence calculation is, but I haven't checked it.

Yep, we just might want a wiki note to not try to use fences to define boundaries the size of a country because you can be far enough off that you'll make the wrong people mad.

@andyp1per
Copy link
Collaborator Author

andyp1per commented Jan 26, 2025 via email

@andyp1per andyp1per requested a review from peterbarker January 26, 2025 20:50
@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch 2 times, most recently from 2854ea4 to a0b9e86 Compare January 30, 2025 11:23
@tridge tridge dismissed stale reviews from peterbarker and themself April 9, 2025 07:05

fixed

@andyp1per andyp1per force-pushed the pr-fence-warn-margin branch from 736528a to 72f7f3c Compare April 9, 2025 12:31
@andyp1per andyp1per merged commit f3bdb54 into ArduPilot:master Apr 9, 2025
103 checks passed
@andyp1per andyp1per deleted the pr-fence-warn-margin branch April 9, 2025 16:01
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.

9 participants