openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

5 years ago
#!/usr/bin/env python3
from cereal import car
from openpilot.system.swaglog import cloudlog
5 years ago
import cereal.messaging as messaging
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
5 years ago
# mocked car interface to work with chffrplus
5 years ago
class CarInterface(CarInterfaceBase):
def __init__(self, CP, CarController, CarState):
super().__init__(CP, CarController, CarState)
5 years ago
cloudlog.debug("Using Mock Car Interface")
self.sm = messaging.SubMaster(['gpsLocation', 'gpsLocationExternal'])
5 years ago
self.speed = 0.
self.prev_speed = 0.
@staticmethod
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
5 years ago
ret.carName = "mock"
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.noOutput)]
5 years ago
ret.mass = 1700.
ret.wheelbase = 2.70
ret.centerToFront = ret.wheelbase * 0.5
ret.steerRatio = 13. # reasonable
5 years ago
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]:
5 years ago
self.prev_speed = self.speed
self.speed = self.sm[gps_sock].speed
5 years ago
# 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
5 years ago
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
5 years ago
def apply(self, c, now_nanos):
5 years ago
# in mock no carcontrols
actuators = car.CarControl.Actuators.new_message()
return actuators, []