DovesLapTimer 4.3.0
GPS-based lap timing Arduino library — go-karts to race cars
Loading...
Searching...
No Matches
CrossingEngine Class Reference

#include <CrossingEngine.h>

+ Collaboration diagram for CrossingEngine:

Public Member Functions

 CrossingEngine (double crossingThresholdMeters=7, Stream *debugSerial=NULL)
 
LineDetectResult detect (double currentLat, double currentLng, unsigned long currentTimeMs, float currentOdometer, float currentSpeedKmh, const crossingPointBufferEntry *prevFix, double pointALat, double pointALng, double pointBLat, double pointBLng, bool &crossingFlag, int lineLabel, double &outLat, double &outLng, unsigned long &outTime, double &outOdometer)
 The crossing-zone state machine (formerly DovesLapTimer::_detectLineCrossing). Detects entry, buffers GPS fixes inside the zone, and interpolates the exact crossing point on exit.
 
bool getForceLinear () const
 
unsigned int getRejectedCrossingCount () const
 Number of crossing-zone exits whose interpolation was rejected.
 
void reset ()
 Clears the buffer, the rejected-crossing counter, and any in-flight zone state. Does NOT clear the configured threshold/mode.
 
void setDebugSerial (Stream *debugSerial)
 Attaches / detaches a debug output stream.
 
void setForceLinear (bool linear)
 Selects linear (true, default) or Catmull-Rom (false) position interpolation. Time and odometer are always interpolated linearly.
 
void setThreshold (double meters)
 Sets the crossing zone threshold, in meters.
 

Constructor & Destructor Documentation

◆ CrossingEngine()

CrossingEngine::CrossingEngine ( double  crossingThresholdMeters = 7,
Stream *  debugSerial = NULL 
)

Member Function Documentation

◆ detect()

LineDetectResult CrossingEngine::detect ( double  currentLat,
double  currentLng,
unsigned long  currentTimeMs,
float  currentOdometer,
float  currentSpeedKmh,
const crossingPointBufferEntry prevFix,
double  pointALat,
double  pointALng,
double  pointBLat,
double  pointBLng,
bool &  crossingFlag,
int  lineLabel,
double &  outLat,
double &  outLng,
unsigned long &  outTime,
double &  outOdometer 
)

The crossing-zone state machine (formerly DovesLapTimer::_detectLineCrossing). Detects entry, buffers GPS fixes inside the zone, and interpolates the exact crossing point on exit.

The caller owns the per-line in-zone flag and the vehicle state (current fix + previous-fix snapshot) — the engine owns only the buffer and the math.

Parameters
currentLat/ currentLng Current GPS position.
currentTimeMsMilliseconds since UTC midnight for this fix.
currentOdometerTotal odometer reading at this fix, meters.
currentSpeedKmhSpeed at this fix, km/h.
prevFixPrevious fix snapshot (Catmull-Rom pre-crossing point), or NULL if no previous fix exists yet.
pointALat/ pointALng Line endpoint A.
pointBLat/ pointBLng Line endpoint B.
crossingFlagReference to the caller-owned per-line in-zone flag.
lineLabelDebug label: 0 = start(/finish), 1 = sprint finish, 2 / 3 = sector.
[out]outLat/ outLng / outTime / outOdometer Interpolated crossing point — only valid when the return is LINE_DETECT_COMPLETED.
Returns
LINE_DETECT_NONE / IN_ZONE / COMPLETED. See enum docs.

Crossing-line detection: hypotenuse threshold method.

Using the width of the crossing line and "crossingThresholdMeters" to form a right triangle, the calculated hypotenuse is the effective proximity threshold. We measure from the driver to each crossing point; if either distance exceeds the hypotenuse we are not in the zone.

Earlier experiments used acute/obtuse-triangle detection (see DovesLapTimer::isObtuseTriangle), which worked on OKC but felt brittle. Hypotenuse-based threshold has been more reliable across short and long track configurations.

◆ getForceLinear()

bool CrossingEngine::getForceLinear ( ) const

◆ getRejectedCrossingCount()

unsigned int CrossingEngine::getRejectedCrossingCount ( ) const

Number of crossing-zone exits whose interpolation was rejected.

A rejection means the GPS data inside the zone never produced a usable straddling pair (no side change, pair too far from the line, incoherent timestamps, or crossing landing off the line segment).

◆ reset()

void CrossingEngine::reset ( )

Clears the buffer, the rejected-crossing counter, and any in-flight zone state. Does NOT clear the configured threshold/mode.

◆ setDebugSerial()

void CrossingEngine::setDebugSerial ( Stream *  debugSerial)

Attaches / detaches a debug output stream.

◆ setForceLinear()

void CrossingEngine::setForceLinear ( bool  linear)

Selects linear (true, default) or Catmull-Rom (false) position interpolation. Time and odometer are always interpolated linearly.

◆ setThreshold()

void CrossingEngine::setThreshold ( double  meters)

Sets the crossing zone threshold, in meters.


The documentation for this class was generated from the following files: