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

#include <DovesLapTimer.h>

+ Collaboration diagram for DovesLapTimer:

Public Member Functions

bool areSectorLinesConfigured () const
 Checks if sector lines are configured.
 
 DovesLapTimer (double crossingThresholdMeters=7, Stream *debugSerial=NULL)
 
void forceCatmullRomInterpolation ()
 Forces Catmull-Rom spline interpolation when checking crossing line.
 
void forceLinearInterpolation ()
 forces linear interpolation when checking crossing line
 
float getBestLapDistance () const
 Gets the best lap distance.
 
int getBestLapNumber () const
 Gets the best lap number.
 
unsigned long getBestLapTime () const
 Gets the best lap time.
 
int getBestSector1LapNumber () const
 Gets the lap number that achieved the best sector 1 time.
 
unsigned long getBestSector1Time () const
 Gets the best sector 1 time.
 
int getBestSector2LapNumber () const
 Gets the lap number that achieved the best sector 2 time.
 
unsigned long getBestSector2Time () const
 Gets the best sector 2 time.
 
int getBestSector3LapNumber () const
 Gets the lap number that achieved the best sector 3 time.
 
unsigned long getBestSector3Time () const
 Gets the best sector 3 time.
 
bool getCrossing () const
 Gets the crossing status.
 
float getCurrentLapDistance () const
 Gets the current lap distance.
 
float getCurrentLapOdometerStart () const
 Gets the current lap odometer start.
 
unsigned long getCurrentLapSector1Time () const
 Gets the current lap sector 1 time.
 
unsigned long getCurrentLapSector2Time () const
 Gets the current lap sector 2 time.
 
unsigned long getCurrentLapSector3Time () const
 Gets the current lap sector 3 time.
 
unsigned long getCurrentLapStartTime () const
 Gets the current lap start time.
 
unsigned long getCurrentLapTime () const
 Gets the current lap time.
 
int getCurrentSector () const
 Gets the current sector the driver is in.
 
int getDirection () const
 Gets the detected driving direction.
 
int getLaps () const
 Gets the total number of laps completed.
 
float getLastLapDistance () const
 Gets the last lap distance.
 
unsigned long getLastLapTime () const
 Gets the last lap time.
 
unsigned long getOptimalLapTime () const
 Gets the optimal lap time calculated from best sector times.
 
float getPaceDifference () const
 Calculates the pace difference between the current lap and the best lap in milliseconds.
 
bool getRaceStarted () const
 Gets the race started status (passed the line one time).
 
float getTotalDistanceTraveled () const
 Gets the total distance traveled.
 
double haversine (double lat1, double lon1, double lat2, double lon2)
 Calculates the great-circle distance between two points on the Earth's surface using the Haversine formula.
 
double haversine3D (double prevLat, double prevLng, double prevAlt, double currentLat, double currentLng, double currentAlt)
 Calculates the distance between two GPS points, including altitude difference.
 
bool insideLineThreshold (double driverLat, double driverLon, double crossingPointALat, double crossingPointALon, double crossingPointBLat, double crossingPointBLon)
 Check if a driver is within a threshold distance of the line formed by the two crossing points.
 
bool isDirectionResolved () const
 Checks if the driving direction has been resolved.
 
bool isObtuseTriangle (double lat1, double lon1, double lat2, double lon2, double lat3, double lon3)
 Checks if the triangle formed by the given coordinates is an obtuse triangle.
 
int loop (double currentLat, double currentLng, float currentAltitudeMeters, float currentSpeedKnots)
 Updates a few internal stats and then checks the status of crossing a line.
 
double pointLineSegmentDistance (double pointX, double pointY, double startX, double startY, double endX, double endY)
 Calculate the shortest distance between a point and a line segment.
 
int pointOnSideOfLine (double driverLat, double driverLng, double pointALat, double pointALng, double pointBLat, double pointBLng)
 Determines which side of a line a driver is on.
 
void reset ()
 Reset all parameters back to 0.
 
void setSector2Line (double pointALat, double pointALng, double pointBLat, double pointBLng)
 Sets the sector 2 line using two points (A and B).
 
void setSector3Line (double pointALat, double pointALng, double pointBLat, double pointBLng)
 Sets the sector 3 line using two points (A and B).
 
void setStartFinishLine (double pointALat, double pointALng, double pointBLat, double pointBLng)
 Sets the start/finish line using two points (A and B).
 
void updateCurrentTime (unsigned long currentTimeMilliseconds)
 Updates the current GPS time since midnight.
 

