MicroPilot

MicroPilot Autopilot Users Group

How can I limit the distance the UAV can go and terminate the flight if it goes too far?

There are a few ways to automatically monitor the distance the UAV is flying.

The Max Flight Distance field is for preventing waypoints from being outside that distance. So during well performing autonomous flight the UAV won't be commanded to go to a location beyond that distance (it could still pass it a small amount if a waypoint is on the edge and you have fly through waypoints). It will not terminate the flight though.

A fly file with waypoints beyond this distance will cause an error during start up, and Horizon operators will not be able to drag waypoints outside of this range.

To terminate the flight immediately if a boundary is passed a geofence should be used. The geofence to stop the UAV right away can be a 4 corner geofence set up in the Flight tab, or a multi-point geofence set up in the Failures tab. The Failures tab option lets you enter coordinates in deicmal degrees while the Flight tab option requires autopilot units (F1 help for more details). Crossing the geofence will set throttle to 0 and desired altitude to 0.

Make sure to note is that you do not want to hit the geofence accidentally during flight at all. Hitting the geofence will permanently terminate the flight without regard for the UAVs health.
*If the geofence is breached the UAV will come down and crash*
It is for preventing flyaways and works very well for that but if you have a large approved flight area don't limit yourself with a tight geofence. Keep the geofence wide and use the distance to geofence/distance to home/no fly zones to give a smaller artificial limit to make sure you do not exceed your expected flight distance while safely staying a large distance from the geofence. That way you can safely recover the UAV if you fly too far, and still have the geofence bring it down if it is really flying away and somehow managed to reach the geofence.

There are a few options to monitor distance and have a response:

1. Have a thread monitor field 1286 [distHome] and start a pattern to fly back home, hover, or whatever behaviour you want if you exceed a certain distance from home (initialization point).

2. Have a thread monitor field 2362 [geofenceDistanceFromAutopilot] and have the thread start a pattern if it is within a certain distance of the geofence.
Additional related fields for distance from the geofence (3.7 only):
8992 [geofenceDistanceWarning]
8993 [geofenceDistanceCaution]

3. Use No-fly zones in Horizon. You can draw a No-fly zone overlay in the Map Selector and Horizon can show a warning if the UAV flies into the no-fly zone and it will also set field 1875 [uavInNoFlyZone] to 1 on the autopilot if the UAV enters the no-fly zone.
The UAV and waypoints are not prevented from going into the no fly zone, it is a graphical zone only.
A thread could be used to respond to this by monitoring field 1875 and starting a pattern.
The autopilot does not know about the Horizon no-fly zone so this requires a GCS link to the UAV for Horizon to set that field, so this can be used in conjunction with a geofence. The geofence should be placed further of course so it is not reached by the time this warning occurs.


Starting a pattern from a thread, there are two ways to do this:

1. Set a user-defined fatal error in the thread to force the fatalErrorFailed pattern to start, and put your commands to execute in that pattern.
The main autopilot manual has a section called "User-Defined Fatal Errors" for more details, it has an example thread to set a user-defined fatal error from a thread based on speed:

thread
waitgreaterthan [currentSpeed], 73 // wait until speed is > 80 km/hr
[2080] = 229 // set fatal error code 229
repeat -2


2. Use the 'int' command (in the command section of the main autopilot manual).
This command will let you end the current pattern (if one is active) with 'int -1' and then start the specified user defined pattern # with 'int #'. So your user-defined thread can make thread0 (main navigation thread) start a pattern.

thread
waitgreaterthan [currentSpeed], 73 // wait until speed is > 80 km/hr
int -1 //end any active user pattern
int 3 //start user pattern 3
waitNotEqual [currentPattern], 3 //Wait here while pattern 3 is running
repeat -4


Since failure patterns are higher priority than user defined patterns this will fail if a failure pattern is active. So if you temporarily lose RC and are in the rcFailed pattern your geofence/distance monitoring thread will not be able to react to getting close to the geofence since it can't start your user-defined pattern

So the fatal error option above would be the better way for important threads such as monitoring the distance to the geofence since the fatalErrorFailed is a high priority failure pattern.

Putting it all together, here is an example thread that starts a pattern when within 500ft of the geofence. As an example, this will interrupt autonomous flight (if no failure pattern is active) and fly home.

thread 1
waitLessThan [geofenceDistanceFromAutopilot], 4000 //wait until you are 500ft or less from the geofence (ft*8)
int -1 //If another pattern is running, end it.
int 0 //start pattern 0
waitNotEqual [currentPattern], 0 //wait until pattern 0 isn't running any more to start checking the geofence distance again (should be back at home when pattern 0 ends unless pattern 0 is ended manually through Horizon)
repeat -4

definePattern 0
hoverAt [home] //fly home
return

Views: 147

Reply to This

Share

© 2024   Created by MicroPilotNingAdmin.   Powered by

Report an Issue  |  Terms of Service