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.
41 lines
1.3 KiB
41 lines
1.3 KiB
2 years ago
|
from opendbc.can.parser import CANParser
|
||
3 months ago
|
from opendbc.car import Bus, structs
|
||
|
from opendbc.car.interfaces import CarStateBase
|
||
|
from opendbc.car.body.values import DBC
|
||
2 years ago
|
|
||
|
|
||
|
class CarState(CarStateBase):
|
||
3 months ago
|
def update(self, can_parsers) -> structs.CarState:
|
||
|
cp = can_parsers[Bus.main]
|
||
|
ret = structs.CarState()
|
||
2 years ago
|
|
||
|
ret.wheelSpeeds.fl = cp.vl['MOTORS_DATA']['SPEED_L']
|
||
|
ret.wheelSpeeds.fr = cp.vl['MOTORS_DATA']['SPEED_R']
|
||
|
|
||
|
ret.vEgoRaw = ((ret.wheelSpeeds.fl + ret.wheelSpeeds.fr) / 2.) * self.CP.wheelSpeedFactor
|
||
|
|
||
|
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
|
||
|
ret.standstill = False
|
||
|
|
||
|
ret.steerFaultPermanent = any([cp.vl['VAR_VALUES']['MOTOR_ERR_L'], cp.vl['VAR_VALUES']['MOTOR_ERR_R'],
|
||
|
cp.vl['VAR_VALUES']['FAULT']])
|
||
|
|
||
|
ret.charging = cp.vl["BODY_DATA"]["CHARGER_CONNECTED"] == 1
|
||
|
ret.fuelGauge = cp.vl["BODY_DATA"]["BATT_PERCENTAGE"] / 100
|
||
|
|
||
|
# irrelevant for non-car
|
||
3 months ago
|
ret.gearShifter = structs.CarState.GearShifter.drive
|
||
2 years ago
|
ret.cruiseState.enabled = True
|
||
|
ret.cruiseState.available = True
|
||
|
|
||
|
return ret
|
||
|
|
||
|
@staticmethod
|
||
3 months ago
|
def get_can_parsers(CP):
|
||
2 years ago
|
messages = [
|
||
2 years ago
|
("MOTORS_DATA", 100),
|
||
|
("VAR_VALUES", 10),
|
||
|
("BODY_DATA", 1),
|
||
|
]
|
||
3 months ago
|
return {Bus.main: CANParser(DBC[CP.carFingerprint][Bus.main], messages, 0)}
|