Autonomy: rangefinders, maps, avoidance and precision landing · 6 MIN READ
Flying without GPS: frozen telemetry, drift, the landing failsafe and your own policy
Detect a GPS outage at the ground station from the fix flag and repeated positions rather than message age, measure how far a drone drifts in wind when its autopilot can only keep level, watch the 'no GPS for 3 s: landing' failsafe act, and compare hold, land and climb policies in an urban canyon with the failsafe on and off.
GPS fails in ordinary places: between tall buildings, under a bridge, beside large steel structures, or near radio interference. Without a position, a multicopter autopilot still holds its attitude and, with a barometer, its height. What it loses is the ability to stay over a point, and in wind that means drifting downwind while the telemetry keeps looking healthy. The ground station has to notice the outage, and the program has to decide what to ask for. Whatever the program decides, the autopilot's own failsafe will act.
drones · A MAP OF THE IDEA
- Watch flag and repeats
- Expect drift in wind
- Agree with the failsafe
- Plan to avoid outages
Useful when
- Content checks catch a frozen fix within 0.3 s.
- Policy runs show which action suits a site.
Watch out
- Hold is impossible without a position estimate.
- The autopilot lands on its own timer, whatever you ask.
Implementation & operation cost: A content check on every position stream, a written outage policy that matches the autopilot configuration, and routes planned for sky view.
What the vehicle knows without a fix
Position and velocity both come from the receiver; the gyros and accelerometers keep the attitude, and the barometer the height. Position integrated from acceleration drifts within seconds, so the autopilot cannot hold a point for long. In the simulator, d.LoseGPS(seconds) takes the fix away: GPSFix() turns false, Telemetry().GPS and .Velocity freeze at the last report, and the autopilot keeps the drone level, so the wind accelerates it until it moves with the air. Real flight stacks first dead-reckon on their inertial sensors. PX4 declares the position lost when it has dead-reckoned for EKF2_NOAID_TOUT, or, for a hovering vehicle, when the horizontal error exceeds COM_POS_FS_EPH. Its position loss failsafe then puts a multicopter in an autonomous mode into Return, else Land, else Descend, which needs no position. In a manual position mode it switches to Altitude mode instead. ArduPilot's EKF failsafe fires when two of its compass, position and velocity variances stay above FS_EKF_THRESH for 1 s. By default FS_EKF_ACTION then lands, in the modes that need a position.
Spotting a stale fix at the ground station
Telemetry keeps arriving during an outage, so the staleness check from the telemetry-streams lesson, the age of the newest report, finds nothing wrong: every report is fresh, but its content is old. Three checks do catch it. The first is the receiver's own flag: in MAVLink, fix_type in GPS_RAW_INT drops below GPS_FIX_TYPE_3D_FIX and satellites_visible falls; in the simulator, GPSFix() turns false. The second is repetition: real GPS noise never reports exactly the same position twice, so three identical reports mean a frozen source. The third is consistency: a position that does not move while the vehicle reports tilt, airspeed or a moving camera image is wrong. Apply the same checks to the fused position in GLOBAL_POSITION_INT, because an autopilot may keep publishing a dead-reckoned estimate for a while after the receiver went quiet.
Lose the fix, then fly a street six times
The program first hovers at 20 m in a 5 m/s wind with gusts and takes the fix away for 20 s. A ground-station loop reads every 5 Hz report, counts identical reports and tracks the age of the newest one. It prints the first three reports, then one every 2 s, next to the true drift, which only the simulator knows. Then it flies a street six times: east at 10 m along a 26 m wide street between 25 m buildings, with a 4 m/s wind blowing across it. Between the rows and below the roofs, the program's world model takes the sky away. The program reacts to the lost fix with one of three policies: hold, land, or climb at 3 m/s. It flies each policy once with the simulator's failsafe on and once with it off. The runs with the failsafe off stand for an autopilot configured with that action, not for switching safety off.
package main
import (
"fmt"
"log"
"math"
"strings"
"gopherforge.app/drone"
)
const roof = 25.0 // height of the buildings along the street, m
// openField hovers at 20 m in wind, loses GPS for 20 s and watches the
// telemetry the way a ground station receives it.
func openField() {
sim := drone.New(drone.Config{Wind: drone.Vec3{X: 5}, Gust: 1.5, Seed: 8})
d := sim.Drone()
if err := d.Arm(); err != nil {
log.Fatal(err)
}
d.TakeOff(20)
sim.RunUntil(30, func(float64) bool { return d.Arrived() })
sim.Run(2, nil)
fmt.Println("hover at 20 m, 5 m/s wind: GPS lost for 20 s at +0.0 s")
fmt.Println(" t report GPS position fix same true drift mode")
t0, start := sim.Time(), d.State().Pos
d.LoseGPS(20)
last, same, flagAt, frozenAt, maxAge, reports := d.Telemetry(), 0, -1.0, -1.0, 0.0, 0
sim.RunUntil(20, func(t float64) bool {
tel := d.Telemetry()
if !d.GPSFix() && flagAt < 0 {
flagAt = t - t0 // the receiver's own flag, GPS_RAW_INT.fix_type in MAVLink
}
maxAge = math.Max(maxAge, t-tel.Time) // how old the newest report is
if tel.Time == last.Time {
return d.State().Landed
}
if tel.GPS == last.GPS && tel.Velocity == last.Velocity {
same++ // real GPS noise never repeats a position exactly
} else {
same = 0
}
if same == 2 && frozenAt < 0 {
frozenAt = t - t0
}
if reports++; reports <= 3 || reports%10 == 0 { // the first three, then every 2 s
fmt.Printf(" %+5.1f %+5.1f %-20v %-5v %4d %6.1f m %v\n", t-t0, tel.Time-t0, tel.GPS, d.GPSFix(), same,
d.State().Pos.Sub(start).Horizontal().Len(), d.State().Mode)
}
last = tel
return d.State().Landed
})
fmt.Printf("detected: fix flag at %+.1f s, frozen position at %+.1f s; newest report never older than %.1f s\n",
flagAt, frozenAt, maxAge)
for _, e := range sim.Events() {
if e.T >= t0 {
fmt.Printf(" %+5.1f s %s\n", e.T-t0, e.Text)
}
}
fmt.Printf("touched down %.1f m downwind of where the fix was lost\n", d.State().Pos.Sub(start).Horizontal().Len())
if err := sim.SaveAs("open-field"); err != nil {
log.Fatal(err)
}
}
// street is two rows of overlapping buildings: a 26 m wide street along X.
func street() []drone.Obstacle {
var out []drone.Obstacle
for i := range 12 {
x := 30 + 8*float64(i)
out = append(out, drone.Obstacle{Name: fmt.Sprintf("north %d", i+1), X: x, Y: 18, Radius: 5, Height: roof},
drone.Obstacle{Name: fmt.Sprintf("south %d", i+1), X: x, Y: -18, Radius: 5, Height: roof})
}
return out
}
// canyon flies east along the street at 10 m with the wind blowing across
// it. Between the buildings and below the roofs the sky is blocked; when the
// program sees the fix go, it applies its policy.
func canyon(policy string, failsafe bool) *drone.Sim {
sim := drone.New(drone.Config{Wind: drone.Vec3{Y: 4}, Gust: 1, MaxSpeed: 4, Seed: 5,
Obstacles: street(), NoFailsafe: !failsafe})
d := sim.Drone()
if err := d.Arm(); err != nil {
log.Fatal(err)
}
d.TakeOff(10)
sim.RunUntil(30, func(float64) bool { return d.Arrived() })
d.GoTo(drone.Vec3{X: 150, Z: 10})
lostAt, acted, hitAt := -1.0, false, -1.0
sim.RunUntil(80, func(t float64) bool {
p := d.State().Pos
// The world: no satellites in view between the rows, below the roofs.
if p.X > 25 && p.X < 125 && p.Z < roof+1 {
d.LoseGPS(1)
}
// The program: act once on a lost fix; after a climb, hold above the roofs.
switch {
case !d.GPSFix() && !acted:
lostAt, acted = t, true
switch policy {
case "hold":
d.Hold()
case "land":
d.Land()
case "climb":
d.SetVelocity(drone.Vec3{Z: 3}, 0)
}
case policy == "climb" && acted && d.GPSFix() && d.State().Mode == drone.Velocity:
d.Hold()
}
st := d.State()
if st.Mode == drone.Crashed && hitAt < 0 {
hitAt = st.Pos.Z
}
return st.Landed || st.Mode == drone.Crashed && st.Pos.Z == 0 || acted && d.GPSFix() && st.Mode == drone.Hold && t-lostAt > 15
})
var notes []string
for _, e := range sim.Events() {
if strings.HasPrefix(e.Text, "hit") {
e.Text += fmt.Sprintf(" at %.1f m", hitAt)
}
if lostAt >= 0 && e.T >= lostAt && !strings.HasPrefix(e.Text, "GPS lost") && e.Text != "land" {
notes = append(notes, fmt.Sprintf("%+.1f %s", e.T-lostAt, e.Text))
}
}
p := d.State().Pos
fmt.Printf(" %-5s %-3s %s; y %.1f m, z %.1f m\n", policy, map[bool]string{true: "on", false: "off"}[failsafe],
strings.Join(notes, ", "), p.Y, p.Z)
return sim
}
func main() {
openField()
fmt.Println("\nstreet: 10 m up, 26 m between 25 m buildings, 4 m/s wind across it")
fmt.Println(" policy, failsafe: seconds after the program saw the fix go; where it ended (y north)")
var replay *drone.Sim
for _, failsafe := range []bool{true, false} {
for _, policy := range []string{"hold", "land", "climb"} {
if sim := canyon(policy, failsafe); policy == "climb" && failsafe {
replay = sim // the climb the failsafe cut short
}
}
}
if err := replay.Save(); err != nil {
log.Fatal(err)
}
}The fix flag drops at +0.0 s. The reported position, (0.5, -0.5, 21.1), repeats from the first report, so the third identical report marks it frozen at +0.3 s, yet the newest report is never older than 0.2 s. The true drift grows from 1.4 m at +1.9 s to 4.8, 8.8 and 13.0 m, and reaches 18.1 m at +9.9 s as the drone picks up the wind's speed. At +3.0 s the failsafe starts 'no GPS for 3 s: landing'. The descent from 20 m lasts until +16.9 s, and the drone touches down 40.6 m downwind of where the fix was lost. In the street with the failsafe on, both hold and climb end in 'hit north 4' at +10.4 s, 2.0 m and 5.5 m up: the failsafe turned both into a landing at +3.0 s, too late to reach the ground before the drift reached the buildings. Land, with the failsafe on or off, touches down at +9.5 s, 12.2 m north of the centre line; the buildings' faces start at 13 m. With the failsafe off, hold drifts into the buildings at 10.0 m. Only the climb gets out: the fix comes back above the roofs at +7.2 s, and the drone holds 28.7 m up, 7.4 m north.
A policy of your own, and why the failsafe acts anyway
Each policy has a case. Hold is what an operator expects, and the one thing an autopilot cannot do without a position: the drone drifts exactly as if nothing had been commanded. Land shortens the time in the air and so limits the drift, but it lands wherever the wind has carried the drone, and a street may be a road. Climb looks for sky: above the roofs the fix comes back and the vehicle can hold again, provided it climbs faster than it drifts towards a wall. With the failsafe on, the program does not get the last word. After 3 s the autopilot lands whatever was commanded, so the climb is cut off halfway and the hold becomes a late landing, both worse than landing at once. That is deliberate. The failsafe runs on the flight controller because it must work when the companion computer, the link or the program is what failed, and it cannot know what a program meant. So make the program's policy agree with the configured action. Choose that action on purpose from what the autopilot offers (in ArduPilot, FS_EKF_ACTION: report only, Land, AltHold, or Land from any mode) and test it. Above all, plan routes that keep outages short: a street survey flown above the roofs never needs a canyon policy.
Fly it in GopherForge
In GopherForge choose New project > Robotics and simulation > Drone flight, replace main.go with this program (mission.go can stay; its Square helper does not clash) and tap Run. Output lists two recordings. open-field.gfflight is the hover that drifts 40 m downwind as it descends. flight.gfflight is the climb the failsafe cut short: the replay draws the two rows of buildings as grey discs, and the flight ends at the north row. Lower the wind to 2 m/s, widen the street, or fly the street at 30 m, above the roofs, and see which policies still matter.
TAKE THIS WITH YOU
Without GPS an autopilot keeps its attitude and its height, and drifts with the wind while telemetry keeps arriving with a frozen position. Detect the outage from the fix flag and from repeated values, not from message age. The autopilot's failsafe acts on its own timer whatever your program commands, so make your policy agree with it, choose and test the configured action, and plan routes that keep outages short.
Check your understanding
During a GPS outage the ground station still receives a position report every 0.2 s. Which checks reveal that the position is stale?
Go to the source
Progress stays in this browser. No account needed.