Skip to content

Commit

Permalink
Coverted from OpenActuator dbc to Ocelot_control
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Sep 4, 2022
1 parent 3030c89 commit 51c692d
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion opendbc
2 changes: 1 addition & 1 deletion panda
Submodule panda updated from e9ae56 to bbdb0a
26 changes: 12 additions & 14 deletions selfdrive/car/bmw/bmwcan.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import crcmod
from opendbc.can.packer import CANPacker

openactuator_checksum = crcmod.mkCrcFun(0x1D7, initCrc=0xFF, rev=False, xorOut=0x00) # 0xeb (implicit notation) HD = 5 (detecting 4, correcting 2 bits)

def create_steer_command(mode, steer_delta, steer_tq, frame):
"""Creates a CAN message for the actuator ControlCommand"""
packer = CANPacker('OpenActuator')
"""Creates a CAN message for the actuator STEERING_COMMAND"""
packer = CANPacker('ocelot_controls')
values = {
"Counter_CMD1": frame % 0xF,
"MotorId_CMD1": 0x0,
"ControlMode": mode,
"PositionChange": steer_delta,
"TorqueFeedforward": steer_tq,
"TorqueCloseloopMax": 0., #TODO: generate signals for this
"COUNTER": frame % 0xF,
"STEER_MODE": mode,
"STEER_ANGLE": steer_delta,
"STEER_TORQUE": steer_tq,
}
dat = packer.make_can_msg("ControlCmd1", 0, values)[2]
# values["CRC8_CMD1"] = openactuator_checksum(dat[:7])
values["CRC8_CMD1"] = (dat[0] + dat[1] + dat[2] + dat[3] + dat[4] + dat[5] + dat[6]) & 0xFF
msg = packer.make_can_msg("STEERING_COMMAND", 0, values)
addr = msg[0]
dat = msg[2]

values["CHECKSUM"] = calc_checksum_8bit(dat, addr)

return packer.make_can_msg("ControlCmd1", 2, values) #bus 2 is the actuator CAN bus
return packer.make_can_msg("STEERING_COMMAND", 2, values) #bus 2 is the actuator CAN bus


def calc_checksum_4bit(work_data, msg_id): # 0x130
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/bmw/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def update(self, control, CS, frame):
self.steer_rate_limited = target_angle_delta != angle_step #advertise steer beeing rate limited

# steer torque
I_steering = 10 #estimated moment of inertia
I_steering = 0 #estimated moment of inertia

PLANNER_SAMPLING_SUBRATE = 6 #planner updates target angle every 4 or 6 samples
if target_angle_lim != self.last_target_angle_lim or self.planner_cnt >= PLANNER_SAMPLING_SUBRATE-1:
Expand Down
19 changes: 9 additions & 10 deletions selfdrive/car/bmw/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def update(self, cp_PT, cp_F, cp_aux):

ret.genericToggle = self.sportMode

ret.steeringTorqueEps = cp_aux.vl['ControlStatus1']['TorqueActual']
self.steer_angle_delta = cp_aux.vl['ControlStatus1']['PositionError']
ret.steeringTorqueEps = cp_aux.vl['STEERING_STATUS']['STEERING_TORQUE']
self.steer_angle_delta = cp_aux.vl['STEERING_STATUS']['STEERING_ANGLE']

self.prev_gasPressed = ret.gasPressed
return ret
Expand Down Expand Up @@ -235,14 +235,13 @@ def get_F_can_parser(CP): # 540 vehicle option could get away with just PT_CAN,
@staticmethod
def get_actuator_can_parser(CP):
signals = [ # signal name, message name, default value
("TorqueActual", "ControlStatus1", 0),
("TorqueCloseLoopActual", "ControlStatus1", 0),
("SpeedActual", "ControlStatus1", 0),
("PositionError", "ControlStatus1", 0),
("PositionRaw", "SystemStatus2", 0),
("STEERING_ANGLE", "STEERING_STATUS", 0),
("STEERING_TORQUE", "STEERING_STATUS", 0),
("STEERING_SPEED", "STEERING_STATUS", 0),
("CONTROL_STATUS", "STEERING_STATUS", 0),
("TEMPERATURE", "STEERING_STATUS", 0),
]
checks = [ # refresh frequency Hz
("ControlStatus1", 100),
("SystemStatus2", 100),
("STEERING_STATUS", 100),
]
return CANParser('OpenActuator', signals, checks, 2) # 2: Actuator-CAN,
return CANParser('ocelot_controls', signals, checks, 2) # 2: Actuator-CAN,
2 changes: 1 addition & 1 deletion selfdrive/car/bmw/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay

ret.lateralTuning.init('pid')
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[5.5, 30.], [5.5, 30.]]
ret.lateralTuning.pid.kiV, ret.lateralTuning.pid.kpV = [[0.0, 0.0], [1, 5]]
ret.lateralTuning.pid.kiV, ret.lateralTuning.pid.kpV = [[0.0, 0.0], [0.5, 3]]
ret.lateralTuning.pid.kf = 0
ret.steerMaxBP = [0.]
ret.steerMaxV = [SteerLimitParams.MAX_STEERING_TQ]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion selfdrive/test/process_replay/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
INJECT_MODEL = 0

segments = [
("BMW", os.path.dirname(os.path.abspath(__file__)) + "/ref_log/2022-08-31--23-27-00--1--rlog.bz2"),
("BMW", os.path.dirname(os.path.abspath(__file__)) + "/ref_log/2022-09-01--22-52-03--4--rlog.bz2"),
("HONDA", "0375fdf7b1ce594d|2019-06-13--08-32-25--3"), # HONDA.ACCORD
("HONDA", "99c94dc769b5d96e|2019-08-03--14-19-59--2"), # HONDA.CIVIC
("TOYOTA", "77611a1fac303767|2020-02-29--13-29-33--3"), # TOYOTA.COROLLA_TSS2
Expand Down

0 comments on commit 51c692d

Please sign in to comment.