nav

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NavLogState    = "state"
	NavLogWaypoint = "waypoint"
	NavLogAltitude = "altitude"
	NavLogSpeed    = "speed"
	NavLogHeading  = "heading"
	NavLogApproach = "approach"
	NavLogCommand  = "command"
	NavLogRoute    = "route"
	NavLogHold     = "hold"
)

Available logging categories

View Source
const MaxIAS = 290
View Source
const MaximumRate = 100000
View Source
const StandardTurnRate = 3

Variables

View Source
var (
	ErrClearedForUnexpectedApproach = errors.New("Cleared for unexpected approach")
	ErrFixIsTooFarAway              = errors.New("Fix is too far away")
	ErrFixNotInRoute                = errors.New("Fix not in aircraft's route")
	ErrInvalidApproach              = errors.New("Invalid approach")
	ErrInvalidFix                   = errors.New("Invalid fix")
	ErrNotClearedForApproach        = errors.New("Aircraft has not been cleared for an approach")
	ErrNotFlyingRoute               = errors.New("Aircraft is not currently flying its assigned route")
	ErrUnableCommand                = errors.New("Unable")
	ErrUnknownApproach              = errors.New("Unknown approach")
)

Errors used by the nav package

Functions

func InitNavLog

func InitNavLog(enabled bool, categories string, callsign string)

InitNavLog is a no-op in release builds

func LogRoute

func LogRoute(callsign string, simTime time.Time, waypoints av.WaypointArray)

LogRoute is a no-op in release builds

func NavLog(callsign string, simTime time.Time, category string, format string, args ...any)

NavLog is a no-op in release builds

func NavLogEnabled(category string) bool

NavLogEnabled always returns false in release builds

func TurnAngle

func TurnAngle(from, to math.MagneticHeading, turn av.TurnDirection) float32

Types

type DeferredNavHeading

type DeferredNavHeading struct {
	Time    time.Time
	Heading *math.MagneticHeading
	Turn    *av.TurnDirection
	Hold    *FlyHold
	// For direct fix, this will be the updated set of waypoints.
	Waypoints []av.Waypoint
}

DeferredNavHeading stores a heading assignment from the controller and the time at which to start executing it; this time is set to be a few seconds after the controller issues it in order to model the delay before pilots start to follow assignments.

type DepartureHeadingState added in v0.14.0

type DepartureHeadingState int

DepartureHeadingState describes the state of a departure's heading assignment.

const (
	// NoHeading indicates no heading is assigned or upcoming
	NoHeading DepartureHeadingState = iota
	// OnHeading indicates the aircraft is currently flying an assigned heading
	OnHeading
	// TurningToHeading indicates the aircraft is about to turn to a heading
	TurningToHeading
)

type FlightState

type FlightState struct {
	IsArrival                 bool
	InitialDepartureClimb     bool
	DepartureAirportLocation  math.Point2LL
	DepartureAirportElevation float32
	ArrivalAirport            av.Waypoint
	ArrivalAirportLocation    math.Point2LL
	ArrivalAirportElevation   float32

	MagneticVariation float32
	NmPerLongitude    float32

	Position     math.Point2LL
	Heading      math.MagneticHeading
	Altitude     float32
	PrevAltitude float32
	IAS, GS      float32 // speeds...
	BankAngle    float32 // degrees
	AltitudeRate float32 // + -> climb, - -> descent
}

func (FlightState) LogValue

func (fs FlightState) LogValue() slog.Value

func (*FlightState) Summary

func (fs *FlightState) Summary() string

type FlyHold

type FlyHold struct {
	Hold         av.Hold
	FixLocation  math.Point2LL
	State        HoldState
	LegStartTime time.Time
	LegStartPos  math.Point2LL
	Entry        av.HoldEntry
	Cancel       bool // when set, we end the hold after the last leg
}

func (*FlyHold) GetHeading

func (fh *FlyHold) GetHeading(callsign string, nav *Nav, wxs wx.Sample, simTime time.Time) (math.MagneticHeading, av.TurnDirection, float32)

type HoldState

