Skip to content

Commit

Permalink
Merge branch 'master' of github.com:commaai/openpilot into vipc-python
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Aug 30, 2021
2 parents cdb5386 + 92cf526 commit 398cd81
Show file tree
Hide file tree
Showing 29 changed files with 117 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,W1201,W1203,E1136
disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,W1201,W1203,E1136,W1514


# Enable the message, report, category or checker with the given id(s). You can
Expand Down
2 changes: 1 addition & 1 deletion cereal
12 changes: 7 additions & 5 deletions selfdrive/camerad/cameras/camera_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,10 @@ static void camera_open(CameraState *s) {
int ret = cam_control(s->csiphy_fd, CAM_CONFIG_DEV, &config_dev_cmd, sizeof(config_dev_cmd));
assert(ret == 0);

release(s->multi_cam_state->video0_fd, buf_desc[0].mem_handle);
release(s->multi_cam_state->video0_fd, cam_packet_handle);
munmap(csiphy_info, buf_desc[0].size);
release_fd(s->multi_cam_state->video0_fd, buf_desc[0].mem_handle);
munmap(pkt, size);
release_fd(s->multi_cam_state->video0_fd, cam_packet_handle);
}

// link devices
Expand All @@ -751,12 +753,12 @@ static void camera_open(CameraState *s) {
ret = cam_control(s->multi_cam_state->video0_fd, CAM_REQ_MGR_LINK_CONTROL, &req_mgr_link_control, sizeof(req_mgr_link_control));
LOGD("link control: %d", ret);

LOGD("start csiphy: %d", ret);
ret = device_control(s->csiphy_fd, CAM_START_DEV, s->session_handle, s->csiphy_dev_handle);
LOGD("start isp: %d", ret);
LOGD("start csiphy: %d", ret);
ret = device_control(s->multi_cam_state->isp_fd, CAM_START_DEV, s->session_handle, s->isp_dev_handle);
LOGD("start sensor: %d", ret);
LOGD("start isp: %d", ret);
ret = device_control(s->sensor_fd, CAM_START_DEV, s->session_handle, s->sensor_dev_handle);
LOGD("start sensor: %d", ret);

enqueue_req_multi(s, 1, FRAME_BUF_COUNT, 0);
}
Expand Down
4 changes: 0 additions & 4 deletions selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@


class CarInterface(CarInterfaceBase):
@staticmethod
def compute_gb(accel, speed):
return float(accel) / 3.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
5 changes: 0 additions & 5 deletions selfdrive/car/ford/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@


class CarInterface(CarInterfaceBase):

@staticmethod
def compute_gb(accel, speed):
return float(accel) / 3.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
9 changes: 2 additions & 7 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ def update(self, enabled, CS, frame, actuators,

can_sends.append(gmcan.create_steering_control(self.packer_pt, CanBus.POWERTRAIN, apply_steer, idx, lkas_enabled))

# GAS/BRAKE
# no output if not enabled, but keep sending keepalive messages
# treat pedals as one
final_pedal = actuators.gas - actuators.brake

if not enabled:
# Stock ECU sends max regen when not enabled.
apply_gas = P.MAX_ACC_REGEN
apply_brake = 0
else:
apply_gas = int(round(interp(final_pedal, P.GAS_LOOKUP_BP, P.GAS_LOOKUP_V)))
apply_brake = int(round(interp(final_pedal, P.BRAKE_LOOKUP_BP, P.BRAKE_LOOKUP_V)))
apply_gas = int(round(interp(actuators.accel, P.GAS_LOOKUP_BP, P.GAS_LOOKUP_V)))
apply_brake = int(round(interp(actuators.accel, P.BRAKE_LOOKUP_BP, P.BRAKE_LOOKUP_V)))

# Gas/regen and brakes - all at 25Hz
if (frame % 4) == 0:
Expand Down
4 changes: 0 additions & 4 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

class CarInterface(CarInterfaceBase):

@staticmethod
def compute_gb(accel, speed):
return float(accel) / 4.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/gm/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self):
ZERO_GAS = 2048
MAX_BRAKE = 350 # Should be around 3.5m/s^2, including regen
self.MAX_ACC_REGEN = 1404 # ACC Regen braking is slightly less powerful than max regen paddle
self.GAS_LOOKUP_BP = [-0.25, 0., 0.5]
self.GAS_LOOKUP_BP = [-1.0, 0., 2.0]
self.GAS_LOOKUP_V = [self.MAX_ACC_REGEN, ZERO_GAS, MAX_GAS]
self.BRAKE_LOOKUP_BP = [-1., -0.25]
self.BRAKE_LOOKUP_BP = [-4., -1.0]
self.BRAKE_LOOKUP_V = [MAX_BRAKE, 0]