Constructor & Destructor Documentation

◆ DovesLapTimer()

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

Member Function Documentation

◆ areSectorLinesConfigured()

bool DovesLapTimer::areSectorLinesConfigured ( ) const

Checks if sector lines are configured.

Returns
True if both sector 2 and sector 3 lines are configured, false otherwise.

◆ forceCatmullRomInterpolation()

void DovesLapTimer::forceCatmullRomInterpolation ( )

Forces Catmull-Rom spline interpolation when checking crossing line.

Catmull-Rom interpolation uses 4 control points to create a smooth curve, which can provide more accurate crossing time calculation when the vehicle path curves near the line. Falls back to linear interpolation automatically if insufficient control points are available (crossing detected too early in the buffer).

◆ forceLinearInterpolation()

void DovesLapTimer::forceLinearInterpolation ( )

forces linear interpolation when checking crossing line

Might maybe be more accurate if your track(s) finishline is on a straight or other location you expect constant speed

◆ getBestLapDistance()

float DovesLapTimer::getBestLapDistance ( ) const

Gets the best lap distance.

Returns
The distance traveled during the best lap in meters.

◆ getBestLapNumber()

int DovesLapTimer::getBestLapNumber ( ) const

Gets the best lap number.

Returns
The lap number of the best lap.

◆ getBestLapTime()

unsigned long DovesLapTimer::getBestLapTime ( ) const

Gets the best lap time.

Returns
The best lap time in milliseconds.

◆ getBestSector1LapNumber()

int DovesLapTimer::getBestSector1LapNumber ( ) const

Gets the lap number that achieved the best sector 1 time.

Returns
The lap number, or 0 if no valid sector 1 time recorded.

◆ getBestSector1Time()

unsigned long DovesLapTimer::getBestSector1Time ( ) const

Gets the best sector 1 time.

Returns
The best sector 1 time in milliseconds, or 0 if no valid sector 1 time recorded.

◆ getBestSector2LapNumber()

int DovesLapTimer::getBestSector2LapNumber ( ) const

Gets the lap number that achieved the best sector 2 time.

Returns
The lap number, or 0 if no valid sector 2 time recorded.

◆ getBestSector2Time()

unsigned long DovesLapTimer::getBestSector2Time ( ) const

Gets the best sector 2 time.

Returns
The best sector 2 time in milliseconds, or 0 if no valid sector 2 time recorded.

◆ getBestSector3LapNumber()

int DovesLapTimer::getBestSector3LapNumber ( ) const

Gets the lap number that achieved the best sector 3 time.

Returns
The lap number, or 0 if no valid sector 3 time recorded.

◆ getBestSector3Time()

unsigned long DovesLapTimer::getBestSector3Time ( ) const

Gets the best sector 3 time.

Returns
The best sector 3 time in milliseconds, or 0 if no valid sector 3 time recorded.

◆ getCrossing()

bool DovesLapTimer::getCrossing ( ) const

Gets the crossing status.

Returns
True if crossing the start/finish line, false otherwise.

◆ getCurrentLapDistance()

float DovesLapTimer::getCurrentLapDistance ( ) const

Gets the current lap distance.

Returns
The distance traveled during the current lap in meters.

◆ getCurrentLapOdometerStart()

float DovesLapTimer::getCurrentLapOdometerStart ( ) const

Gets the current lap odometer start.

Returns
The distance traveled at the start of the current lap in meters.

◆ getCurrentLapSector1Time()

unsigned long DovesLapTimer::getCurrentLapSector1Time ( ) const

Gets the current lap sector 1 time.

Returns
The current lap sector 1 time in milliseconds, or 0 if sector 1 not yet completed.

◆ getCurrentLapSector2Time()

unsigned long DovesLapTimer::getCurrentLapSector2Time ( ) const

Gets the current lap sector 2 time.

Returns
The current lap sector 2 time in milliseconds, or 0 if sector 2 not yet completed.

◆ getCurrentLapSector3Time()

unsigned long DovesLapTimer::getCurrentLapSector3Time ( ) const

Gets the current lap sector 3 time.

Returns
The current lap sector 3 time in milliseconds, or 0 if sector 3 not yet completed.

◆ getCurrentLapStartTime()

unsigned long DovesLapTimer::getCurrentLapStartTime ( ) const

Gets the current lap start time.

Returns
The current lap start time in milliseconds.

◆ getCurrentLapTime()

unsigned long DovesLapTimer::getCurrentLapTime ( ) const

