Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions maps/way.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading