Files
dragonpilot/selfdrive/car/mock/interface.py

62 lines
1.8 KiB
Python
Raw Normal View History

2020-01-17 10:58:43 -08:00
#!/usr/bin/env python3
from cereal import car
from openpilot.system.swaglog import cloudlog
2020-01-17 10:58:43 -08:00
import cereal.messaging as messaging
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
2020-01-17 10:58:43 -08:00
# mocked car interface to work with chffrplus
2020-01-17 10:58:43 -08:00
class CarInterface(CarInterfaceBase):
def __init__(self, CP, CarController, CarState):
2020-05-09 16:40:43 -07:00
super().__init__(CP, CarController, CarState)
2020-01-17 10:58:43 -08:00
cloudlog.debug("Using Mock Car Interface")
self.sm = messaging.SubMaster(['gpsLocation', 'gpsLocationExternal'])
2020-01-17 10:58:43 -08:00
self.speed = 0.
self.prev_speed = 0.
@staticmethod
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
2020-01-17 10:58:43 -08:00
ret.carName = "mock"
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.noOutput)]
2020-01-17 10:58:43 -08:00
ret.mass = 1700.
ret.wheelbase = 2.70
ret.centerToFront = ret.wheelbase * 0.5
ret.steerRatio = 13. # reasonable
2020-01-17 10:58:43 -08:00
return ret
# returns a car.CarState
def _update(self, c):
self.sm.update(0)
gps_sock = 'gpsLocationExternal' if self.sm.rcv_frame['gpsLocationExternal'] > 1 else 'gpsLocation'
if self.sm.updated[gps_sock]:
2020-01-17 10:58:43 -08:00
self.prev_speed = self.speed
self.speed = self.sm[gps_sock].speed
2020-01-17 10:58:43 -08:00
# create message
ret = car.CarState.new_message()
# speeds
ret.vEgo = self.speed
ret.vEgoRaw = self.speed
ret.aEgo = self.speed - self.prev_speed
ret.brakePressed = ret.aEgo < -0.5
2020-01-17 10:58:43 -08:00
ret.standstill = self.speed < 0.01
ret.wheelSpeeds.fl = self.speed
ret.wheelSpeeds.fr = self.speed
ret.wheelSpeeds.rl = self.speed
ret.wheelSpeeds.rr = self.speed
return ret
2020-01-17 10:58:43 -08:00
def apply(self, c, now_nanos):
2020-01-17 10:58:43 -08:00
# in mock no carcontrols
actuators = car.CarControl.Actuators.new_message()
return actuators, []