card: set mock carState fields (#33294)
* mock carstate inside card * not used
This commit is contained in:
parent
9f14c447db
commit
cb61d0045c
|
@ -1,4 +1,5 @@
|
|||
from cereal import car
|
||||
import cereal.messaging as messaging
|
||||
from openpilot.selfdrive.car import DT_CTRL
|
||||
from openpilot.selfdrive.car.interfaces import MAX_CTRL_SPEED
|
||||
from openpilot.selfdrive.car.volkswagen.values import CarControllerParams as VWCarControllerParams
|
||||
|
@ -12,6 +13,21 @@ EventName = car.CarEvent.EventName
|
|||
NetworkLocation = car.CarParams.NetworkLocation
|
||||
|
||||
|
||||
# TODO: the goal is to abstract this file into the CarState struct and make events generic
|
||||
class MockCarState:
|
||||
def __init__(self):
|
||||
self.sm = messaging.SubMaster(['gpsLocation', 'gpsLocationExternal'])
|
||||
|
||||
def update(self, CS: car.CarState):
|
||||
self.sm.update(0)
|
||||
gps_sock = 'gpsLocationExternal' if self.sm.recv_frame['gpsLocationExternal'] > 1 else 'gpsLocation'
|
||||
|
||||
CS.vEgo = self.sm[gps_sock].speed
|
||||
CS.vEgoRaw = self.sm[gps_sock].speed
|
||||
|
||||
return CS
|
||||
|
||||
|
||||
class CarSpecificEvents:
|
||||
def __init__(self, CP: car.CarParams):
|
||||
self.CP = CP
|
||||
|
|
|
@ -15,7 +15,7 @@ from openpilot.common.swaglog import cloudlog, ForwardingHandler
|
|||
from openpilot.selfdrive.pandad import can_capnp_to_list, can_list_to_can_capnp
|
||||
from openpilot.selfdrive.car import DT_CTRL, carlog
|
||||
from openpilot.selfdrive.car.can_definitions import CanData, CanRecvCallable, CanSendCallable
|
||||
from openpilot.selfdrive.car.car_specific import CarSpecificEvents
|
||||
from openpilot.selfdrive.car.car_specific import CarSpecificEvents, MockCarState
|
||||
from openpilot.selfdrive.car.fw_versions import ObdCallback
|
||||
from openpilot.selfdrive.car.car_helpers import get_car
|
||||
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
||||
|
@ -133,6 +133,7 @@ class Car:
|
|||
self.events = Events()
|
||||
|
||||
self.car_events = CarSpecificEvents(self.CP)
|
||||
self.mock_carstate = MockCarState()
|
||||
|
||||
# card is driven by can recv, expected at 100Hz
|
||||
self.rk = Ratekeeper(100, print_delay_threshold=None)
|
||||
|
@ -144,6 +145,9 @@ class Car:
|
|||
can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True)
|
||||
CS = self.CI.update(can_capnp_to_list(can_strs))
|
||||
|
||||
if self.CP.carName == 'mock':
|
||||
CS = self.mock_carstate.update(CS)
|
||||
|
||||
self.sm.update(0)
|
||||
|
||||
can_rcv_valid = len(can_strs) > 0
|
||||
|
|
|
@ -3,5 +3,5 @@ from openpilot.selfdrive.car.interfaces import CarStateBase
|
|||
|
||||
|
||||
class CarState(CarStateBase):
|
||||
def update(self, *args) -> car.CarState:
|
||||
pass
|
||||
def update(self, *_) -> car.CarState:
|
||||
return car.CarState.new_message()
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
from cereal import car
|
||||
import cereal.messaging as messaging
|
||||
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
||||
|
||||
|
||||
# mocked car interface for dashcam mode
|
||||
class CarInterface(CarInterfaceBase):
|
||||
def __init__(self, CP, CarController, CarState):
|
||||
super().__init__(CP, CarController, CarState)
|
||||
|
||||
self.speed = 0.
|
||||
self.sm = messaging.SubMaster(['gpsLocation', 'gpsLocationExternal'])
|
||||
|
||||
@staticmethod
|
||||
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
|
||||
|
@ -23,11 +16,4 @@ class CarInterface(CarInterfaceBase):
|
|||
return ret
|
||||
|
||||
def _update(self):
|
||||
self.sm.update(0)
|
||||
gps_sock = 'gpsLocationExternal' if self.sm.recv_frame['gpsLocationExternal'] > 1 else 'gpsLocation'
|
||||
|
||||
ret = car.CarState.new_message()
|
||||
ret.vEgo = self.sm[gps_sock].speed
|
||||
ret.vEgoRaw = self.sm[gps_sock].speed
|
||||
|
||||
return ret
|
||||
return self.CS.update()
|
||||
|
|
Loading…
Reference in New Issue