class CAR:
Expand Down
62 changes: 42 additions & 20 deletions selfdrive/car/honda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
from common.numpy_fast import clip, interp
from selfdrive.car import create_gas_command
from selfdrive.car.honda import hondacan
from selfdrive.car.honda.values import OLD_NIDEC_LONG_CONTROL, CruiseButtons, CAR, VISUAL_HUD, HONDA_BOSCH, CarControllerParams
from selfdrive.car.honda.values import OLD_NIDEC_LONG_CONTROL, CruiseButtons, VISUAL_HUD, HONDA_BOSCH, CarControllerParams
from opendbc.can.packer import CANPacker

VisualAlert = car.CarControl.HUDControl.VisualAlert


# TODO: not clear this does anything useful
def compute_gb_honda_bosch(accel, speed):
#TODO returns 0s, is unused
return 0.0, 0.0


def compute_gb_honda_nidec(accel, speed):
creep_brake = 0.0
creep_speed = 2.3
creep_brake_value = 0.15
if speed < creep_speed:
creep_brake = (creep_speed - speed) / creep_speed * creep_brake_value
gb = float(accel) / 4.8 - creep_brake
return clip(gb, 0.0, 1.0), clip(-gb, 0.0, 1.0)


def compute_gas_brake(accel, speed, fingerprint):
if fingerprint in HONDA_BOSCH:
return compute_gb_honda_bosch(accel, speed)
else:
return compute_gb_honda_nidec(accel, speed)


#TODO not clear this does anything useful
def actuator_hystereses(brake, braking, brake_steady, v_ego, car_fingerprint):
# hyst params
brake_hyst_on = 0.02 # to activate brakes exceed this value
Expand All @@ -32,9 +54,6 @@ def actuator_hystereses(brake, braking, brake_steady, v_ego, car_fingerprint):
brake_steady = brake + brake_hyst_gap
brake = brake_steady

if (car_fingerprint in (CAR.ACURA_ILX, CAR.CRV, CAR.CRV_EU)) and brake > 0.0:
brake += 0.15

return brake, braking, brake_steady


