From 73e61ae00f06f865a014698fc1b8dfb4fe23cbb3 Mon Sep 17 00:00:00 2001 From: Jacob Pfeifer Date: Mon, 17 Aug 2026 19:46:27 -0400 Subject: [PATCH] reduce processing and fix some timing issues --- main.go | 7 ++++++- maps/way.go | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e817e80..41aaccf 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,13 @@ func main() { selfdriveState := cereal.NewSubscriber("selfdriveState", cereal.SelfdriveStateReader, true, ms.Settings.SubscriberSettings.ShadowSelfdriveState) defer selfdriveState.Sub.Msgq.Close() + lastLoopTime := time.Now() + for { + lastLoopDuration := time.Since(lastLoopTime) + time.Sleep(max(ms.LOOP_DELAY - lastLoopDuration, 0)) + lastLoopTime = time.Now() + err := state.Send() // send beginning of each loop to ensure it happens at the correct rate if err != nil { slog.Error("Failed to send update", "error", err) @@ -65,7 +71,6 @@ func main() { if err != nil { slog.Error("Failed to send extended update", "error", err) } - time.Sleep(ms.LOOP_DELAY) // handle settings inputs from openpilot/cli input, inputSuccess := sub.Read() diff --git a/maps/way.go b/maps/way.go index 62c2b11..82f957a 100644 --- a/maps/way.go +++ b/maps/way.go @@ -344,6 +344,12 @@ func (w *Way) Hazard() string { func (w *Way) OnWay(location log.GpsLocationData, distanceMultiplier float32) (OnWayResult, error) { res := OnWayResult{} pos := m.NewPosition(location.Latitude(), location.Longitude()) + box := w.Box() + oversizedBox := box.Overlap(0.01) + if !oversizedBox.PosInside(pos) { + res.OnWay = false + return res, nil + } d, err := w.DistanceFrom(pos) res.Distance = d if err != nil {