Gets the current lap time.

Returns
The current lap time in milliseconds.

◆ getCurrentSector()

int DovesLapTimer::getCurrentSector ( ) const

Gets the current sector the driver is in.

Returns
0 if race not started, 1/2/3 for current sector.

◆ getDirection()

int DovesLapTimer::getDirection ( ) const

Gets the detected driving direction.

Returns
DIR_UNKNOWN (0), DIR_FORWARD (1), or DIR_REVERSE (2).

◆ getLaps()

int DovesLapTimer::getLaps ( ) const

Gets the total number of laps completed.

Returns
The total number of laps completed.

◆ getLastLapDistance()

float DovesLapTimer::getLastLapDistance ( ) const

Gets the last lap distance.

Returns
The distance traveled during the last lap in meters.

◆ getLastLapTime()

unsigned long DovesLapTimer::getLastLapTime ( ) const

Gets the last lap time.

Returns
The last lap time in milliseconds.

◆ getOptimalLapTime()

unsigned long DovesLapTimer::getOptimalLapTime ( ) const

Gets the optimal lap time calculated from best sector times.

Returns
The sum of best sector 1, 2, and 3 times in milliseconds, or 0 if sectors not configured.

◆ getPaceDifference()

float DovesLapTimer::getPaceDifference ( ) const

Calculates the pace difference between the current lap and the best lap in milliseconds.

This function computes the pace for both the current lap and the best lap, and returns the difference. A positive value indicates that the current lap's pace is slower than the best lap's pace, while a negative value indicates that the current lap's pace is faster.

◆ getRaceStarted()

bool DovesLapTimer::getRaceStarted ( ) const

Gets the race started status (passed the line one time).

Returns
True if the race has started, false otherwise.

◆ getTotalDistanceTraveled()

float DovesLapTimer::getTotalDistanceTraveled ( ) const

Gets the total distance traveled.

Returns
The total distance traveled in meters.

◆ haversine()

double DovesLapTimer::haversine ( double  lat1,
double  lon1,
double  lat2,
double  lon2 
)

Calculates the great-circle distance between two points on the Earth's surface using the Haversine formula.

This function takes the latitude and longitude of two points in decimal degrees and returns the distance between them in meters. The Haversine formula is used to account for the Earth's curvature, providing accurate results for relatively short distances (up to a few thousand kilometers).

Note: This function assumes that the Earth is a perfect sphere with a radius of 6,371 kilometers.

Parameters
lat1Latitude of the first point in decimal degrees
lon1Longitude of the first point in decimal degrees
lat2Latitude of the second point in decimal degrees
lon2Longitude of the second point in decimal degrees
Returns
double The great-circle distance between the two points in meters

◆ haversine3D()

double DovesLapTimer::haversine3D ( double  prevLat,
double  prevLng,
double  prevAlt,
double  currentLat,
double  currentLng,
double  currentAlt 
)

Calculates the distance between two GPS points, including altitude difference.

This function computes the distance between two GPS points using the haversine formula, and takes into account the altitude difference between the points. The resulting distance is the true 3D distance between the points, rather than just the 2D distance on the Earth's surface.

Parameters
prevLatLatitude of the first GPS point in decimal degrees.
prevLngLongitude of the first GPS point in decimal degrees.
prevAltAltitude of the first GPS point in meters.
currentLatLatitude of the second GPS point in decimal degrees.
currentLngLongitude of the second GPS point in decimal degrees.
currentAltAltitude of the second GPS point in meters.
Returns
The 3D distance between the two GPS points in meters.

◆ insideLineThreshold()

bool DovesLapTimer::insideLineThreshold ( double  driverLat,
double  driverLon,
double  crossingPointALat,
double  crossingPointALon,
double  crossingPointBLat,
double  crossingPointBLon 
)

Check if a driver is within a threshold distance of the line formed by the two crossing points.

This function checks whether the driver is within a threshold distance from the line formed by crossing points A and B. The threshold is defined by crossingThresholdMeters.

Parameters
driverLatLatitude of the driver's position.
driverLonLongitude of the driver's position.
crossingPointALatLatitude of crossing point A.
crossingPointALonLongitude of crossing point A.
crossingPointBLatLatitude of crossing point B.
crossingPointBLonLongitude of crossing point B.
Returns
True if the driver is within the threshold distance, otherwise False.

◆ isDirectionResolved()

bool DovesLapTimer::isDirectionResolved ( ) const

Checks if the driving direction has been resolved.