Expand Down Expand Up @@ -94,8 +113,15 @@ def update(self, enabled, CS, frame, actuators,

P = self.params

if enabled:
accel = actuators.accel
gas, brake = compute_gas_brake(actuators.accel, CS.out.vEgo, CS.CP.carFingerprint)
else:
accel = 0.0
gas, brake = 0.0, 0.0

# *** apply brake hysteresis ***
brake, self.braking, self.brake_steady = actuator_hystereses(actuators.brake, self.braking, self.brake_steady, CS.out.vEgo, CS.CP.carFingerprint)
pre_limit_brake, self.braking, self.brake_steady = actuator_hystereses(brake, self.braking, self.brake_steady, CS.out.vEgo, CS.CP.carFingerprint)

# *** no output if not enabled ***
if not enabled and CS.out.cruiseState.enabled:
Expand All @@ -107,7 +133,7 @@ def update(self, enabled, CS, frame, actuators,
pcm_cancel_cmd = pcm_cancel_cmd and CS.CP.pcmCruise

# *** rate limit after the enable check ***
self.brake_last = rate_limit(brake, self.brake_last, -2., DT_CTRL)
self.brake_last = rate_limit(pre_limit_brake, self.brake_last, -2., DT_CTRL)

# vehicle hud display, wait for one update from 10Hz 0x304 msg
if hud_show_lanes:
Expand Down Expand Up @@ -147,18 +173,13 @@ def update(self, enabled, CS, frame, actuators,
lkas_active, CS.CP.carFingerprint, idx, CS.CP.openpilotLongitudinalControl))


accel = actuators.gas - actuators.brake

# TODO: pass in LoC.long_control_state and use that to decide starting/stoppping
stopping = accel < 0 and CS.out.vEgo < 0.3
starting = accel > 0 and CS.out.vEgo < 0.3

# Prevent rolling backwards
accel = -1.0 if stopping else accel
if CS.CP.carFingerprint in HONDA_BOSCH:
apply_accel = interp(accel, P.BOSCH_ACCEL_LOOKUP_BP, P.BOSCH_ACCEL_LOOKUP_V)
else:
apply_accel = interp(accel, P.NIDEC_ACCEL_LOOKUP_BP, P.NIDEC_ACCEL_LOOKUP_V)
accel = -4.0 if stopping else accel

# wind brake from air resistance decel at high speed
wind_brake = interp(CS.out.vEgo, [0.0, 2.3, 35.0], [0.001, 0.002, 0.15])
Expand All @@ -167,14 +188,15 @@ def update(self, enabled, CS, frame, actuators,
pcm_accel = int(clip(pcm_accel, 0, 1) * 0xc6)
else:
max_accel = interp(CS.out.vEgo, P.NIDEC_MAX_ACCEL_BP, P.NIDEC_MAX_ACCEL_V)
pcm_accel = int(clip(apply_accel/max_accel, 0.0, 1.0) * 0xc6)
# TODO this 1.44 is just to maintain previous behavior
pcm_accel = int(clip((accel/1.44)/max_accel, 0.0, 1.0) * 0xc6)
pcm_speed_BP = [-wind_brake,
-wind_brake*(3/4),
0.0]
pcm_speed_V = [0.0,
clip(CS.out.vEgo + apply_accel/2.0 - 2.0, 0.0, 100.0),
clip(CS.out.vEgo + apply_accel/2.0 + 2.0, 0.0, 100.0)]
pcm_speed = interp(accel, pcm_speed_BP, pcm_speed_V)
clip(CS.out.vEgo + accel/2.0 - 2.0, 0.0, 100.0),
clip(CS.out.vEgo + accel/2.0 + 2.0, 0.0, 100.0)]
pcm_speed = interp(-brake, pcm_speed_BP, pcm_speed_V)

if not CS.CP.openpilotLongitudinalControl:
if (frame % 2) == 0:
Expand All @@ -193,8 +215,8 @@ def update(self, enabled, CS, frame, actuators,
ts = frame * DT_CTRL

if CS.CP.carFingerprint in HONDA_BOSCH:
apply_gas = interp(accel, P.BOSCH_GAS_LOOKUP_BP, P.BOSCH_GAS_LOOKUP_V)
can_sends.extend(hondacan.create_acc_commands(self.packer, enabled, apply_accel, apply_gas, idx, stopping, starting, CS.CP.carFingerprint))
bosch_gas = interp(accel, P.BOSCH_GAS_LOOKUP_BP, P.BOSCH_GAS_LOOKUP_V)
can_sends.extend(hondacan.create_acc_commands(self.packer, enabled, accel, bosch_gas, idx, stopping, starting, CS.CP.carFingerprint))

else:
apply_brake = clip(self.brake_last - wind_brake, 0.0, 1.0)
Expand All @@ -209,7 +231,7 @@ def update(self, enabled, CS, frame, actuators,
gas_mult = interp(CS.out.vEgo, [0., 10.], [0.4, 1.0])
# send exactly zero if apply_gas is zero. Interceptor will send the max between read value and apply_gas.
# This prevents unexpected pedal range rescaling
apply_gas = clip(gas_mult * actuators.gas, 0., 1.)
apply_gas = clip(gas_mult * gas, 0., 1.)
can_sends.append(create_gas_command(self.packer, apply_gas, idx))

hud = HUDData(int(pcm_accel), int(round(hud_v_cruise)), hud_car,
Expand Down
44 changes: 1 addition & 43 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,7 @@
TransmissionType = car.CarParams.TransmissionType


def compute_gb_honda_bosch(accel, speed):
return float(accel) / 3.5


def compute_gb_honda_nidec(accel, speed):
creep_brake = 0.0
creep_speed = 2.3
creep_brake_value = 0.15
if speed < creep_speed:
creep_brake = (creep_speed - speed) / creep_speed * creep_brake_value
return float(accel) / 4.8 - creep_brake


def compute_gb_acura(accel, speed):
GB_VALUES = [-2., 0.0, 0.8]
GB_BP = [-5., 0.0, 4.0]
return interp(accel, GB_BP, GB_VALUES)


class CarInterface(CarInterfaceBase):
def __init__(self, CP, CarController, CarState):
super().__init__(CP, CarController, CarState)

if self.CS.CP.carFingerprint in HONDA_BOSCH:
self.compute_gb = compute_gb_honda_bosch
else:
self.compute_gb = compute_gb_honda_nidec

@staticmethod
def compute_gb(accel, speed): # pylint: disable=method-hidden
raise NotImplementedError

@staticmethod
def calc_accel_override(a_ego, a_target, v_ego, v_target):

Expand Down Expand Up @@ -333,17 +302,6 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]): # py
ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
tire_stiffness_factor=tire_stiffness_factor)

if candidate in HONDA_BOSCH:
ret.gasMaxBP = [0.] # m/s
ret.gasMaxV = [0.6]
ret.brakeMaxBP = [0.] # m/s
ret.brakeMaxV = [1.] # max brake allowed, 3.5m/s^2
else:
ret.gasMaxBP = [0.] # m/s
ret.gasMaxV = [0.6] # max gas allowed
ret.brakeMaxBP = [5., 20.] # m/s
ret.brakeMaxV = [1., 0.8] # max brake allowed

ret.startAccel = 0.5

ret.steerActuatorDelay = 0.1
Expand Down Expand Up @@ -422,7 +380,7 @@ def update(self, c, can_strings):
# we engage when pcm is active (rising edge)
if ret.cruiseState.enabled and not self.CS.out.cruiseState.enabled:
events.add(EventName.pcmEnable)
elif not ret.cruiseState.enabled and (c.actuators.brake <= 0. or not self.CP.openpilotLongitudinalControl):
elif not ret.cruiseState.enabled and (c.actuators.accel >= 0. or not self.CP.openpilotLongitudinalControl):
# it can happen that car cruise disables while comma system is enabled: need to
# keep braking if needed or if the speed is very low
if ret.vEgo < self.CP.minEnableSpeed + 2.:
Expand Down
5 changes: 1 addition & 4 deletions selfdrive/car/honda/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def __init__(self, CP):
self.NIDEC_MAX_ACCEL_V = [0.5, 2.4, 1.4, 0.6]
self.NIDEC_MAX_ACCEL_BP = [0.0, 4.0, 10., 20.]


self.BOSCH_ACCEL_LOOKUP_BP = [-1., 0., 0.6]
self.BOSCH_ACCEL_LOOKUP_V = [-3.5, 0., 2.]
self.BOSCH_GAS_LOOKUP_BP = [0., 0.6]
self.BOSCH_GAS_LOOKUP_BP = [0., 2.0] # 2m/s^2
self.BOSCH_GAS_LOOKUP_V = [0, 2000]


Expand Down
5 changes: 0 additions & 5 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
from selfdrive.car.interfaces import CarInterfaceBase

class CarInterface(CarInterfaceBase):

@staticmethod
def compute_gb(accel, speed):
return float(accel) / 3.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]): # pylint: disable=dangerous-default-value
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
12 changes: 2 additions & 10 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def __init__(self, CP, CarController, CarState):
def calc_accel_override(a_ego, a_target, v_ego, v_target):
return 1.

