igc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package igc provides means to parse and analyse files in the IGC format.

This format is defined by the International Gliding Commission (IGC) and was created to set a standard for recording gliding flights.

The full specification is available in Appendix A of the IGC FR Specification: http://www.fai.org/component/phocadownload/category/?download=11005

Calculation of the optimal flight distance considering multiple turnpoints and FAI triangles are available via Optimizers. Available Optimizers include brute force, montecarlo method, genetic algorithms, etc.

Copyright The ezgliding Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Example (Optimize)

Calculate the optimal track distance for the multiple possible tasks using the Brute Force Optimizer:

track, _ := ParseLocation("sample-flight.igc")

// In this case we use a brute force optimizer
o := NewBruteForceOptimizer(false)
r, _ := o.Optimize(track, 1, Distance)
fmt.Printf("Optimization result was: %v", r)
Output:

Example (Parse)

Parse and ParseLocation return a Track object.

// We can parse passing a file location
track, _ := ParseLocation("sample-flight.igc")

// Or similarly giving directly the contents
contents := `
AFLA001Some Additional Data
HFDTE010203
HFFXA500
HFPLTPilotincharge:EZ PILOT
	`
track, _ = Parse(contents)

// Accessing track metadata
fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Parsecontent)

Parse directly flight contents and get a Track object.

// We could pass here a string with the full contents in IGC format
track, _ := Parse(`
AFLA001Some Additional Data
HFDTE010203
HFFXA500
HFPLTPilotincharge:EZ PILOT
	`)

fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Parselocation)

Parse a given file and get a Track object.

track, _ := ParseLocation("sample-flight.igc")

fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Totaldistance)

Calculate the total track distance using the Points.

This is not a very useful metric (you should look at one of the Optimizers) instead, but it is a good example of how to use the Point data in the Track.

track, _ := ParseLocation("sample-flight.igc")
totalDistance := 0.0
for i := 0; i < len(track.Points)-1; i++ {
	totalDistance += track.Points[i].Distance(track.Points[i+1])
}
fmt.Printf("Distance was %v", totalDistance)
Output:

Index

Examples

Constants

View Source
const (
	// TimeFormat is the golang time.Parse format for IGC time.
	TimeFormat = "150405"
	// DateFormat is the golang time.Parse format for IGC time.
	DateFormat = "020106"
)
View Source
const (
	// MinTurnRate is the min rate to consider circling
	MinTurnRate = 6.5
	// MaxTurnRate is the max rate considered for valid turns
	MaxTurnRate = 22.5
	// MinCirclingTime is used to decide when a switch to circling occurs.
	// This value is used when calculating flight phases to switch from
	// PossibleCircling to Circling.
	MinCirclingTime = 15
	// MinCruisingTime is used to decide when a switch to cruising occurs.
	// This value is used when calculating flight phases to switch from
	// PossibleCruising to Cruising.
	MinCruisingTime = 10
)
View Source
const (
	// EarthRadius is the average earth radius.
	EarthRadius = 6371.0
)
View Source
const MaxSpeed float64 = 500.0

MaxSpeed is the maximum theoretical speed for a glider.

It is used to detect bad GPS coordinates, which should be removed from the track.

Variables

View Source
var Manufacturers = map[string]Manufacturer{
	"GCS": {'A', "GCS", "Garrecht"},
	"LGS": {'B', "LGS", "Logstream"},
	"CAM": {'C', "CAM", "Cambridge Aero Instruments"},
	"DSX": {'D', "DSX", "Data Swan/DSX"},
	"EWA": {'E', "EWA", "EW Avionics"},
	"FIL": {'F', "FIL", "Filser"},
	"FLA": {'G', "FLA", "Flarm (Track Alarm)"},
	"SCH": {'H', "SCH", "Scheffel"},
	"ACT": {'I', "ACT", "Aircotec"},
	"CNI": {'K', "CNI", "ClearNav Instruments"},
	"NKL": {'K', "NKL", "NKL"},
	"LXN": {'L', "LXN", "LX Navigation"},
	"IMI": {'M', "IMI", "IMI Gliding Equipment"},
	"NTE": {'N', "NTE", "New Technologies s.r.l."},
	"NAV": {'O', "NAV", "Naviter"},
	"PES": {'P', "PES", "Peschges"},
	"PRT": {'R', "PRT", "Print Technik"},
	"SDI": {'S', "SDI", "Streamline Data Instruments"},
	"TRI": {'T', "TRI", "Triadis Engineering GmbH"},
	"LXV": {'V', "LXV", "LXNAV d.o.o."},
	"WES": {'W', "WES", "Westerboer"},
	"XCS": {' ', "XCS", "XCSoar"},
	"XYY": {'X', "XYY", "Other manufacturer"},
	"ZAN": {'Z', "ZAN", "Zander"},
}

