Files
StarPilot/mapd_repo/car_state.go
T
firestar5683 ab81464bd1 Maps
Add navigation and map matching providers with the vendored map service sources.

Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
2026-10-14 19:56:17 -05:00

42 lines
1002 B
Go

package main
import (
"time"
"pfeifer.dev/mapd/cereal/car"
m "pfeifer.dev/mapd/math"
ms "pfeifer.dev/mapd/settings"
"pfeifer.dev/mapd/utils"
)
type CarState struct {
SetSpeed utils.Float32Tracker
VEgo float32
AEgo float32
VCruise float32
GasPressed bool
UpdateTime utils.UpdateTracker
SetSpeedChanging bool
EnableSpeedActive bool
}
func (c *CarState) Update(carData car.CarState) {
c.SetSpeed.Update(carData.VCruise() * ms.KPH_TO_MS)
c.VEgo = carData.VEgo()
c.AEgo = carData.AEgo()
c.VCruise = carData.VCruise()
c.GasPressed = carData.GasPressed()
c.SetSpeedChanging = time.Since(c.SetSpeed.UpdatedTime) < 1500*time.Millisecond
if ms.Settings.EnableSpeed == 0 {
c.EnableSpeedActive = true
} else {
c.EnableSpeedActive = m.Abs(c.SetSpeed.Value-ms.Settings.EnableSpeed) < ms.ENABLE_SPEED_RANGE
}
c.UpdateTime.Update()
}
func (c *CarState) Init() {
c.SetSpeed.AllowNullLastValue = true
c.UpdateTime.Init(100)
}