func (tello *Tello) CancelAutoFlyToXY() {
	tello.autoXYMu.Lock()
	tello.autoXY = false
	tello.autoXYMu.Unlock()
}
CancelAutoFlyToXY stops any in-flight AutoFlyToXY navigation.
The drone should stop.
package tello
import (
	"errors"
	"log"
	"math"
	"time"
)
const (
	autopilotPeriodMs  = keepAlivePeriodMs * 2  
	autoPilotSpeedFast = 32767
	autoPilotSpeedSlow = 16384
	AutoHeightLimitDm = 300
	AutoXYLimitM = 200  
	AutoXYToleranceM = 0.3
	AutoXYNearTargetM = 3.0
)
func (tello *Tello) CancelAutoFlyToHeight() {
	tello.autoHeightMu.Lock()
	tello.autoHeight = false
	tello.autoHeightMu.Unlock()
}
func (tello *Tello) AutoFlyToHeight(dm int16) (done chan bool, err error) {
	if dm > AutoHeightLimitDm || dm < -AutoHeightLimitDm {
		return nil, errors.New("Verical navigation limit exceeded")
	}
	tello.autoHeightMu.RLock()
	if tello.autoHeight {
		tello.autoHeightMu.RUnlock()
		return nil, errors.New("Already navigating vertically")
	}
	tello.autoHeightMu.RUnlock()
	tello.autoHeightMu.Lock()
	tello.autoHeight = true
	tello.autoHeightMu.Unlock()
	done = make(chan bool, 1)  
	go func() {
		for {
			tello.autoHeightMu.RLock()
			autoH := tello.autoHeight
			tello.autoHeightMu.RUnlock()
			if !autoH {
				tello.ctrlMu.Lock()
				tello.ctrlLy = 0
				tello.ctrlMu.Unlock()
				tello.sendStickUpdate()
				done <- true
				return
			}
			tello.fdMu.RLock()
			delta := dm - tello.fd.Height  
			tello.fdMu.RUnlock()
			tello.ctrlMu.Lock()
			switch {
			case delta > 4:
				tello.ctrlLy = autoPilotSpeedFast  
			case delta > 0:
				tello.ctrlLy = autoPilotSpeedSlow  
			case delta < -4:
				tello.ctrlLy = -autoPilotSpeedFast
			case delta < 0:
				tello.ctrlLy = -autoPilotSpeedSlow
			case delta == 0:  
				tello.autoHeightMu.Lock()
				tello.autoHeight = false
				tello.autoHeightMu.Unlock()
			}
			tello.ctrlMu.Unlock()
			time.Sleep(autopilotPeriodMs * time.Millisecond)
		}
	}()
	return done, nil
}
func (tello *Tello) CancelAutoTurn() {
	tello.autoYawMu.Lock()
	tello.autoYaw = false
	tello.autoYawMu.Unlock()
}
func (tello *Tello) AutoTurnToYaw(targetYaw int16) (done chan bool, err error) {
	if targetYaw < -180 || targetYaw > 180 {
		return nil, errors.New("Target yaw must be between -180 and +180")
	}
	adjustedTarget := targetYaw
	if targetYaw < 0 {
		adjustedTarget = 360 + targetYaw
	}
	tello.autoYawMu.RLock()
	if tello.autoYaw {
		tello.autoYawMu.RUnlock()
		return nil, errors.New("Already navigating rotationally")
	}
	tello.autoYawMu.RUnlock()
	tello.autoYawMu.Lock()
	tello.autoYaw = true
	tello.autoYawMu.Unlock()
	done = make(chan bool, 1)  
	go func() {
		for {
			tello.autoYawMu.RLock()
			autoY := tello.autoYaw
			tello.autoYawMu.RUnlock()
			if !autoY {
				log.Println("Cancelled")
				tello.ctrlMu.Lock()
				tello.ctrlLx = 0
				tello.ctrlMu.Unlock()
				tello.sendStickUpdate()
				done <- true
				return
			}
			tello.fdMu.RLock()
			adjustedCurrent := tello.fd.IMU.Yaw
			tello.fdMu.RUnlock()
			if adjustedCurrent < 0 {
				adjustedCurrent = 360 + adjustedCurrent
			}
			delta := adjustedTarget - adjustedCurrent
			absDelta := int16Abs(delta)
			switch {
			case absDelta <= 180:  
			case delta > 0:
				delta = absDelta - 360
			case delta > 0:
				delta = 360 - absDelta
			}
			tello.ctrlMu.Lock()
			switch {
			case delta > 10:
				tello.ctrlLx = autoPilotSpeedFast
			case delta > 0:
				tello.ctrlLx = autoPilotSpeedSlow
			case delta < -10:
				tello.ctrlLx = -autoPilotSpeedFast
			case delta < 0:
				tello.ctrlLx = -autoPilotSpeedSlow
			case delta == 0:  
				tello.autoYawMu.Lock()
				tello.autoYaw = false
				tello.autoYawMu.Unlock()
			}
			tello.ctrlMu.Unlock()
			time.Sleep(autopilotPeriodMs * time.Millisecond)
		}
	}()
	return done, nil
}
func (tello *Tello) IsAutoTurning() (set bool) {
	tello.autoYawMu.RLock()
	set = tello.autoYaw
	tello.autoYawMu.RUnlock()
	return set
}
func (tello *Tello) AutoTurnByDeg(delta int16) (done chan bool, err error) {
	if delta < -180 || delta > 180 {
		return nil, errors.New("Turn amount must be between -180 and +180")
	}
	if tello.IsAutoTurning() {
		return nil, errors.New("Already navigating rotationally")
	}
	tello.fdMu.RLock()
	adjustedTarget := tello.fd.IMU.Yaw
	tello.fdMu.RUnlock()
	adjustedTarget += delta
	switch {
	case adjustedTarget == 360:
		adjustedTarget = 0
	case adjustedTarget > 180:
		adjustedTarget = -(360 - adjustedTarget)
	case adjustedTarget < -180:
		adjustedTarget = 360 + adjustedTarget
	}
	return tello.AutoTurnToYaw(adjustedTarget)
}
func (tello *Tello) SetHome() (err error) {
	tello.autoXYMu.RLock()
	alreadyAuto := tello.autoXY
	tello.autoXYMu.RUnlock()
	if alreadyAuto {
		return errors.New("Cannot set origin during automatic flight")
	}
	tello.autoXYMu.Lock()
	tello.autoXY = false
	tello.fdMu.RLock()
	tello.homeX = tello.fd.MVO.PositionX
	tello.homeY = tello.fd.MVO.PositionY
	tello.homeYaw = tello.fd.IMU.Yaw
	tello.fdMu.RUnlock()
	if tello.homeYaw < 0 {
		tello.homeYaw += 360
	}
	tello.homeValid = true
	tello.autoXYMu.Unlock()
	return nil
}
func (tello *Tello) IsHomeSet() (set bool) {
	tello.autoXYMu.RLock()
	set = tello.homeValid
	tello.autoXYMu.RUnlock()
	return set
}