Manufacturers holds the list of available manufacturers.

This list is defined in the IGC specification, section A2.5.6.

Functions

func DecimalFromDMD

func DecimalFromDMD(dmd string) float64

DecimalFromDMD returns the decimal representation (in radians) of the given DMD.

DMD is a representation of a coordinate in Decimal,Minutes,100thMinute with an extra character indicating north, south, east, west.

Examples: N512688, W0064364, S342212, E0021275

func DecimalFromDMS

func DecimalFromDMS(dms string) float64

DecimalFromDMS returns the decimal representation (in radians) of the given DMS.

DMS is a representation of a coordinate in Decimal,Minutes,Seconds, with an extra character indicating north, south, east, west.

Examples: N512646, W0064312, S342244, E0021233

func Distance

func Distance(task Task) float64

Distance returns the sum of distances between each of the points in the Task.

The sum is made calculating the distances between each two consecutive Points.

Types

type CirclingType added in v0.3.0

type CirclingType int

CirclingType indicates Left, Right or Mixed circling.

const (
	Mixed CirclingType = 0
	Left  CirclingType = 1
	Right CirclingType = 2
)

type Crawler added in v0.4.0

type Crawler interface {
	Crawl(time.Time, time.Time) ([]Flight, error)
}

type Event

type Event struct {
	Time time.Time
	Type string
	Data string
}

Event holds data records triggered at a given time.

This is the E record in the IGC specification, section A4.2. The events can be pilot initiated (with a PEV code), proximity alerts, etc.

type Flight added in v0.4.0

type Flight struct {
	URL            string
	ID             string
	Pilot          string
	Club           string
	Date           time.Time
	Takeoff        string
	Region         string
	Country        string
	Distance       float64
	Points         float64
	Glider         string
	Type           string
	TrackURL       string
	TrackID        string
	CompetitionID  string
	CompetitionURL string
	Speed          float64
	Comments       string
}

Flight represents a flight submission in an online competition.

It includes all the flight metadata available in the online competition, including computed data like speed or distance. It also includes a url to the flight track file (usually in IGC format).

type FlightID added in v0.4.0

type FlightID string
type Header struct {
	Manufacturer      string
	UniqueID          string
	AdditionalData    string
	Date              time.Time
	Site              string
	FixAccuracy       int64
	Pilot             string
	PilotBirth        time.Time
	Crew              string
	GliderType        string
	GliderID          string
	Observation       string
	GPSDatum          string
	FirmwareVersion   string
	HardwareVersion   string
	SoftwareVersion   string // for non-igc flight recorders
	Specification     string
	FlightRecorder    string
	GPS               string
	GNSSModel         string
	PressureModel     string
	PressureSensor    string
	AltimeterPressure float64
	CompetitionID     string
	CompetitionClass  string
	Timezone          int
	MOPSensor         string
}

Header holds the meta information of a track.

This is the H record in the IGC specification, section A3.2.

type K

type K struct {
	Time   time.Time
	Fields map[string]string
}

K holds flight data needed less often than Points.

This is the K record in the IGC specification, section A4.4. Fields is a map between a given content type and its value, with the possible content types being defined in the J record.

Examples of content types include heading true (HDT) or magnetic (HDM), airspeed (IAS), etc.

type Manufacturer

type Manufacturer struct {
	// contains filtered or unexported fields
}

Manufacturer holds manufacturer name, short ID and char identifier.

The list of manufacturers is defined in the IGC specification, section A2.5.6. A map Manufacturers is available in this library.

type Optimizer

type Optimizer interface {
	Optimize(track Track, nPoints int, score Score) (Task, error)
}

Optimizer returns an optimal Task for the given turnpoints and Score function.

Available score functions include MaxDistance and MaxPoints, but it is possible to pass the Optimizer a custom function.

Optimizers might not support a high number of turnpoints. As an example, the BruteForceOptimizer does not perform well with nPoints > 2, and might decide to return an error instead of attempting to finalize the optimization indefinitely.

func NewBruteForceOptimizer

func NewBruteForceOptimizer(cache bool) Optimizer

NewBruteForceOptimizer returns a BruteForceOptimizer with the given characteristics.

type Phase added in v0.3.0

type Phase struct {
	Type         PhaseType
	CirclingType CirclingType
	Start        Point
	StartIndex   int
	End          Point
	EndIndex     int
	AvgVario     float64
	TopVario     float64
	AvgGndSpeed  float64
	TopGndSpeed  float64
	Distance     float64
	LD           float64
	Centroid     s2.LatLng
	CellID       s2.CellID
}

Phase is a flight phase (towing, cruising, circling).

func (*Phase) Duration added in v0.3.0

func (p *Phase) Duration() time.Duration

Duration returns the duration of this flight phase.

type PhaseType added in v0.3.0

type PhaseType int

PhaseType represents a flight phase.

