37#ifndef ALIRO_APPROACH_H
38#define ALIRO_APPROACH_H
48#define ALIRO_APPROACH_MEDIAN_N 5
53enum aliro_approach_action {
54 ALIRO_APPROACH_HOLD = 0,
57 ALIRO_APPROACH_UNLOCK_PREDICT,
60 ALIRO_APPROACH_UNLOCK_THRESHOLD,
63 ALIRO_APPROACH_RELOCK_DEPART,
66 ALIRO_APPROACH_RELOCK_ABORT,
104 int32_t far_silence_ms;
126 int32_t win[ALIRO_APPROACH_MEDIAN_N];
128 int near_dwell, far_dwell;
141 int64_t pred_deadline_ms;
148 int64_t last_feed_ms;
bool aliro_approach_locked(const struct aliro_approach *ap)
Return true if the door is locked, false if unlocked.
Definition aliro_approach.c:352
enum aliro_approach_action aliro_approach_feed(struct aliro_approach *ap, int64_t now_ms, int32_t cm)
Update the Kalman filter state with a new range measurement, compute estimated time-to-arrival (ETA) ...
Definition aliro_approach.c:202
int32_t aliro_approach_eta_ms(const struct aliro_approach *ap)
Return the estimated time in milliseconds until approach completes (unlock reaches the door).
Definition aliro_approach.c:387
void aliro_approach_defaults(struct aliro_approach_cfg *cfg)
Initialize an approach configuration with factory defaults: unlock at 100 cm, relock at 250 cm,...
Definition aliro_approach.c:138
void aliro_approach_init(struct aliro_approach *ap, const struct aliro_approach_cfg *cfg)
Initialize an approach controller to locked state with zero velocity and no prediction in flight.
Definition aliro_approach.c:171
enum aliro_approach_action aliro_approach_tick(struct aliro_approach *ap, int64_t now_ms)
Advance the approach state machine by one tick: handle predictive unlock abort on deadline,...
Definition aliro_approach.c:307
enum aliro_approach_action aliro_approach_gone(struct aliro_approach *ap)
Reset the approach controller to locked state while preserving its configuration.
Definition aliro_approach.c:340
int32_t aliro_approach_est_cm(const struct aliro_approach *ap)
Return the current estimated distance in centimeters.
Definition aliro_approach.c:361
void aliro_approach_observe_departure(struct aliro_approach *ap, int64_t now_ms, int32_t cm)
Record a range for the DEPARTURE decision alone, trust gate or no trust gate.
Definition aliro_approach.c:287
int32_t aliro_approach_vel_cm_s(const struct aliro_approach *ap)
Return the current velocity in centimeters per second (positive = approaching, negative = receding).
Definition aliro_approach.c:373
Configuration for approach detection: unlock_cm (presence radius and ETA target), relock_cm (departur...
Definition aliro_approach.h:76
State machine and Kalman filter for approach detection and predictive unlock.
Definition aliro_approach.h:121