|
DovesLapTimer 4.0.0
GPS-based lap timing Arduino library — go-karts to race cars
|
#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. | |
| DovesLapTimer::DovesLapTimer | ( | double | crossingThresholdMeters = 7, |
| Stream * | debugSerial = NULL |
||
| ) |
| bool DovesLapTimer::areSectorLinesConfigured | ( | ) | const |
Checks if sector lines are configured.
| 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).
| 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
| float DovesLapTimer::getBestLapDistance | ( | ) | const |
Gets the best lap distance.
| int DovesLapTimer::getBestLapNumber | ( | ) | const |
Gets the best lap number.
| unsigned long DovesLapTimer::getBestLapTime | ( | ) | const |
Gets the best lap time.
| int DovesLapTimer::getBestSector1LapNumber | ( | ) | const |
Gets the lap number that achieved the best sector 1 time.
| unsigned long DovesLapTimer::getBestSector1Time | ( | ) | const |
Gets the best sector 1 time.
| int DovesLapTimer::getBestSector2LapNumber | ( | ) | const |
Gets the lap number that achieved the best sector 2 time.
| unsigned long DovesLapTimer::getBestSector2Time | ( | ) | const |
Gets the best sector 2 time.
| int DovesLapTimer::getBestSector3LapNumber | ( | ) | const |
Gets the lap number that achieved the best sector 3 time.
| unsigned long DovesLapTimer::getBestSector3Time | ( | ) | const |
Gets the best sector 3 time.
| bool DovesLapTimer::getCrossing | ( | ) | const |
Gets the crossing status.
| float DovesLapTimer::getCurrentLapDistance | ( | ) | const |
Gets the current lap distance.
| float DovesLapTimer::getCurrentLapOdometerStart | ( | ) | const |
Gets the current lap odometer start.
| unsigned long DovesLapTimer::getCurrentLapSector1Time | ( | ) | const |
Gets the current lap sector 1 time.
| unsigned long DovesLapTimer::getCurrentLapSector2Time | ( | ) | const |
Gets the current lap sector 2 time.
| unsigned long DovesLapTimer::getCurrentLapSector3Time | ( | ) | const |
Gets the current lap sector 3 time.
| unsigned long DovesLapTimer::getCurrentLapStartTime | ( | ) | const |
Gets the current lap start time.
| unsigned long DovesLapTimer::getCurrentLapTime | ( | ) | const |
Gets the current lap time.
| int DovesLapTimer::getCurrentSector | ( | ) | const |
Gets the current sector the driver is in.
| int DovesLapTimer::getDirection | ( | ) | const |
Gets the detected driving direction.
| int DovesLapTimer::getLaps | ( | ) | const |
Gets the total number of laps completed.
| float DovesLapTimer::getLastLapDistance | ( | ) | const |
Gets the last lap distance.
| unsigned long DovesLapTimer::getLastLapTime | ( | ) | const |
Gets the last lap time.
| unsigned long DovesLapTimer::getOptimalLapTime | ( | ) | const |
Gets the optimal lap time calculated from best sector times.
| 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.
| bool DovesLapTimer::getRaceStarted | ( | ) | const |
Gets the race started status (passed the line one time).
| float DovesLapTimer::getTotalDistanceTraveled | ( | ) | const |
Gets the total distance traveled.
| 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.
| lat1 | Latitude of the first point in decimal degrees |
| lon1 | Longitude of the first point in decimal degrees |
| lat2 | Latitude of the second point in decimal degrees |
| lon2 | Longitude of the second point in decimal degrees |
| 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.
| prevLat | Latitude of the first GPS point in decimal degrees. |
| prevLng | Longitude of the first GPS point in decimal degrees. |
| prevAlt | Altitude of the first GPS point in meters. |
| currentLat | Latitude of the second GPS point in decimal degrees. |
| currentLng | Longitude of the second GPS point in decimal degrees. |
| currentAlt | Altitude of the second GPS point in meters. |
| 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.
| driverLat | Latitude of the driver's position. |
| driverLon | Longitude of the driver's position. |
| crossingPointALat | Latitude of crossing point A. |
| crossingPointALon | Longitude of crossing point A. |
| crossingPointBLat | Latitude of crossing point B. |
| crossingPointBLon | Longitude of crossing point B. |
| bool DovesLapTimer::isDirectionResolved | ( | ) | const |
Checks if the driving direction has been resolved.
| 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.
| lat1 | Latitude of the first point |
| lon1 | Longitude of the first point |
| lat2 | Latitude of the second point |
| lon2 | Longitude of the second point |
| lat3 | Latitude of the third point |
| lon3 | Longitude of the third point |
| 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!!!!!!
| currentLat | Latitude of the current position in decimal degrees. |
| currentLng | Longitude of the current position in decimal degrees. |
| currentAltitudeMeters | Altitude of the current position in meters. |
| currentSpeedKnots | The current speed in knots |
| 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).
| pointX | The x-coordinate of the point. |
| pointY | The y-coordinate of the point. |
| startX | The x-coordinate of the first endpoint of the line segment. |
| startY | The y-coordinate of the first endpoint of the line segment. |
| endX | The x-coordinate of the second endpoint of the line segment. |
| endY | The y-coordinate of the second endpoint of the line segment. |
| 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.
| driverLat | The latitude of the point's position. |
| driverLng | The longitude of the point's position. |
| pointALat | The latitude of the first point of the line. |
| pointALng | The longitude of the first point of the line. |
| pointBLat | The latitude of the second point of the line. |
| pointBLng | The longitude of the second point of the line. |
| void DovesLapTimer::reset | ( | ) |
Reset all parameters back to 0.
| void DovesLapTimer::setSector2Line | ( | double | pointALat, |
| double | pointALng, | ||
| double | pointBLat, | ||
| double | pointBLng | ||
| ) |
Sets the sector 2 line using two points (A and B).
| pointALat | Latitude of point A in decimal degrees. |
| pointALng | Longitude of point A in decimal degrees. |
| pointBLat | Latitude of point B in decimal degrees. |
| pointBLng | Longitude of point B in decimal degrees. |
| void DovesLapTimer::setSector3Line | ( | double | pointALat, |
| double | pointALng, | ||
| double | pointBLat, | ||
| double | pointBLng | ||
| ) |
Sets the sector 3 line using two points (A and B).
| pointALat | Latitude of point A in decimal degrees. |
| pointALng | Longitude of point A in decimal degrees. |
| pointBLat | Latitude of point B in decimal degrees. |
| pointBLng | Longitude of point B in decimal degrees. |
| void DovesLapTimer::setStartFinishLine | ( | double | pointALat, |
| double | pointALng, | ||
| double | pointBLat, | ||
| double | pointBLng | ||
| ) |
Sets the start/finish line using two points (A and B).
| pointALat | Latitude of point A in decimal degrees. |
| pointALng | Longitude of point A in decimal degrees. |
| pointBLat | Latitude of point B in decimal degrees. |
| pointBLng | Longitude of point B in decimal degrees. |
| void DovesLapTimer::updateCurrentTime | ( | unsigned long | currentTimeMilliseconds | ) |
Updates the current GPS time since midnight.
| currentTimeMilliseconds | The current time in milliseconds. |