Possible values include Towing, PossibleCruising/Cruising, PossibleCircling/Circling, Unknown.

const (
	Unknown          PhaseType = 0
	Towing           PhaseType = 1
	PossibleCruising PhaseType = 2
	Cruising         PhaseType = 3
	PossibleCircling PhaseType = 4
	Circling         PhaseType = 5
)

type Point

type Point struct {
	s2.LatLng
	Time             time.Time
	FixValidity      byte
	PressureAltitude int64
	GNSSAltitude     int64
	IData            map[string]string
	NumSatellites    int
	Description      string
	// contains filtered or unexported fields
}

Point represents a GPS recording (single point in the track).

It is based on a golang-geo s2 LatLng, adding extra metadata such as the Time the point was recorded, pressure and GNSS altitude, number of satellites available and extra metadata added by the recorder.

You can use all methods available for a s2.LatLng on this struct.

func NewPoint

func NewPoint() Point

NewPoint returns a new Point set to latitude and longitude 0.

func NewPointFromDMD

func NewPointFromDMD(lat string, lng string) Point

NewPointFromDMD returns a Point corresponding to the given string in DMD format.

DecimalFromDMD includes more information regarding this format.

func NewPointFromDMS

func NewPointFromDMS(lat string, lng string) Point

NewPointFromDMS returns a Point corresponding to the given string in DMS format.

DecimalFromDMS includes more information regarding this format.

func NewPointFromLatLng

func NewPointFromLatLng(lat float64, lng float64) Point

NewPointFromLatLng returns a new Point with the given latitude and longitude.

func (*Point) Bearing added in v0.3.0

func (p *Point) Bearing(b Point) s1.Angle

Bearing returns the bearing to the given point in degrees.

func (*Point) Distance

func (p *Point) Distance(b Point) float64

Distance returns the great circle distance in kms to the given point.

Internally it uses the golang-geo s2 LatLng.Distance() method, but converts its result (an angle) to kms considering the constant EarthRadius.

func (*Point) Speed

func (p *Point) Speed(b Point) float64

Speed returns the distance/time to the given point in km/h.

type Satellite

type Satellite struct {
	Time time.Time
	Ids  []string
}

Satellite holds the IDs of the available satellites at a given Time.

This is the F record in the IGC specification, section A4.3.

type Score

type Score func(task Task) float64

Score functions calculate a score for the given Task.

The main use of these functions is in passing them to the Optimizers, so they can evaluate each Task towards different goals.

Example functions include the total distance between all turn points or an online competition (netcoupe, online contest) score which takes additional metrics of each leg into account.

type Task

type Task struct {
	DeclarationDate time.Time
	Date            time.Time
	Number          int
	Takeoff         Point
	Start           Point
	Turnpoints      []Point
	Finish          Point
	Landing         Point
	Description     string
}

Task holds all the metadata put in a pre-declared task to be performed.

This is the C record in the IGC specification, section A3.5.

func (*Task) Distance

func (task *Task) Distance() float64

Distance returns the total distance in kms between the turn points.

It includes the Start and Finish fields as the first and last point, respectively, with the Turnpoints in the middle. The return value is sum of all distances between each consecutive point.

type Track

type Track struct {
	Header
	ID            string
	Points        []Point
	K             []K
	Events        []Event
	Satellites    []Satellite
	Logbook       []string
	Task          Task
	DGPSStationID string
	Signature     string
	// contains filtered or unexported fields
}

Track holds all IGC flight data (header and GPS points).

func NewTrack

func NewTrack() Track

NewTrack returns a new instance of Track, with fields initialized to zero.

func Parse

func Parse(content string) (Track, error)

Parse returns a Track object corresponding to the given content.

The value of content should be a text string with all the flight data in the IGC format.

func ParseClean

func ParseClean(content string) (Track, error)

ParseClean returns a cleaned up Track object.

See Parse().

func ParseCleanLocation

func ParseCleanLocation(location string) (Track, error)

ParseCleanLocation returns a cleaned up Track object.

See ParseLocation().

func ParseLocation

func ParseLocation(location string) (Track, error)

ParseLocation returns a Track object corresponding to the given file.

It calls Parse internatlly, so the file content should be in IGC format.

func (*Track) Cleanup

func (track *Track) Cleanup() (Track, error)

func (*Track) Encode added in v0.3.0

func (track *Track) Encode(format string) ([]byte, error)

func (*Track) EncodePhases added in v0.3.0

func (track *Track) EncodePhases(format string) ([]byte, error)

func (*Track) Phases added in v0.3.0

func (track *Track) Phases() ([]Phase, error)

Phases returns the list of flight phases for the Track. Each phases is one of Cruising, Circling, Towing or Unknown.

func (*Track) Simplify

func (track *Track) Simplify(tolerance float64) (Track, error)

Jump to

Keyboard shortcuts

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