DovesLapTimer 4.3.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
30public:
31 WaypointLapTimer(Stream *debugSerial = NULL);
32
33 void updateCurrentTime(unsigned long currentTimeMilliseconds);
34 int loop(double currentLat, double currentLng, float currentAltitudeMeters, float currentSpeedKnots);
35 void reset();
36 void setSpeedThresholdMph(float mph);
37 void setProximityMeters(float meters);
38
39 // Timing getters (duck-typed to DovesLapTimer)
40 bool getRaceStarted() const;
41 bool getCrossing() const;
42 int getLaps() const;
43 unsigned long getCurrentLapTime() const;
44 unsigned long getLastLapTime() const;
45 unsigned long getBestLapTime() const;
46 float getCurrentLapDistance() const;
47 float getTotalDistanceTraveled() const;
48 int getBestLapNumber() const;
49 float getPaceDifference() const;
50 float getCurrentSpeedKmh() const;
51 float getCurrentSpeedMph() const;
52
53 float getLastLapDistance() const;
54 float getBestLapDistance() const;
55
56 // Waypoint access
57 bool hasWaypoint() const;
58 double getWaypointLat() const;
59 double getWaypointLng() const;
60
61 // Sector getters (not supported, return 0)
62 int getCurrentSector() const { return 0; }
63 bool areSectorLinesConfigured() const { return false; }
64 unsigned long getCurrentLapSector1Time() const { return 0; }
65 unsigned long getCurrentLapSector2Time() const { return 0; }
66 unsigned long getCurrentLapSector3Time() const { return 0; }
67 unsigned long getBestSector1Time() const { return 0; }
68 unsigned long getBestSector2Time() const { return 0; }
69 unsigned long getBestSector3Time() const { return 0; }
70 unsigned long getOptimalLapTime() const { return 0; }
71 int getBestSector1LapNumber() const { return 0; }
72 int getBestSector2LapNumber() const { return 0; }
73 int getBestSector3LapNumber() const { return 0; }
74
75 // Direction (not applicable)
76 int getDirection() const { return DIR_UNKNOWN; }
77 bool isDirectionResolved() const { return false; }
78
79private:
80#ifdef DOVES_DISABLE_DEBUG
81 // Compile-time debug kill switch: the runtime _serial null-check still
82 // keeps every debug string and print call-site in flash on production
83 // builds that never attach a debug Stream. Defining DOVES_DISABLE_DEBUG
84 // (e.g. -DDOVES_DISABLE_DEBUG in build flags) replaces the debug
85 // templates with empty inlines so the compiler drops it all — several
86 // KB on a fully-featured firmware. Debug behavior is unchanged when
87 // the macro is not defined.
88 template<typename... Args> void debug_print(Args&&...) {}
89 template<typename... Args> void debug_println(Args&&...) {}
90#else
91 template<typename... Args>
92 void debug_print(Args&&... args) {
93 if(_serial) { _serial->print(std::forward<Args>(args)...); }
94 }
95 template<typename... Args>
96 void debug_println(Args&&... args) {
97 if(_serial) { _serial->println(std::forward<Args>(args)...); }
98 }
99#endif
100
101 void _resetState();
102 void _checkSpeed(double lat, double lng);
103 void _checkProximity(double lat, double lng);
104 void _updateProximity(double lat, double lng);
105 void _resetClosestApproach();
106 void _finalizeProximityPass();
107
108 Stream *_serial;
109
110 int _state;
111 unsigned long _millisecondsSinceMidnight;
112
113 // Waypoint
114 double _waypointLat;
115 double _waypointLng;
116 float _waypointOdometer;
117
118 // Odometer / position
119 float _totalDistanceTraveled;
120 double _positionPrevLat;
121 double _positionPrevLng;
122 bool _firstPositionReceived;
123 int _consecutiveJumpCount;
124 float _currentSpeedKmh;
125 float _speedThresholdMph;
126 float _proximityMeters;
127
128 // Timing
129 bool _raceStarted;
130 bool _crossing;
131 unsigned long _currentLapStartTime;
132 unsigned long _lastLapTime;
133 unsigned long _bestLapTime;
134 float _currentLapOdometerStart;
135 float _lastLapDistance;
136 float _bestLapDistance;
137 int _bestLapNumber;
138 int _laps;
139
140 // Closest approach to the waypoint during the current proximity pass.
141 // Only these three scalars are needed for the lap split — the old
142 // 50-entry buffer of every in-proximity fix was written and never read
143 // (1.6 KB of dead SRAM per instance).
144 float _closestDist;
145 unsigned long _closestTime;
146 float _closestOdometer;
147};
148
149#endif
#define DIR_UNKNOWN
Definition DovesLapTimer.h:55
void loop()
Definition basic_oled_example.ino:116
Definition WaypointLapTimer.h:29
bool areSectorLinesConfigured() const
Definition WaypointLapTimer.h:63
float getCurrentSpeedKmh() const
Definition WaypointLapTimer.cpp:289
float getTotalDistanceTraveled() const
Definition WaypointLapTimer.cpp:268
double getWaypointLat() const
Definition WaypointLapTimer.cpp:309
unsigned long getBestSector2Time() const
Definition WaypointLapTimer.h:68
void reset()
Definition WaypointLapTimer.cpp:109
bool isDirectionResolved() const
Definition WaypointLapTimer.h:77
int getCurrentSector() const
Definition WaypointLapTimer.h:62
void setSpeedThresholdMph(float mph)
Definition WaypointLapTimer.cpp:113
unsigned long getCurrentLapTime() const
Definition WaypointLapTimer.cpp:248
unsigned long getBestSector1Time() const
Definition WaypointLapTimer.h:67
int getBestLapNumber() const
Definition WaypointLapTimer.cpp:272
int getBestSector2LapNumber() const
Definition WaypointLapTimer.h:72
int getDirection() const
Definition WaypointLapTimer.h:76
void updateCurrentTime(unsigned long currentTimeMilliseconds)
Definition WaypointLapTimer.cpp:51
float getCurrentSpeedMph() const
Definition WaypointLapTimer.cpp:293
int getBestSector3LapNumber() const
Definition WaypointLapTimer.h:73
bool getCrossing() const
Definition WaypointLapTimer.cpp:240
unsigned long getBestSector3Time() const
Definition WaypointLapTimer.h:69
unsigned long getCurrentLapSector3Time() const
Definition WaypointLapTimer.h:66
int getLaps() const
Definition WaypointLapTimer.cpp:244
unsigned long getCurrentLapSector1Time() const
Definition WaypointLapTimer.h:64
float getLastLapDistance() const
Definition WaypointLapTimer.cpp:297
int getBestSector1LapNumber() const
Definition WaypointLapTimer.h:71
bool hasWaypoint() const
Definition WaypointLapTimer.cpp:305
float getPaceDifference() const
Definition WaypointLapTimer.cpp:276
unsigned long getCurrentLapSector2Time() const
Definition WaypointLapTimer.h:65
float getBestLapDistance() const
Definition WaypointLapTimer.cpp:301
float getCurrentLapDistance() const
Definition WaypointLapTimer.cpp:262
void setProximityMeters(float meters)
Definition WaypointLapTimer.cpp:117
unsigned long getOptimalLapTime() const
Definition WaypointLapTimer.h:70
double getWaypointLng() const
Definition WaypointLapTimer.cpp:313
bool getRaceStarted() const
Definition WaypointLapTimer.cpp:236
unsigned long getLastLapTime() const
Definition WaypointLapTimer.cpp:254
unsigned long getBestLapTime() const
Definition WaypointLapTimer.cpp:258