Skip to content

Commit

Permalink
try to add wheelticks
Browse files Browse the repository at this point in the history
hopefully i dont mess up anything else.
  • Loading branch information
Casey Francis authored and Casey Francis committed Jan 8, 2021
1 parent aca376b commit 0258741
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
28 changes: 21 additions & 7 deletions selfdrive/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __init__(self, dbc_name, CP, VM):
self.last_pump_ts = 0.
self.packer = CANPacker(dbc_name)
self.new_radar_config = False
self.stopped_frame = 0
self.last_wheeltick = 0
self.last_wheeltick_ct = 0

# tesla radar
p = Params()
Expand Down Expand Up @@ -152,14 +155,25 @@ def update(self, enabled, CS, frame, actuators,
# **** process the car messages ****

if CS.CP.carFingerprint in HONDA_BOSCH:
stopping = 0
stopped = 0
starting = 0
accel = actuators.gas - actuators.brake
if accel < 0 and CS.out.vEgo < 0.05:
# prevent rolling backwards
stopping = 0. #vaggy's hack to stop the jerky brakes
# accel = -1.0 #vaggy's hack to stop the jerky brakes
elif accel > 0 and CS.out.vEgo < 0.05:
if accel < 0 and CS.out.vEgo <= 0.1:
if CS.avg_wheelTick == self.last_wheeltick:
self.last_wheeltick_ct += 1
if self.last_wheeltick_ct == 6:
self.stopped_frame = frame
if self.last_wheeltick_ct >= 6:
stopped = 1
# go to full brake after 1 second of standstill
if (frame - self.stopped_frame) >= 100:
accel = -1.0
else:
self.last_wheeltick = CS.avg_wheelTick
self.last_wheeltick_ct = 0
self.stopped_frame = 0

elif accel > 0 and (0.3 >= CS.out.vEgo >= 0):
starting = 1
apply_accel = interp(accel, BOSCH_ACCEL_LOOKUP_BP, BOSCH_ACCEL_LOOKUP_V)
apply_gas = interp(accel, BOSCH_GAS_LOOKUP_BP, BOSCH_GAS_LOOKUP_V)
Expand Down Expand Up @@ -208,7 +222,7 @@ def update(self, enabled, CS, frame, actuators,
idx = frame // 2
ts = frame * DT_CTRL
if CS.CP.carFingerprint in HONDA_BOSCH:
can_sends.extend(hondacan.create_acc_commands(self.packer, enabled, apply_accel, apply_gas, idx, stopping, starting, CS.CP.carFingerprint))
can_sends.extend(hondacan.create_acc_commands(self.packer, enabled, apply_accel, apply_gas, idx, stopped, starting, CS.CP.carFingerprint))
else:
apply_gas = clip(actuators.gas, 0., 1.)
apply_brake = int(clip(self.brake_last * P.BRAKE_MAX, 0, P.BRAKE_MAX - 1))
Expand Down
10 changes: 10 additions & 0 deletions selfdrive/car/honda/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def get_can_signals(CP):
]

if CP.carFingerprint in HONDA_BOSCH:
signals += [("WHEEL_TICK_FL", "WHEEL_TICKS", 0),
("WHEEL_TICK_FR", "WHEEL_TICKS", 0),
("WHEEL_TICK_RL", "WHEEL_TICKS", 0),
("WHEEL_TICK_RR", "WHEEL_TICKS", 0)]
# Civic is only bosch to use the same brake message as other hondas.
if CP.carFingerprint not in (CAR.ACCORDH, CAR.CIVIC_BOSCH, CAR.CIVIC_BOSCH_DIESEL, CAR.CRV_HYBRID, CAR.INSIGHT):
signals += [("BRAKE_PRESSED", "BRAKE_MODULE", 0)]
Expand Down Expand Up @@ -221,6 +225,12 @@ def update(self, cp, cp_cam, cp_body):
ret.wheelSpeeds.rl = cp.vl["WHEEL_SPEEDS"]['WHEEL_SPEED_RL'] * CV.KPH_TO_MS * speed_factor
ret.wheelSpeeds.rr = cp.vl["WHEEL_SPEEDS"]['WHEEL_SPEED_RR'] * CV.KPH_TO_MS * speed_factor
v_wheel = (ret.wheelSpeeds.fl + ret.wheelSpeeds.fr + ret.wheelSpeeds.rl + ret.wheelSpeeds.rr)/4.

self.FL_wheelTick = cp.vl["WHEEL_TICKS"]['WHEEL_TICK_FL']
self.FR_wheelTick = cp.vl["WHEEL_TICKS"]['WHEEL_TICK_FR']
self.RL_wheelTick = cp.vl["WHEEL_TICKS"]['WHEEL_TICK_RL']
self.RR_wheelTick = cp.vl["WHEEL_TICKS"]['WHEEL_TICK_RR']
self.avg_wheelTick = (self.FL_wheelTick + self.FR_wheelTick + self.RL_wheelTick + self.RR_wheelTick) / 4.

# blend in transmission speed at low speed, since it has more low speed accuracy
v_weight = interp(v_wheel, v_weight_bp, v_weight_v)
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/car/honda/hondacan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def create_brake_command(packer, apply_brake, pump_on, pcm_override, pcm_cancel_
return packer.make_can_msg("BRAKE_COMMAND", bus, values, idx)


def create_acc_commands(packer, enabled, accel, gas, idx, stopping, starting, car_fingerprint):
def create_acc_commands(packer, enabled, accel, gas, idx, stopped, starting, car_fingerprint):
commands = []
bus = get_pt_bus(car_fingerprint)

control_on = 5 if enabled else 0
# no gas = -30000
gas_command = gas if enabled and gas > 0 else -30000
accel_command = accel if enabled else 0
braking = 1 if enabled and accel < 0 else 0
standstill = 1 if enabled and stopping else 0
braking = 1 if enabled and accel < -0.15 else 0
standstill = 1 if enabled and stopped else 0
standstill_release = 1 if enabled and starting else 0

acc_control_values = {
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]): # py
ret.brakeMaxBP = [5., 20.] # m/s
ret.brakeMaxV = [1., 0.8] # max brake allowed

ret.stoppingControl = True
ret.startAccel = 0.5
#ret.stoppingControl = True
#ret.startAccel = 0.5

ret.steerActuatorDelay = 0.1
ret.steerRateCost = 0.5
Expand Down

0 comments on commit 0258741

Please sign in to comment.