DovesLapTimer 4.0.0
GPS-based lap timing Arduino library — go-karts to race cars
Loading...
Searching...
No Matches
WaypointLapTimer.h
Go to the documentation of this file.
1
16#ifndef _WAYPOINT_LAP_TIMER_H
17#define _WAYPOINT_LAP_TIMER_H
18
19#include <Arduino.h>
20#include "DovesLapTimer.h"
21#include "GeoMath.h"
22
23// Internal states
24#define WLT_STATE_IDLE 0
25#define WLT_STATE_WAITING_SPEED 1
26#define WLT_STATE_DRIVING 2
27#define WLT_STATE_IN_PROXIMITY 3
28
30 double lat;
31 double lng;
32 unsigned long time;
33 float odometer;
35};
36
38public:
39 WaypointLapTimer(Stream *debugSerial = NULL);
40
41 void updateCurrentTime(unsigned long currentTimeMilliseconds);
42 int loop(double currentLat, double currentLng, float currentAltitudeMeters, float currentSpeedKnots);
43 void reset();
44 void setSpeedThresholdMph(float mph);
45 void setProximityMeters(float meters);
46
47 // Timing getters (duck-typed to DovesLapTimer)
48 bool getRaceStarted() const;
49 bool getCrossing() const;
50 int getLaps() const;
51 unsigned long getCurrentLapTime() const;
52 unsigned long getLastLapTime() const;
53 unsigned long getBestLapTime() const;
54 float getCurrentLapDistance() const;
55 float getTotalDistanceTraveled() const;
56 int getBestLapNumber() const;
57 float getPaceDifference() const;
58
59 float getLastLapDistance() const;
60 float getBestLapDistance() const;
61
62 // Waypoint access
63 bool hasWaypoint() const;
64 double getWaypointLat() const;
65 double getWaypointLng() const;
66
67 // Sector getters (not supported, return 0)
68 int getCurrentSector() const { return 0; }
69 bool areSectorLinesConfigured() const { return false; }
70 unsigned long getCurrentLapSector1Time() const { return 0; }
71 unsigned long getCurrentLapSector2Time() const { return 0; }
72 unsigned long getCurrentLapSector3Time() const { return 0; }
73 unsigned long getBestSector1Time() const { return 0; }
74 unsigned long getBestSector2Time() const { return 0; }
75 unsigned long getBestSector3Time() const { return 0; }
76 unsigned long getOptimalLapTime() const { return 0; }
77 int getBestSector1LapNumber() const { return 0; }
78 int getBestSector2LapNumber() const { return 0; }
79 int getBestSector3LapNumber() const { return 0; }
80
81 // Direction (not applicable)
82 int getDirection() const { return DIR_UNKNOWN; }
83 bool isDirectionResolved() const { return false; }
84
85private:
86 template<typename... Args>
87 void debug_print(Args&&... args) {
88 if(_serial) { _serial->print(std::forward<Args>(args)...); }
89 }
90 template<typename... Args>
91 void debug_println(Args&&... args) {
92 if(_serial) { _serial->println(std::forward<Args>(args)...); }
93 }
94
95 void _resetState();
96 void _checkSpeed(double lat, double lng);
97 void _checkProximity(double lat, double lng);
98 void _bufferProximityPoint(double lat, double lng);
99 void _clearProximityBuffer();
100 void _processProximityBuffer();
101
102 Stream *_serial;
103
104 int _state;
105 unsigned long _millisecondsSinceMidnight;
106
107 // Waypoint
108 double _waypointLat;
109 double _waypointLng;
110 float _waypointOdometer;
111
112 // Odometer / position
113 float _totalDistanceTraveled;
114 double _positionPrevLat;
115 double _positionPrevLng;
116 bool _firstPositionReceived;
117 float _currentSpeedKmh;
118 float _speedThresholdMph;
119 float _proximityMeters;
120
121 // Timing
122 bool _raceStarted;
123 bool _crossing;
124 unsigned long _currentLapStartTime;
125 unsigned long _lastLapTime;
126 unsigned long _bestLapTime;
127 float _currentLapOdometerStart;
128 float _lastLapDistance;
129 float _bestLapDistance;
130 int _bestLapNumber;
131 int _laps;
132
133 // Proximity buffer
135 int _proximityBufferIndex;
136 int _proximityBufferCount;
137 float _closestDist;
138 unsigned long _closestTime;
139 float _closestOdometer;
140};
141
142#endif
#define DIR_UNKNOWN
Definition DovesLapTimer.h:33
#define WAYPOINT_LAP_BUFFER_SIZE
Definition DovesLapTimer.h:30
void loop()
Definition basic_oled_example.ino:116
Definition WaypointLapTimer.h:37
bool areSectorLinesConfigured() const
Definition WaypointLapTimer.h:69
float getTotalDistanceTraveled() const
Definition WaypointLapTimer.cpp:258
double getWaypointLat() const
Definition WaypointLapTimer.cpp:291
unsigned long getBestSector2Time() const
Definition WaypointLapTimer.h:74
void reset()
Definition WaypointLapTimer.cpp:87
bool isDirectionResolved() const
Definition WaypointLapTimer.h:83
int getCurrentSector() const
Definition WaypointLapTimer.h:68
void setSpeedThresholdMph(float mph)
Definition WaypointLapTimer.cpp:91
unsigned long getCurrentLapTime() const
Definition WaypointLapTimer.cpp:238
unsigned long getBestSector1Time() const
Definition WaypointLapTimer.h:73
int getBestLapNumber() const
Definition WaypointLapTimer.cpp:262
int getBestSector2LapNumber() const
Definition WaypointLapTimer.h:78
int getDirection() const
Definition WaypointLapTimer.h:82
void updateCurrentTime(unsigned long currentTimeMilliseconds)
Definition WaypointLapTimer.cpp:50
int getBestSector3LapNumber() const
Definition WaypointLapTimer.h:79
bool getCrossing() const
Definition WaypointLapTimer.cpp:230
unsigned long getBestSector3Time() const
Definition WaypointLapTimer.h:75
unsigned long getCurrentLapSector3Time() const
Definition WaypointLapTimer.h:72
int getLaps() const
Definition WaypointLapTimer.cpp:234
unsigned long getCurrentLapSector1Time() const
Definition WaypointLapTimer.h:70
float getLastLapDistance() const
Definition WaypointLapTimer.cpp:279
int getBestSector1LapNumber() const
Definition WaypointLapTimer.h:77
bool hasWaypoint() const
Definition WaypointLapTimer.cpp:287
float getPaceDifference() const
Definition WaypointLapTimer.cpp:266
unsigned long getCurrentLapSector2Time() const
Definition WaypointLapTimer.h:71
float getBestLapDistance() const
Definition WaypointLapTimer.cpp:283
float getCurrentLapDistance() const
Definition WaypointLapTimer.cpp:252
void setProximityMeters(float meters)
Definition WaypointLapTimer.cpp:95
unsigned long getOptimalLapTime() const
Definition WaypointLapTimer.h:76
double getWaypointLng() const
Definition WaypointLapTimer.cpp:295
bool getRaceStarted() const
Definition WaypointLapTimer.cpp:226
unsigned long getLastLapTime() const
Definition WaypointLapTimer.cpp:244
unsigned long getBestLapTime() const
Definition WaypointLapTimer.cpp:248
Definition WaypointLapTimer.h:29
unsigned long time
Definition WaypointLapTimer.h:32
float odometer
Definition WaypointLapTimer.h:33
double lat
Definition WaypointLapTimer.h:30
double lng
Definition WaypointLapTimer.h:31
float distToWaypoint
Definition WaypointLapTimer.h:34