Returns
True if direction is known (forward or reverse), false if still unknown.

◆ isObtuseTriangle()

bool DovesLapTimer::isObtuseTriangle ( double  lat1,
double  lon1,
double  lat2,
double  lon2,
double  lat3,
double  lon3 
)

Checks if the triangle formed by the given coordinates is an obtuse triangle.

Parameters
lat1Latitude of the first point
lon1Longitude of the first point
lat2Latitude of the second point
lon2Longitude of the second point
lat3Latitude of the third point
lon3Longitude of the third point
Returns
true if the triangle is an obtuse triangle, false otherwise

◆ loop()

int DovesLapTimer::loop ( double  currentLat,
double  currentLng,
float  currentAltitudeMeters,
float  currentSpeedKnots 
)

Updates a few internal stats and then checks the status of crossing a line.

This should be run every time the GPS is fixed and gets a new location is aquired! All of the magic happens here!!!!!!

Parameters
currentLatLatitude of the current position in decimal degrees.
currentLngLongitude of the current position in decimal degrees.
currentAltitudeMetersAltitude of the current position in meters.
currentSpeedKnotsThe current speed in knots

◆ pointLineSegmentDistance()

double DovesLapTimer::pointLineSegmentDistance ( double  pointX,
double  pointY,
double  startX,
double  startY,
double  endX,
double  endY 
)

Calculate the shortest distance between a point and a line segment.

This function takes the coordinates of a point (pointX, pointY) and a line segment defined by two endpoints (startX, startY) and (endX, endY), and returns the shortest distance between the point and the line segment. The distance is calculated in the same unit as the input coordinates (e.g., degrees for latitude and longitude values).

Parameters
pointXThe x-coordinate of the point.
pointYThe y-coordinate of the point.
startXThe x-coordinate of the first endpoint of the line segment.
startYThe y-coordinate of the first endpoint of the line segment.
endXThe x-coordinate of the second endpoint of the line segment.
endYThe y-coordinate of the second endpoint of the line segment.
Returns
The shortest distance between the point and the line segment.

◆ pointOnSideOfLine()

int DovesLapTimer::pointOnSideOfLine ( double  driverLat,
double  driverLng,
double  pointALat,
double  pointALng,
double  pointBLat,
double  pointBLng 
)

Determines which side of a line a driver is on.

Given a point's position and two points defining a line segment, this function computes the side of the line the point is on. The line is treated as infinite for the side determination.

Parameters
driverLatThe latitude of the point's position.
driverLngThe longitude of the point's position.
pointALatThe latitude of the first point of the line.
pointALngThe longitude of the first point of the line.
pointBLatThe latitude of the second point of the line.
pointBLngThe longitude of the second point of the line.
Returns
Returns 1 if the point is on one side of the line, -1 if the point is on the other side, and 0 if the point is exactly on the line.

◆ reset()

void DovesLapTimer::reset ( )

Reset all parameters back to 0.

◆ setSector2Line()

void DovesLapTimer::setSector2Line ( double  pointALat,
double  pointALng,
double  pointBLat,
double  pointBLng 
)

Sets the sector 2 line using two points (A and B).

Parameters
pointALatLatitude of point A in decimal degrees.
pointALngLongitude of point A in decimal degrees.
pointBLatLatitude of point B in decimal degrees.
pointBLngLongitude of point B in decimal degrees.

◆ setSector3Line()

void DovesLapTimer::setSector3Line ( double  pointALat,
double  pointALng,
double  pointBLat,
double  pointBLng 
)

Sets the sector 3 line using two points (A and B).

Parameters
pointALatLatitude of point A in decimal degrees.
pointALngLongitude of point A in decimal degrees.
pointBLatLatitude of point B in decimal degrees.
pointBLngLongitude of point B in decimal degrees.

◆ setStartFinishLine()

void DovesLapTimer::setStartFinishLine ( double  pointALat,
double  pointALng,
double  pointBLat,
double  pointBLng 
)

Sets the start/finish line using two points (A and B).

Parameters
pointALatLatitude of point A in decimal degrees.
pointALngLongitude of point A in decimal degrees.
pointBLatLatitude of point B in decimal degrees.
pointBLngLongitude of point B in decimal degrees.

◆ updateCurrentTime()

void DovesLapTimer::updateCurrentTime ( unsigned long  currentTimeMilliseconds)

Updates the current GPS time since midnight.

Parameters
currentTimeMillisecondsThe current time in milliseconds.

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