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 float getCurrentSpeedKmh() const;
59 float getCurrentSpeedMph() const;
60
61 float getLastLapDistance() const;
62 float getBestLapDistance() const;
63
64 // Waypoint access
65 bool hasWaypoint() const;
66 double getWaypointLat() const;
67 double getWaypointLng() const;
68
69 // Sector getters (not supported, return 0)
70 int getCurrentSector() const { return 0; }
71 bool areSectorLinesConfigured() const { return false; }
72 unsigned long getCurrentLapSector1Time() const { return 0; }
73 unsigned long getCurrentLapSector2Time() const { return 0; }
74 unsigned long getCurrentLapSector3Time() const { return 0; }
75 unsigned long getBestSector1Time() const { return 0; }
76 unsigned long getBestSector2Time() const { return 0; }
77 unsigned long getBestSector3Time() const { return 0; }
78 unsigned long getOptimalLapTime() const { return 0; }
79 int getBestSector1LapNumber() const { return 0; }
80 int getBestSector2LapNumber() const { return 0; }
81 int getBestSector3LapNumber() const { return 0; }
82
83 // Direction (not applicable)
84 int getDirection() const { return DIR_UNKNOWN; }
85 bool isDirectionResolved() const { return false; }
86
87private:
88 template<typename... Args>
89 void debug_print(Args&&... args) {
90 if(_serial) { _serial->print(std::forward<Args>(args)...); }
91 }
92 template<typename... Args>
93 void debug_println(Args&&... args) {
94 if(_serial) { _serial->println(std::forward<Args>(args)...); }
95 }
96
97 void _resetState();
98 void _checkSpeed(double lat, double lng);
99 void _checkProximity(double lat, double lng);
100 void _bufferProximityPoint(double lat, double lng);
101 void _clearProximityBuffer();
102 void _processProximityBuffer();
103
104 Stream *_serial;
105
106 int _state;
107 unsigned long _millisecondsSinceMidnight;
108
109 // Waypoint
110 double _waypointLat;
111 double _waypointLng;
112 float _waypointOdometer;
113
114 // Odometer / position
115 float _totalDistanceTraveled;
116 double _positionPrevLat;
117 double _positionPrevLng;
118 bool _firstPositionReceived;
119 float _currentSpeedKmh;
120 float _speedThresholdMph;
121 float _proximityMeters;
122
123 // Timing
124 bool _raceStarted;
125 bool _crossing;
126 unsigned long _currentLapStartTime;
127 unsigned long _lastLapTime;
128 unsigned long _bestLapTime;
129 float _currentLapOdometerStart;
130 float _lastLapDistance;
131 float _bestLapDistance;
132 int _bestLapNumber;
133 int _laps;
134
135 // Proximity buffer
137 int _proximityBufferIndex;
138 int _proximityBufferCount;
139 float _closestDist;
140 unsigned long _closestTime;
141 float _closestOdometer;
142};
143
144#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:71
float getCurrentSpeedKmh() const
Definition WaypointLapTimer.cpp:279
float getTotalDistanceTraveled() const
Definition WaypointLapTimer.cpp:258
double getWaypointLat() const
Definition WaypointLapTimer.cpp:299
unsigned long getBestSector2Time() const
Definition WaypointLapTimer.h:76
void reset()
Definition WaypointLapTimer.cpp:87
bool isDirectionResolved() const
Definition WaypointLapTimer.h:85
int getCurrentSector() const
Definition WaypointLapTimer.h:70
void setSpeedThresholdMph(float mph)
Definition WaypointLapTimer.cpp:91
unsigned long getCurrentLapTime() const
Definition WaypointLapTimer.cpp:238
unsigned long getBestSector1Time() const
Definition WaypointLapTimer.h:75
int getBestLapNumber() const
Definition WaypointLapTimer.cpp:262
int getBestSector2LapNumber() const
Definition WaypointLapTimer.h:80
int getDirection() const
Definition WaypointLapTimer.h:84
void updateCurrentTime(unsigned long currentTimeMilliseconds)
Definition WaypointLapTimer.cpp:50
float getCurrentSpeedMph() const
Definition WaypointLapTimer.cpp:283
int getBestSector3LapNumber() const
Definition WaypointLapTimer.h:81
bool getCrossing() const
Definition WaypointLapTimer.cpp:230
unsigned long getBestSector3Time() const
Definition WaypointLapTimer.h:77
unsigned long getCurrentLapSector3Time() const
Definition WaypointLapTimer.h:74
int getLaps() const
Definition WaypointLapTimer.cpp:234
unsigned long getCurrentLapSector1Time() const
Definition WaypointLapTimer.h:72
float getLastLapDistance() const
Definition WaypointLapTimer.cpp:287
int getBestSector1LapNumber() const
Definition WaypointLapTimer.h:79
bool hasWaypoint() const
Definition WaypointLapTimer.cpp:295
float getPaceDifference() const
Definition WaypointLapTimer.cpp:266
unsigned long getCurrentLapSector2Time() const
Definition WaypointLapTimer.h:73
float getBestLapDistance() const
Definition WaypointLapTimer.cpp:291
float getCurrentLapDistance() const
Definition WaypointLapTimer.cpp:252
void setProximityMeters(float meters)
Definition WaypointLapTimer.cpp:95
unsigned long getOptimalLapTime() const
Definition WaypointLapTimer.h:78
double getWaypointLng() const
Definition WaypointLapTimer.cpp:303
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