type HoldState int
const (
	// Everyone starts here and then transitions to one of the next three groups depending on their entry method.
	HoldStateApproaching HoldState = iota

	HoldStateDirectTurningInitialOutbound

	HoldStateTurningForParallelEntry
	HoldStateFlyingParallelOutbound
	HoldStateTurningParallelInbound

	HoldStateFlyingTeardropOutbound
	HoldStateTurningForTeardropEntry

	// All holds cycle through these once after entry.
	HoldStateTurningOutbound
	HoldStateFlyingOutbound
	HoldStateTurningInbound
	HoldStateFlyingInbound
)

func (HoldState) String

func (s HoldState) String() string

type HoldStateFunc

type HoldStateFunc func(nav *Nav, fh *FlyHold, wxs wx.Sample, simTime time.Time) (math.MagneticHeading, av.TurnDirection, HoldState)

Holds are implemented using a simple state machine where each state is handled by a function with this signature. Return values: heading to fly, which direction to turn, and which state to be in for the next step.

type InterceptState

type InterceptState int
const (
	NotIntercepting InterceptState = iota
	InitialHeading
	TurningToJoin
	OnApproachCourse
)

type LateralManeuver added in v0.14.2

type LateralManeuver struct {
	Heading        math.MagneticHeading // heading to fly
	Track          math.MagneticHeading // if non-zero, wind-corrected heading via headingForTrack
	FlyToward      math.Point2LL        // if non-zero, heading = bearing to this point each tick
	Turn           av.TurnDirection
	Until          ManeuverComplete
	AssignAltitude *float32 // if non-nil, set nav.Altitude when this maneuver becomes active
}

LateralManeuver describes a single phase of flight: fly a heading until a condition is met. A sequence of LateralManeuvers forms a procedure turn or hold circuit.

func (*LateralManeuver) String added in v0.14.2

func (m *LateralManeuver) String() string

type ManeuverComplete added in v0.14.2

type ManeuverComplete struct {
	Type    ManeuverCompleteType
	Heading math.MagneticHeading // target heading (UntilHeading)
	Seconds float32              // duration in seconds (UntilTime)
	Dist    float32              // distance in nm (UntilDist)
	Fix     math.Point2LL        // target fix (UntilFix, UntilIntercept)

	// UntilIntercept: inbound course to intercept and turn direction for the intercept turn.
	InterceptCourse math.MagneticHeading
	InterceptTurn   av.TurnDirection

	// Lazy-init start state for time/distance conditions.
	Start    time.Time     // captured on first Done() call (UntilTime)
	StartPos math.Point2LL // captured on first Done() call (UntilDist)
}

ManeuverComplete encapsulates the completion condition for a lateral maneuver. Type selects the condition; the relevant field(s) provide its parameters. Time and distance conditions capture their start state lazily on first check.

func (*ManeuverComplete) Done added in v0.14.2

func (mc *ManeuverComplete) Done(nav *Nav, simTime time.Time, wxs wx.Sample, targetHdg math.MagneticHeading) bool

type ManeuverCompleteType added in v0.14.2

type ManeuverCompleteType int

ManeuverCompleteType discriminates the four completion conditions.

const (
	UntilHeading                ManeuverCompleteType = iota // done when aircraft heading ≈ Until.Heading
	UntilTime                                               // done after Until.Seconds elapsed (lazy start)
	UntilDist                                               // done after Until.Dist nm flown (lazy start)
	UntilFix                                                // done when ETA to Until.Fix < 2s
	UntilIntercept                                          // done when shouldTurnToIntercept fires for course through Fix
	UntilControllerIntervention                             // never completes; lasts until controller issues a new instruction
)
type Nav struct {
	FlightState FlightState
	Perf        av.AircraftPerformance
	Altitude    NavAltitude
	Speed       NavSpeed
	Heading     NavHeading
	Approach    NavApproach
	Airwork     *NavAirwork
	Prespawn    bool

	FixAssignments map[string]NavFixAssignment

	// DeferredNavHeading stores a heading/direct fix assignment from the
	// controller that the pilot has not yet started to follow.  Note that
	// only a single such assignment is stored; for example, if the
	// controller issues a first heading and then a second shortly
	// afterward, before the first has been followed, it's fine for the
	// second to override it.
	DeferredNavHeading *DeferredNavHeading

	// ExpectedDirectFix records a fix the pilot has been told to expect
	// direct to; when the actual direct instruction comes, there is less
	// delay since the pilot is prepared.
	ExpectedDirectFix string

	FinalAltitude float32
	Waypoints     av.WaypointArray

	Rand *rand.Rand
}