@staticmethod
def compute_gb(accel, speed):
raise NotImplementedError

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
raise NotImplementedError
Expand All @@ -72,15 +68,11 @@ def get_std_params(candidate, fingerprint):
ret.pcmCruise = True # openpilot's state is tied to the PCM's cruise state on most cars
ret.minEnableSpeed = -1. # enable is done by stock ACC, so ignore this
ret.steerRatioRear = 0. # no rear steering, at least on the listed cars aboveA
ret.gasMaxBP = [0.]
ret.gasMaxV = [.5] # half max brake
ret.brakeMaxBP = [0.]
ret.brakeMaxV = [1.]
ret.openpilotLongitudinalControl = False
ret.startAccel = 0.0
ret.minSpeedCan = 0.3
ret.stoppingBrakeRate = 0.2 # brake_travel/s while trying to stop
ret.startingBrakeRate = 0.8 # brake_travel/s while releasing on restart
ret.stoppingDecelRate = 0.8 # brake_travel/s while trying to stop
ret.startingAccelRate = 3.2 # brake_travel/s while releasing on restart
ret.stoppingControl = True
ret.longitudinalTuning.deadzoneBP = [0.]
ret.longitudinalTuning.deadzoneV = [0.]
Expand Down
4 changes: 0 additions & 4 deletions selfdrive/car/nissan/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ def __init__(self, CP, CarController, CarState):
super().__init__(CP, CarController, CarState)
self.cp_adas = self.CS.get_adas_can_parser(CP)

@staticmethod
def compute_gb(accel, speed):
return float(accel) / 4.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):

Expand Down
4 changes: 0 additions & 4 deletions selfdrive/car/subaru/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

class CarInterface(CarInterfaceBase):

@staticmethod
def compute_gb(accel, speed):
return float(accel) / 4.0

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
5 changes: 0 additions & 5 deletions selfdrive/car/tesla/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@


class CarInterface(CarInterfaceBase):
@staticmethod
def compute_gb(accel, speed):
# TODO: is this correct?
return accel

@staticmethod
def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
Expand Down
Loading

0 comments on commit 398cd81

Please sign in to comment.