The business logic is split between two locations:
| Location | Purpose |
|---|---|
GPS/Classes/ |
Main application logic, state management, guidance |
AgOpenGPS.Core/Models/ |
Reusable models, geo conversions, helpers |
These classes manage application state and core operations:
File: Classes/CVehicle.cs
Purpose: Vehicle configuration and steering parameters
Key Properties:
// Dead zone settings
public int deadZoneHeading, deadZoneDelay;
public bool isInDeadZone;
// Speed limits
public double slowSpeedCutoff;
public double functionSpeedLimit;
public double maxSteerSpeed, minSteerSpeed;
// Steering gains
public double stanleyDistanceErrorGain;
public double stanleyHeadingErrorGain;
public double stanleyIntegralGainAB;
public double purePursuitIntegralGain;
// Lookahead parameters
public double goalPointLookAheadHold;
public double goalPointLookAheadMult;
public double goalPointAcquireFactor;
// Steering state
public bool isInFreeDriveMode;
public double driveFreeSteerAngle;
public double modeXTE, modeTime;Key Methods:
- Constructor loads settings from VehicleSettings and ToolSettings
UpdateGenreals()- Updates calculated steering parameters
File: Classes/CTool.cs
Purpose: Tool configuration and section management
Key Properties:
// Dimensions
public double width, halfWidth, overlap;
public double offset;
public double hitchLength;
// Trailing tool settings
public bool isToolTrailing, isToolTBT;
public bool isToolRearFixed, isToolFrontFixed;
public double trailingHitchLength;
public double tankTrailingHitchLength;
// Lookahead settings
public double lookAheadOnSetting;
public double lookAheadOffSetting;
public double turnOffDelay;
// Section configuration
public int numOfSections;
public int minCoverage;
public bool isSectionsNotZones;
public bool isSectionOffWhenOut;
// Zone support
public int zones;
public int[] zoneRanges;
// Colors
public Color[] secColors;Key Methods:
SetCurrentToolConfig()- Loads tool settings from ToolSettingsResetSectionPositions()- Resets section positionsUpdateSectionPositions()- Updates section positions based on width
File: Classes/CSection.cs
Purpose: Individual section control state
Key Properties:
// Section state
public bool isSectionOn;
public bool isSectionRequiredOn;
public bool sectionOnRequest, sectionOffRequest;
// Timers
public int sectionOnTimer, sectionOffTimer;
public int mappingOnTimer, mappingOffTimer;
// Position (meters from center, left is negative)
public double positionLeft = -4;
public double positionRight = 4;
public double sectionWidth;
// World space points
public vec2 leftPoint, rightPoint;
public vec2 lastLeftPoint, lastRightPoint;
// Location state
public bool isInBoundary;
public bool isInHeadlandArea;
public bool isLookOnInHeadland;
// Button state
public btnStates sectionBtnState;Key Methods:
SetSectionColors()- Sets section display colorsDrawSection()- Renders section in OpenGL
File: Classes/CGuidance.cs
Purpose: Steering angle calculation using Stanley or Pure Pursuit algorithms
Key Properties:
// Distance errors
public double distanceFromCurrentLineSteer;
public double distanceFromCurrentLinePivot;
public double steerAngleGu;
// Heading error
public double steerHeadingError;
public double distSteerError, lastDistSteerError;
public double derivativeDistError;
// Integral
public double inty;
// Side hill compensation
public double sideHillCompFactor;Key Methods:
DoSteerAngleCalc()- Stanley steering calculationPurePursuitSteerCalc()- Pure Pursuit steering calculationCalculateIntegral()- Integral term calculation
Stanley Algorithm:
// Cross-track error
double XTEc = Math.Atan((distanceFromCurrentLineSteer * stanleyDistanceErrorGain) / speed);
// Heading error
steerHeadingError *= stanleyHeadingErrorGain;
// Combined
steerAngleGu = (XTEc + steerHeadingError) * -1.0;File: Classes/CAHRS.cs
Purpose: IMU data and GPS/IMU fusion
Key Properties:
// Raw IMU data
public double imuHeading = 99999;
public double imuRoll = 0;
public double imuPitch = 0;
public double imuYawRate = 0;
// Roll zero offset
public double rollZero;
public double rollFilter;
// Settings
public bool isAutoSteerAuto;
public bool isRollInvert;
public bool isDualAsIMU;
public bool isReverseOn;
// Fusion parameters
public double forwardComp;
public double reverseComp;
public double fusionWeight;
// Auto-switch
public bool autoSwitchDualFixOn;
public double autoSwitchDualFixSpeed;Key Methods:
ResetAHRS()- Resets AHRS valuesSetHeading()- Sets fused heading from GPS/IMU
File: Classes/CABLine.cs
Purpose: AB line guidance calculations
Key Properties:
// AB line points
public vec3 currentLinePtA;
public vec3 currentLinePtB;
public double abHeading, abLength;
// Distance from line
public double distanceFromCurrentLinePivot;
public double distanceFromRefLine;
// Pure pursuit
public vec2 goalPointAB;
public vec2 radiusPointAB;
public double ppRadiusAB;
public double steerAngleAB;
// State
public bool isABValid;
public bool isMakingABLine;
public bool isHeadingSameWay;
// Design mode
public vec2 desPtA, desPtB;
public double desHeading;
public string desName;Key Methods:
CreateCurrentABLine()- Creates AB line from A and B pointsGetCurrentABLine()- Returns current AB line offset by path countResetABLines()- Clears all AB linesSnapABLine()- Snaps to existing AB line
File: Classes/CContour.cs
Purpose: Contour guidance calculations
Key Properties:
// Contour points
public List<vec3> ptList;
// Current contour
public vec2 goalPointCT;
public vec2 radiusPointCT;
public double steerAngleCT;
// State
public bool isContourValid;
public bool isContourOn;
public int currentIndex;Key Methods:
BuildContour()- Builds contour from recorded pointsGetCurrentContour()- Returns current contour pointSmoothContour()- Applies smoothing to contour
File: Classes/CTrack.cs
Purpose: Current guidance track state (combines AB Line, Contour, etc.)
Key Properties:
// Track type
public enum TrackType { None, ABLine, Curve, Contour }
// Current track state
public TrackType trackType;
public double distanceFromCurrentLine;
public double steerAngle;
// Guidance line
public vec2 goalPoint;
public vec2 radiusPoint;
// Mode
public int mode;
public bool isLocked;Key Methods:
UpdateTrack()- Updates track calculationsGetGoalPoint()- Returns goal point for guidanceGetSteerAngle()- Returns calculated steer angle
File: Classes/CYouTurn.cs
Purpose: Automatic U-turn generation at headlands
Key Properties:
// U-turn state
public bool isYouTurnTriggered;
public bool isTurnLeft;
public bool isYouTurnBtnOn;
// U-turn parameters
public double youTurnRadius;
public int youTurnStartOffset;
public int uTurnStyle;
public int rowSkipsWidth;
public int uTurnSmoothing;
// Generated path
public List<vec3> ytList;
public vec2 goalPointYT;
public vec2 radiusPointYT;
public double steerAngleYT;
// Turn validation
public bool isTurnCreationTooClose;
public bool isTurnCreationNotCrossingError;
public bool isOutOfBounds;Key Methods:
BuildYouTurnList()- Generates U-turn path pointsCalculateYouTurn()- Calculates U-turn steeringResetYouTurn()- Resets U-turn state
U-Turn Styles:
- 0: Basic U-turn
- 1: Wide U-turn
- 2: Y-turn
File: Classes/CModuleComm.cs
Purpose: Communication with steering modules
Key Properties:
// Safety
public bool isOutOfBounds;
// Section switch data (PGN 234)
public byte[] ss = new byte[9];
public int swHeader, swMain, swNumSections;
// Module feedback
public int pwmDisplay = 0;
public double actualSteerAngleDegrees = 0;
public int actualSteerAngleChart = 0;
public int sensorData = -1;
// Work switch
public bool isWorkSwitchActiveLow;
public bool isRemoteWorkSystemOn;
public bool workSwitchHigh, steerSwitchHigh;Key Methods:
CheckWorkAndSteerSwitch()- Handles work/steer switch input
File: Classes/CISOBUS.cs
Purpose: ISOBUS section control communication
Key Properties:
// Section control
private bool sectionControlEnabled;
private bool[] actualSectionStates;
// Process data
private int lastGuidanceLineDeviation;
private int lastActualSpeed;
private int lastTotalDistance;Key Methods:
RequestSectionControlEnabled(bool)- Request section controlSetGuidanceLineDeviation(int)- Send guidance deviationSetActualSpeed(int)- Send vehicle speedSetTotalDistance(int)- Send total distanceDeserializeHeartbeat(byte[])- Parse ISOBUS heartbeatIsAlive()- Check if ISOBUS connected (1s timeout)
File: Classes/CBoundary.cs, Classes/CBoundaryList.cs
Purpose: Boundary (geofence) definition and checking
Key Properties:
// Boundary points
public List<vec3> ptList;
// Area
public double area;
// State
public bool isBndBeingMade;
public bool isBndBeingViewed;Key Methods:
IsPointInsideBoundary(vec2)- Checks if point is insideCalculateArea()- Calculates boundary areaSmoothBoundary()- Applies Douglas-Peucker smoothing
File: Classes/CFence.cs
Purpose: Geofence logic for stopping guidance outside boundary
Key Properties:
// Fence state
public bool isAlright
public bool isOnInZone;
// Trigger points
public vec2 turnLineStart, turnLineEnd;Key Methods:
FenceCheck()- Checks if vehicle is in boundaryTurnOnDisableSections()- Turns off sections when outTurnOnEnableSections()- Turns on sections when in
File: Classes/CHead.cs
Purpose: Headland detection and section control
Key Properties:
// Headland state
public bool isInHeadland;
// Headland distance
public double distanceFromHeadland;Key Methods:
HeadlandCheck()- Checks if vehicle is in headland area
File: Classes/CNMEA.cs
Purpose: NMEA sentence parsing
Key Methods:
ParseGPGGA()- Parse GPGGA sentenceParseGPRMC()- Parse GPRMC sentenceParseGPVTG()- Parse GPVTG sentenceParseGPCHC()- Parse GPCHC (ComNav) sentence
File: Classes/CSim.cs
Purpose: Simulation mode for testing
Key Properties:
public double simLatitude;
public double simLongitude;
public double simHeading;
public double simSpeed;Key Methods:
UpdateSimulation()- Updates simulated position
File: Classes/CFieldData.cs
Purpose: Field save/load operations
Key Methods:
SaveField()- Saves field to fileLoadField()- Loads field from fileCreateFieldFile()- Creates new field file
File: Classes/CTram.cs
Purpose: Tramline management
Key Properties:
public List<vec3> tramList;
public double tramWidth;
public int passes;Key Methods:
BuildTram()- Generates tramlines from boundaryDrawTram()- Renders tramlines
File: Classes/CFlag.cs
Purpose: Flag/waypoint management
Key Properties:
public vec2 position;
public string notes;
public int ID;File: Classes/CRecordedPath.cs
Purpose: Recorded path storage
Key Properties:
public List<vec3> path;
public string name;File: Classes/CSettingsMigration.cs
Purpose: Migrates old single-file settings to new split format
Key Methods:
MigrateVehicle()- Migrates vehicle settingsMigrateTool()- Migrates tool settingsMigrateEnvironment()- Migrates environment settings
Purpose: Geographic coordinate with northing/easting
Key Properties:
public double Northing { get; set; }
public double Easting { get; set; }Purpose: WGS84 latitude/longitude coordinate
Key Properties:
public double Latitude { get; set; }
public double Longitude { get; set; }Purpose: Local plane projection for calculations
Key Methods:
ConvertWgs84ToGeoCoord()- Converts WGS84 to local easting/northingConvertGeoCoordToWgs84()- Converts local to WGS84
Purpose: Unit conversion utilities
Key Methods:
m2in()- Meters to inchesin2m()- Inches to meterskmh2mph()- km/h to mph
| Class | Purpose |
|---|---|
Field |
Field definition with name, directory |
Boundary |
Boundary data with point list |
TramLines |
Tramline storage |
Contour |
Contour data |
RecordedPath |
Recorded track data |
WorkedArea |
Worked area polygon |
Flag |
Flag/waypoint |
| Class | Purpose |
|---|---|
DubinsPathSelector |
Dubins path algorithm for smooth turns |
DubinsPathConstraints |
Path constraints (min radius, etc.) |
- Classes in GPS/:
Cprefix (e.g.,CSection) - Forms:
Formprefix (e.g.,FormGPS) - Core models: No prefix (e.g.,
GeoCoord)
Most classes hold a reference to the main form:
private readonly FormGPS mf;This provides access to:
mf.vehicle- CVehicle instancemf.tool- CTool instancemf.ahrs- CAHRS instancemf.trk- CTrack instancemf.pn- Position/Navigation data
Settings are accessed via static Default property:
Properties.VehicleSettings.Default.setVehicle_wheelbase = 3.3;
Properties.ToolSettings.Default.setVehicle_toolWidth = 4.0;
Properties.Settings.Default.setMenu_isMetric = true;FormGPS is split across multiple files:
FormGPS.cs- Main formUDPComm.Designer.cs- UDP communicationPGN.Designer.cs- PGN definitions- And many more partial class files
- Architecture - System architecture and component relationships
- Settings - Settings system and properties
- PGN Protocol - Communication protocol specification