State related to navigation. Pointers are used for optional values; nil -> unset/unspecified.

func MakeArrivalNav

func MakeArrivalNav(callsign av.ADSBCallsign, arr *av.Arrival, fp av.FlightPlan, perf av.AircraftPerformance,
	nmPerLongitude float32, magneticVariation float32, model *wx.Model, simTime time.Time, lg *log.Logger) *Nav

func MakeDepartureNav

func MakeDepartureNav(callsign av.ADSBCallsign, fp av.FlightPlan, perf av.AircraftPerformance,
	assignedAlt, clearedAlt, speedRestriction int, wp []av.Waypoint, randomizeAltitudeRange bool,
	nmPerLongitude float32, magneticVariation float32, model *wx.Model, simTime time.Time, lg *log.Logger) *Nav

func MakeOverflightNav

func MakeOverflightNav(callsign av.ADSBCallsign, of *av.Overflight, fp av.FlightPlan, perf av.AircraftPerformance,
	nmPerLongitude float32, magneticVariation float32, model *wx.Model, simTime time.Time, lg *log.Logger) *Nav
func (nav *Nav) AltitudeOurDiscretion() av.CommandIntent
func (nav *Nav) ApproachHeading(callsign string, wxs wx.Sample, simTime time.Time) (heading math.MagneticHeading, turn av.TurnDirection)
func (nav *Nav) AssignAltitude(alt float32, afterSpeed bool) av.CommandIntent
func (nav *Nav) AssignHeading(hdg math.MagneticHeading, turn av.TurnDirection, simTime time.Time) av.CommandIntent
func (nav *Nav) AssignMach(mach float32, afterAltitude bool, temp av.Temperature) av.CommandIntent
func (nav *Nav) AssignSpeed(speed float32, afterAltitude bool) av.CommandIntent
func (nav *Nav) AssignSpeedUntil(speed float32, until *av.SpeedUntil) av.CommandIntent
func (nav *Nav) AssignedHeading() (math.MagneticHeading, bool)

AssignedHeading returns the aircraft's current heading assignment, if any, regardless of whether the pilot has yet started following it.

func (nav *Nav) AssignedWaypoints() []av.Waypoint

AssignedWaypoints returns the route that should be flown following a controller instruction. If an instruction has been issued but the delay hasn't passed, these are different than the waypoints currently being used for navigation.

func (nav *Nav) AtFixCleared(fix, id string) av.CommandIntent
func (nav *Nav) AtFixIntercept(fix, airport string, lg *log.Logger) av.CommandIntent
func (nav *Nav) CancelApproachClearance() av.CommandIntent
func (nav *Nav) Check(lg *log.Logger)
func (nav *Nav) ClearedApproach(airport string, id string, straightIn bool, simTime time.Time) (av.CommandIntent, bool)
func (nav *Nav) ClimbViaSID(simTime time.Time) av.CommandIntent
func (nav *Nav) ContactMessage(reportingPoints []av.ReportingPoint, star string, runway string,
	reportHeading bool, isDeparture bool) *av.RadioTransmission
func (nav *Nav) CrossFixAt(fix string, ar *av.AltitudeRestriction, speed int, mach float32) av.CommandIntent
func (nav *Nav) DepartFixDirect(fixa string, fixb string) av.CommandIntent
func (nav *Nav) DepartFixHeading(fix string, hdg math.MagneticHeading) av.CommandIntent
func (nav *Nav) DepartOnCourse(alt float32, exit string, simTime time.Time)
func (nav *Nav) DepartureHeading() (int, DepartureHeadingState)

DepartureHeading returns the heading a departure will fly and its state. Returns the heading and state based on: - OnHeading: aircraft has an assigned heading - TurningToHeading: first waypoint has a heading (about to turn) - NoHeading: no assigned heading and first waypoint has no heading

