Autonomy: rangefinders, maps, avoidance and precision landing · 6 MIN READ
Inspecting a structure: a constant-standoff orbit from rangefinder feedback
Orbit a mast at a constant distance from its surface with a radial PI loop on the rangefinder and a tangential speed, count laps, and compare per-lap standoff statistics with a GPS-only orbit around a mapped position that is a few metres off.
Inspection flights photograph masts, chimneys, wind turbine towers and bridge piers from a fixed distance, so that every image has the same scale and focus and the vehicle never drifts into the structure. Autopilots can orbit a point in coordinates. That works when the coordinates are right, but site plans, imagery and GPS are each good to a few metres, and a 4 m error in the centre turns an 8 m standoff into anything from 4 to 12 m.
drones · A MAP OF THE IDEA
- Find the mast in the scan
- Radial PI on range error
- Tangential speed command
- Count laps, score standoff
Useful when
- Holds the standoff to centimetres whatever the map error.
- The measured bearing can point the camera without a model.
Watch out
- Lattice towers, guy wires and flat walls break the round-mast model.
- A lost return must stop the orbit, not continue it blind.
Implementation & operation cost: A horizontal rangefinder or scan, a radial PI loop with anti-windup at 10 Hz, and a lap counter and standoff log per inspection.
Orbiting a point: what autopilots offer
PX4's Orbit mode takes a centre, radius, altitude and speed from a ground station or from MAV_CMD_DO_ORBIT, whose parameters are the radius (positive clockwise, negative counter-clockwise), the tangential velocity, the yaw behaviour, the number of radians to fly and the centre. It faces the centre by default and limits the speed to keep the centripetal acceleration below 2 m/s2. ArduPilot's Circle mode orbits a point CIRCLE_RADIUS_M ahead of the vehicle (in metres, default 10; CIRCLE_RADIUS in centimetres up to firmware 4.6) at CIRCLE_RATE degrees per second, limits the speed so that the centripetal acceleration stays under half of WP_ACC, and with CIRCLE_OPTIONS can set the centre at the current position and point a mount at it. Both fly a circle around coordinates on the position estimate; neither measures the structure. The centripetal acceleration is v squared / R: 0.95 m/s2 at 3 m/s on a 9.5 m radius.
Closing the loop on the structure
A horizontal rangefinder measures the quantity that matters, the distance to the surface. For a round mast the shortest reading in a scan points at its centre, so one scan gives both the inward direction n and the range r. Command v = vt t + (kp e + ki integral of e) n, with e = r - standoff, n pointing at the mast and t = n turned 90 degrees clockwise, which keeps the mast on the left and flies counter-clockwise. The integral earns its place here for a different reason than in the PID altitude lesson: the circle needs an inward acceleration, the velocity loop lags the command as it turns, and the drone drifts outwards until a P-only loop has enough error to command the inward speed it needs. The integral supplies that command with zero error and also absorbs the wind; clamp it, as in the PID lesson's anti-windup. Count laps by unwrapping the bearing to the mast and counting whole turns of 2 pi.
A GPS orbit against a rangefinder orbit
The mast stands at (30, 20) with a radius of 1.5 m and a height of 40 m; the site plan puts it at (27, 22.5). The target is 8 m from the surface at 3 m/s and 20 m altitude, in a 3 m/s wind with 1.5 m/s gusts, three laps per method. The GPS-only orbit runs the same radial PI on the distance from the telemetry GPS to the mapped centre; the rangefinder orbits use the shortest of 360 beams, once with P only (kp 0.8) and once with PI (ki 0.15). Every lap prints its duration, the true standoff from the simulator's truth (what an inspector measuring the images would find), its RMS error against 8 m, and the RMS error the controller believes it has.
package main
import (
"fmt"
"log"
"math"
"gopherforge.app/drone"
)
const (
standoff = 8.0 // m from the mast's surface: what the camera is focused for
vt = 3.0 // m/s along the orbit
alt = 20.0 // m
laps = 3
)
var (
mast = drone.Obstacle{Name: "mast", X: 30, Y: 20, Radius: 1.5, Height: 40}
mapped = drone.Vec3{X: 27, Y: 22.5} // where the site plan puts it: 3.9 m off
)
// Stats collects, over one lap, the true standoff and the error the
// controller believes it has.
type Stats struct{ n, sum, sq, min, max, believed float64 }
func (s *Stats) Add(v, e float64) {
if s.n == 0 {
s.min, s.max = v, v
}
s.n, s.sum, s.sq, s.believed = s.n+1, s.sum+v, s.sq+(v-standoff)*(v-standoff), s.believed+e*e
s.min, s.max = math.Min(s.min, v), math.Max(s.max, v)
}
func (s Stats) String() string {
return fmt.Sprintf("standoff %4.1f..%4.1f m mean %4.2f rms error %4.2f m (believed %4.2f)",
s.min, s.max, s.sum/s.n, math.Sqrt(s.sq/s.n), math.Sqrt(s.believed/s.n))
}
// Nearest returns the shortest reading and its heading: towards the centre
// of a round mast, as the shortest distance to a circle points at its centre.
func Nearest(scan []float64) (r, heading float64) {
k := 0
for i := range scan {
if scan[i] < scan[k] {
k = i
}
}
return scan[k], 2 * math.Pi * float64(k) / float64(len(scan))
}
// Orbit flies `laps` counter-clockwise laps. The guidance function returns
// the unit vector towards the centre and the radial error (positive: too
// far out), from whatever the vehicle believes.
func Orbit(label string, ki float64, guidance func(d *drone.Drone) (drone.Vec3, float64, bool)) *drone.Sim {
sim := drone.New(drone.Config{Wind: drone.Vec3{X: 3, Y: -1}, Gust: 1.5, Obstacles: []drone.Obstacle{mast}, Seed: 17})
d := sim.Drone()
if err := d.Arm(); err != nil {
log.Fatal(err)
}
d.TakeOff(alt)
sim.RunUntil(30, func(float64) bool { return d.Arrived() })
start := mapped.Add(drone.Vec3{X: -(standoff + mast.Radius), Z: alt})
d.GoTo(start)
sim.RunUntil(60, func(float64) bool { return d.Arrived() })
fmt.Println(label)
integral, e, turned, lap, prev, lapStart := 0.0, 0.0, 0.0, 0, math.NaN(), sim.Time()
var s Stats
sim.RunUntil(400, func(t float64) bool {
st := d.State()
if math.Mod(math.Round(t/sim.Dt()), 5) == 0 { // 10 Hz
in, err, ok := guidance(d)
if e = err; !ok {
d.Hold()
return true
}
integral = math.Max(-2, math.Min(2, integral+e*0.1))
radial := math.Max(-2, math.Min(2, 0.8*e+ki*integral))
tangent := drone.Vec3{X: in.Y, Y: -in.X} // centre on the left: counter-clockwise
d.SetVelocity(tangent.Scale(vt).Add(in.Scale(radial)), 0)
}
// truth, for scoring only: the angle around the real mast and the real standoff
rel := st.Pos.Sub(drone.Vec3{X: mast.X, Y: mast.Y}).Horizontal()
a := math.Atan2(rel.Y, rel.X)
if !math.IsNaN(prev) {
turned += math.Remainder(a-prev, 2*math.Pi)
}
prev = a
s.Add(rel.Len()-mast.Radius, e)
if turned >= 2*math.Pi*float64(lap+1) {
lap++
fmt.Printf(" lap %d %4.1f s %v\n", lap, t-lapStart, s)
s, lapStart = Stats{}, t
}
return lap == laps
})
fmt.Printf(" radial integral %.2f m/s\n", ki*integral)
d.Land()
sim.RunUntil(60, func(float64) bool { return d.State().Landed })
return sim
}
func main() {
fmt.Printf("mast at (%.1f, %.1f), radius %.1f m; the site plan says (%.1f, %.1f), %.1f m off\n",
mast.X, mast.Y, mast.Radius, mapped.X, mapped.Y, mapped.Sub(drone.Vec3{X: mast.X, Y: mast.Y}).Len())
fmt.Printf("orbit %.0f m from the surface at %.0f m/s, %d laps each, wind 3 m/s with gusts\n", standoff, vt, laps)
gps := Orbit("GPS only, around the mapped centre:", 0.15, func(d *drone.Drone) (drone.Vec3, float64, bool) {
rel := mapped.Sub(d.Telemetry().GPS).Horizontal()
return rel.Scale(1 / rel.Len()), rel.Len() - mast.Radius - standoff, true
})
ranged := func(d *drone.Drone) (drone.Vec3, float64, bool) {
r, h := Nearest(d.Scan(360))
return drone.Vec3{X: math.Cos(h), Y: math.Sin(h)}, r - standoff, r < drone.RangeMax
}
p := Orbit("rangefinder, radial P only:", 0, ranged)
pi := Orbit("rangefinder, radial PI:", 0.15, ranged)
if err := gps.SaveAs("gps-orbit"); err != nil {
log.Fatal(err)
}
if err := p.SaveAs("p-only"); err != nil {
log.Fatal(err)
}
if err := pi.Save(); err != nil {
log.Fatal(err)
}
}The GPS orbit is a good circle around the wrong point. Its controller believes it holds 8 m within 0.52 to 0.63 m RMS, the GPS noise, while the true standoff swings from 3.8 to 12.2 m with 2.32 to 2.90 m RMS error, so the image scale changes threefold around each lap. The rangefinder orbits start 11.1 m out and converge during lap 1. P only settles at 8.25 m, 0.25 m outside, the error it needs to command about 0.2 m/s inwards (0.8 x 0.25); PI holds a mean of 8.02 and 8.04 m with 0.07 and 0.08 m RMS on laps 2 and 3, and its integral ends at 0.24 m/s, the same inward command delivered without an error. What the rangefinder controller believes agrees with the truth to 0.02 m, because it measures what it controls. Laps take 18.8 to 20.2 s, close to 2 pi x 9.5 / 3 = 19.9 s.
Inspection in practice
Real structures are rarely smooth cylinders. A lattice tower lets beams through, guy wires are invisible to most scanners and must come from the map with a wide margin, and a flat wall has a nearest point but no centre, so follow it along its normal instead. Near large structures GNSS also suffers from multipath and a blocked sky, one more reason to measure the structure directly. Point the camera along the measured bearing rather than at the mapped centre. Cover the height in laps at several altitudes, stepping by the camera's vertical footprint minus the overlap, as the survey in the waypoint missions lesson stepped sideways. Decide what happens when the return is lost: a reading at maximum range means the structure is gone from view, so hold or back away instead of flying the last command, and keep the mapped position as a sanity check on the measured one, which should agree within the map's known error.
Fly it in GopherForge
In GopherForge choose New project > Robotics and simulation > Drone flight, replace main.go with this program, keep mission.go and tap Run. Output lists gps-orbit.gfflight, whose circle sits visibly off-centre around the grey mast disc, p-only.gfflight and flight.gfflight, the PI orbit hugging the mast at a constant distance. Move mapped onto the true position and the GPS orbit's error drops to the GPS noise; pass 0.4 instead of 0.15 as the PI orbit's ki and the first lap dips to 7.6 m before it settles.
TAKE THIS WITH YOU
An orbit around coordinates is only as good as the coordinates. Measure the structure instead: the shortest reading gives the bearing and the range, a radial PI loop on the range error plus a tangential speed holds the standoff, the integral supplies the inward command that turning and wind need, and per-lap statistics show whether the images will be consistent.
Check your understanding
An orbit around a mast's surveyed coordinates shows 8 m on the ground station, yet the images change scale around every lap. Why?
Go to the source
Progress stays in this browser. No account needed.