21#ifndef _DOVES_CROSSING_ENGINE_H
22#define _DOVES_CROSSING_ENGINE_H
28#include "ArxTypeTraits.h"
31#define CROSSING_LINE_SIDE_A -1
32#define CROSSING_LINE_SIDE_EXACT 0
33#define CROSSING_LINE_SIDE_B 1
36#define DOVES_MILLIS_PER_DAY 86400000UL
41#define CROSSING_MAX_FIX_GAP_MS 10000UL
46#define CROSSING_PAIR_SPACING_FACTOR 1.25
60 if (endMs < startMs) {
63 return endMs - startMs;
83 CrossingEngine(
double crossingThresholdMeters = 7, Stream *debugSerial = NULL);
138 double currentLat,
double currentLng,
139 unsigned long currentTimeMs,
140 float currentOdometer,
141 float currentSpeedKmh,
143 double pointALat,
double pointALng,
144 double pointBLat,
double pointBLng,
147 double& outLat,
double& outLng,
148 unsigned long& outTime,
149 double& outOdometer);
152#ifdef DOVES_DISABLE_DEBUG
160 template<
typename... Args>
void debug_print(Args&&...) {}
161 template<
typename... Args>
void debug_println(Args&&...) {}
163 template<
typename... Args>
164 void debug_print(Args&&... args) {
165 if(_serial) { _serial->print(std::forward<Args>(args)...); }
167 template<
typename... Args>
168 void debug_println(Args&&... args) {
169 if(_serial) { _serial->println(std::forward<Args>(args)...); }
178 bool interpolateCrossingPoint(
double& crossingLat,
double& crossingLng,
unsigned long& crossingTime,
double& crossingOdometer,
double pointALat,
double pointALng,
double pointBLat,
double pointBLng);
182 double interpolateWeight(
double distA,
double distB,
float speedA,
float speedB);
186 double catmullRom(
double p0,
double p1,
double p2,
double p3,
double t);
189 double crossingThresholdMeters;
190 bool forceLinear =
true;
191 unsigned int rejectedCrossingCount = 0;
197 #if defined(RAMEND) && defined(RAMSTART)
198 #if ((RAMEND - RAMSTART) > 3000)
199 static const int crossingPointBufferSize = 100;
201 static const int crossingPointBufferSize = 25;
204 static const int crossingPointBufferSize = 100;
208 int crossingPointBufferIndex = 0;
209 bool crossingPointBufferFull =
false;
static unsigned long timeSinceMidnightDelta(unsigned long startMs, unsigned long endMs)
Elapsed milliseconds between two milliseconds-since-midnight timestamps.
Definition CrossingEngine.h:59
#define DOVES_MILLIS_PER_DAY
Definition CrossingEngine.h:36
LineDetectResult
Definition CrossingEngine.h:67
@ LINE_DETECT_IN_ZONE
Definition CrossingEngine.h:69
@ LINE_DETECT_NONE
Definition CrossingEngine.h:68
@ LINE_DETECT_COMPLETED
Definition CrossingEngine.h:70
Definition CrossingEngine.h:81
void setThreshold(double meters)
Sets the crossing zone threshold, in meters.
Definition CrossingEngine.cpp:21
void setDebugSerial(Stream *debugSerial)
Attaches / detaches a debug output stream.
Definition CrossingEngine.cpp:25
unsigned int getRejectedCrossingCount() const
Number of crossing-zone exits whose interpolation was rejected.
Definition CrossingEngine.cpp:37
void setForceLinear(bool linear)
Selects linear (true, default) or Catmull-Rom (false) position interpolation. Time and odometer are a...
Definition CrossingEngine.cpp:29
LineDetectResult detect(double currentLat, double currentLng, unsigned long currentTimeMs, float currentOdometer, float currentSpeedKmh, const crossingPointBufferEntry *prevFix, double pointALat, double pointALng, double pointBLat, double pointBLng, bool &crossingFlag, int lineLabel, double &outLat, double &outLng, unsigned long &outTime, double &outOdometer)
The crossing-zone state machine (formerly DovesLapTimer::_detectLineCrossing). Detects entry,...
Definition CrossingEngine.cpp:61
void reset()
Clears the buffer, the rejected-crossing counter, and any in-flight zone state. Does NOT clear the co...
Definition CrossingEngine.cpp:41
bool getForceLinear() const
Definition CrossingEngine.cpp:33
Definition CrossingEngine.h:73
double lng
Definition CrossingEngine.h:75
float speedKmh
Definition CrossingEngine.h:78
unsigned long time
Definition CrossingEngine.h:76
float odometer
Definition CrossingEngine.h:77
double lat
Definition CrossingEngine.h:74