func (nav *Nav) DepartureMessage(sid string, reportHeading bool) *av.RadioTransmission
func (nav *Nav) DescendViaSTAR(simTime time.Time) av.CommandIntent
func (nav *Nav) DirectFix(fix string, turn av.TurnDirection, simTime time.Time) av.CommandIntent
func (nav *Nav) DistanceAlongRoute(fix string) (float32, error)
func (nav *Nav) DistanceToEndOfApproach() (float32, error)

distanceToEndOfApproach returns the remaining distance to the last waypoint (usually runway threshold) of the currently assigned approach.

func (nav *Nav) DivertToAirport(airport string)
func (nav *Nav) ETA(p math.Point2LL) float32

ETA returns the estimated time in seconds until the aircraft will arrive at `p`, assuming it is flying direct.

func (nav *Nav) EnqueueDirectFix(wps []av.Waypoint, turn av.TurnDirection, simTime time.Time)
func (nav *Nav) EnqueueHeading(hdg math.MagneticHeading, turn av.TurnDirection, approachCleared bool, simTime time.Time)

EnqueueHeading enqueues the given heading assignment to be followed a few seconds in the future. It should only be called for heading changes due to controller instructions to the pilot and never in cases where the autopilot is changing the heading assignment.

func (nav *Nav) EnqueueOnCourse(simTime time.Time)
func (nav *Nav) ExpectApproach(airport *av.Airport, id string, runwayWaypoints map[string]av.WaypointArray,
	lahsoRunway string, lg *log.Logger) av.CommandIntent
func (nav *Nav) ExpectDirect(fix string) av.CommandIntent
func (nav *Nav) ExpediteClimb() av.CommandIntent
func (nav *Nav) ExpediteDescent() av.CommandIntent
func (nav *Nav) FlyPresentHeading(simTime time.Time) av.CommandIntent
func (nav *Nav) GoAroundWithProcedure(altitude float32, runwayEndWP av.Waypoint)

GoAroundWithProcedure initiates a go-around with a defined procedure. The runwayEndWP waypoint should have Location (opposite threshold), FlyOver, Heading (outbound), AltitudeRestriction, and GoAroundContactController set.

func (nav *Nav) HoldAtFix(callsign string, fix string, hold *av.Hold) av.CommandIntent
func (nav *Nav) InterceptApproach(airport string, lg *log.Logger) av.CommandIntent
func (nav *Nav) InterceptedButNotCleared() bool
func (nav *Nav) IsAirborne() bool
func (nav *Nav) Mach(temp av.Temperature) float32
func (nav *Nav) MaintainMaximumForward() av.CommandIntent
func (nav *Nav) MaintainPresentSpeed() av.CommandIntent
func (nav *Nav) MaintainSlowestPractical() av.CommandIntent
func (nav *Nav) OnApproach(checkAltitude bool) bool
func (nav *Nav) OnExtendedCenterline(maxNmDeviation float32) bool

OnExtendedCenterline checks if the flight position is less than maxNmDeviation from the infinite line defined by the assigned approach localizer

func (nav *Nav) RestoreSnapshot(snap NavSnapshot)

RestoreSnapshot restores nav state from a previously captured snapshot. The aircraft's physical state (FlightState) is NOT restored - only control assignments.

func (nav *Nav) ResumeOwnNavigation() av.CommandIntent
func (nav *Nav) SayAltitude() av.CommandIntent
func (nav *Nav) SayHeading() av.CommandIntent
func (nav *Nav) SayIndicatedSpeed() av.CommandIntent
func (nav *Nav) SayMach(temp av.Temperature) av.CommandIntent
func (nav *Nav) SaySpeed(temp av.Temperature) av.CommandIntent
func (nav *Nav) Summary(fp av.FlightPlan, model *wx.Model, simTime time.Time, lg *log.Logger) string

Full human-readable summary of nav state for use when paused and mouse hover on the scope

func (nav *Nav) TAS(temp av.Temperature) float32
func (nav *Nav) TakeSnapshot() NavSnapshot

TakeSnapshot captures the current controller-modifiable nav state for later rollback.

func (nav *Nav) TargetAltitude() (float32, float32, bool)

TargetAltitude returns the target altitude, the rate to use (ft/min), and whether the descent is geometric (following a computed glidepath to a fix).

