dragonpilot - 基於 openpilot 的開源駕駛輔助系統
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.

64 lines
1.9 KiB

5 years ago
#!/usr/bin/env python3
from cereal import car
from system.swaglog import cloudlog
5 years ago
import cereal.messaging as messaging
from selfdrive.car import get_safety_config
5 years ago
from selfdrive.car.interfaces import CarInterfaceBase
# 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
ret.tireStiffnessFront = 1e6 # very stiff to neglect slip
ret.tireStiffnessRear = 1e6 # very stiff to neglect slip
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, []