func (nav *Nav) TargetHeading(callsign string, wxs wx.Sample, simTime time.Time) (heading math.MagneticHeading, turn av.TurnDirection, rate float32)
func (nav *Nav) TargetSpeed(targetAltitude float32, fp *av.FlightPlan, wxs wx.Sample, bravo *av.AirspaceGrid) (float32, float32)
func (nav *Nav) Update(callsign string, model *wx.Model, fp *av.FlightPlan, simTime time.Time, bravo *av.AirspaceGrid) *av.Waypoint

returns passed waypoint if any

func (nav *Nav) UpdateWithWeather(callsign string, wxs wx.Sample, fp *av.FlightPlan, simTime time.Time, bravo *av.AirspaceGrid) *av.Waypoint

UpdateWithWeather is a helper for simulations that use pre-fetched weather

type NavAirwork struct {
	Radius   float32
	Center   math.Point2LL
	AltRange [2]float32

	RemainingSteps  int
	NextMoveCounter int
	Heading         math.MagneticHeading
	TurnRate        float32
	TurnDirection   av.TurnDirection
	IAS             float32
	Altitude        float32
	Dive            bool
	ToCenter        bool
}

func StartAirwork

func StartAirwork(wp av.Waypoint, nav Nav) *NavAirwork
func (aw *NavAirwork) Start360(nav Nav)
func (aw *NavAirwork) TargetAltitude() (float32, float32, bool)
func (aw *NavAirwork) TargetHeading() (math.MagneticHeading, av.TurnDirection, float32)
func (aw *NavAirwork) TargetSpeed() (float32, float32, bool)
func (aw *NavAirwork) Update(nav *Nav) bool
type NavAltitude struct {
	Assigned           *float32 // controller assigned
	Cleared            *float32 // from initial clearance
	AfterSpeed         *float32
	AfterSpeedSpeed    *float32
	Expedite           bool
	ExpediteAfterSpeed bool

	// Carried after passing a waypoint if we were unable to meet the
	// restriction at the way point; we keep trying until we get there (or
	// are given another instruction..)
	Restriction *av.AltitudeRestriction
}
type NavApproach struct {
	Assigned                    *av.Approach
	AssignedId                  string
	ATPAVolume                  *av.ATPAVolume
	Cleared                     bool
	StandbyApproach             bool // suppress repeated approach clearance requests
	RequestApproachClearance    bool // pilot should radio for approach clearance
	GoAroundNoApproachClearance bool // pilot should go around (reached FAF without clearance)
	InterceptState              InterceptState
	PassedApproachFix           bool // have we passed a fix on the approach yet?
	PassedFAF                   bool
	NoPT                        bool
	AtFixClearedRoute           []av.Waypoint
	AtFixInterceptFix           string // fix where aircraft should intercept the localizer
}
type NavFixAssignment struct {
	Arrive struct {
		Altitude *av.AltitudeRestriction
		Speed    *float32
		Mach     *float32
	}
	Depart struct {
		Fix     *av.Waypoint
		Heading *math.MagneticHeading
		Turn    *av.TurnDirection
	}
	Hold *av.Hold
}
type NavHeading struct {
	Assigned   *math.MagneticHeading
	Turn       *av.TurnDirection
	Arc        *av.DMEArc
	JoiningArc bool
	Maneuvers  []LateralManeuver
	Hold       *FlyHold
}
type NavSnapshot struct {
	Altitude           NavAltitude
	Speed              NavSpeed
	Heading            NavHeading
	Approach           NavApproach
	Waypoints          av.WaypointArray
	DeferredNavHeading *DeferredNavHeading
	FixAssignments     map[string]NavFixAssignment
}

NavSnapshot captures all controller-modifiable state in Nav for rollback purposes. It does NOT include FlightState (aircraft physical position/heading/altitude) - only control assignments that can be rolled back.

type NavSpeed struct {
	Assigned                 *float32
	AfterAltitude            *float32
	AfterAltitudeAltitude    *float32
	MaintainSlowestPractical bool
	MaintainMaximumForward   bool
	// Carried after passing a waypoint
	Restriction *float32
	Mach        bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL