diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c31c08fcd..e0a1755d10 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - id: flake8 exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/' args: - - --ignore=E111,E114,E121,E122,E123,E124,E126,E127,E128,E201,E202,E203,E226,E241,E265,E266,E302,E305,E402,E501,E502,E722,E741,W504 + - --ignore=E111,E114,E121,E122,E123,E124,E126,E127,E128,E201,E202,E203,E226,E241,E265,E266,E302,E305,E402,E501,E722,E741,W504 - --statistics - repo: local hooks: diff --git a/common/transformations/coordinates.py b/common/transformations/coordinates.py index a0d179c353..f619e55cfb 100644 --- a/common/transformations/coordinates.py +++ b/common/transformations/coordinates.py @@ -51,7 +51,7 @@ def ecef2geodetic(ecef, radians=False): S = np.cbrt(1 + C + np.sqrt(C * C + 2 * C)) P = F / (3 * pow((S + 1 / S + 1), 2) * G * G) Q = np.sqrt(1 + 2 * esq * esq * P) - r_0 = -(P * esq * r) / (1 + Q) + np.sqrt(0.5 * a * a*(1 + 1.0 / Q) - \ + r_0 = -(P * esq * r) / (1 + Q) + np.sqrt(0.5 * a * a*(1 + 1.0 / Q) - P * (1 - esq) * z * z / (Q * (1 + Q)) - 0.5 * P * r * r) U = np.sqrt(pow((r - esq * r_0), 2) + z * z) V = np.sqrt(pow((r - esq * r_0), 2) + (1 - esq) * z * z) diff --git a/panda b/panda index 8039638482..eba113cb67 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit 8039638482ebedb9cd10cb1eac083631919ac95e +Subproject commit eba113cb677b53b868f166dd2437347698b1341e diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 381174e59d..85ad43af14 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -70,7 +70,7 @@ class CarInterface(CarInterfaceBase): ret.buttonEvents = [] # events - events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.low], \ + events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.low], gas_resume_speed=2.) if ret.vEgo < self.CP.minSteerSpeed: diff --git a/selfdrive/car/gm/carcontroller.py b/selfdrive/car/gm/carcontroller.py index 9b4961272b..c304081c0a 100644 --- a/selfdrive/car/gm/carcontroller.py +++ b/selfdrive/car/gm/carcontroller.py @@ -67,7 +67,7 @@ class CarController(): self.packer_pt = CANPacker(DBC[CP.carFingerprint]['pt']) self.packer_ch = CANPacker(DBC[CP.carFingerprint]['chassis']) - def update(self, enabled, CS, frame, actuators, \ + def update(self, enabled, CS, frame, actuators, hud_v_cruise, hud_show_lanes, hud_show_car, hud_alert): P = self.params diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index c5ffb127b1..4dffa73c2b 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -182,9 +182,9 @@ class CarInterface(CarInterfaceBase): # In GM, PCM faults out if ACC command overlaps user gas. enabled = c.enabled and not self.CS.out.gasPressed - can_sends = self.CC.update(enabled, self.CS, self.frame, \ + can_sends = self.CC.update(enabled, self.CS, self.frame, c.actuators, - hud_v_cruise, c.hudControl.lanesVisible, \ + hud_v_cruise, c.hudControl.lanesVisible, c.hudControl.leadVisible, c.hudControl.visualAlert) self.frame += 1 diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index a09dffce30..0438dd76a0 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -96,8 +96,8 @@ class CarController(): self.params = CarControllerParams(CP) - def update(self, enabled, CS, frame, actuators, \ - pcm_speed, pcm_override, pcm_cancel_cmd, pcm_accel, \ + def update(self, enabled, CS, frame, actuators, + pcm_speed, pcm_override, pcm_cancel_cmd, pcm_accel, hud_v_cruise, hud_show_lanes, hud_show_car, hud_alert): P = self.params diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 65f80187db..1adbfdf896 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -269,7 +269,7 @@ class CarState(CarStateBase): ret.cruiseState.speedOffset = calc_cruise_offset(0, ret.vEgo) if self.CP.carFingerprint in (CAR.CIVIC_BOSCH, CAR.CIVIC_BOSCH_DIESEL, CAR.ACCORDH, CAR.CRV_HYBRID, CAR.INSIGHT): ret.brakePressed = cp.vl["POWERTRAIN_DATA"]['BRAKE_PRESSED'] != 0 or \ - (self.brake_switch and self.brake_switch_prev and \ + (self.brake_switch and self.brake_switch_prev and cp.ts["POWERTRAIN_DATA"]['BRAKE_SWITCH'] != self.brake_switch_ts) self.brake_switch_prev = self.brake_switch self.brake_switch_ts = cp.ts["POWERTRAIN_DATA"]['BRAKE_SWITCH'] diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index ae421892f8..7d4591626d 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -44,12 +44,12 @@ class Controls: # Setup sockets self.pm = pm if self.pm is None: - self.pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState', \ + self.pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState', 'carControl', 'carEvents', 'carParams']) self.sm = sm if self.sm is None: - self.sm = messaging.SubMaster(['thermal', 'health', 'model', 'liveCalibration', \ + self.sm = messaging.SubMaster(['thermal', 'health', 'model', 'liveCalibration', 'dMonitoringState', 'plan', 'pathPlan', 'liveLocationKalman']) self.can_sock = can_sock @@ -76,8 +76,8 @@ class Controls: internet_needed or not openpilot_enabled_toggle # detect sound card presence and ensure successful init - sounds_available = not os.path.isfile('/EON') or (os.path.isfile('/proc/asound/card0/state') \ - and open('/proc/asound/card0/state').read().strip() == 'ONLINE') + sounds_available = (not os.path.isfile('/EON') or (os.path.isfile('/proc/asound/card0/state') and + open('/proc/asound/card0/state').read().strip() == 'ONLINE')) car_recognized = self.CP.carName != 'mock' # If stock camera is disconnected, we loaded car controls and it's not dashcam mode @@ -184,7 +184,7 @@ class Controls: self.events.add(EventName.preLaneChangeLeft) else: self.events.add(EventName.preLaneChangeRight) - elif self.sm['pathPlan'].laneChangeState in [LaneChangeState.laneChangeStarting, \ + elif self.sm['pathPlan'].laneChangeState in [LaneChangeState.laneChangeStarting, LaneChangeState.laneChangeFinishing]: self.events.add(EventName.laneChange) diff --git a/selfdrive/controls/lib/longcontrol.py b/selfdrive/controls/lib/longcontrol.py index 2b4db2e7af..d75f9db383 100644 --- a/selfdrive/controls/lib/longcontrol.py +++ b/selfdrive/controls/lib/longcontrol.py @@ -24,7 +24,7 @@ def long_control_state_trans(active, long_control_state, v_ego, v_target, v_pid, output_gb, brake_pressed, cruise_standstill): """Update longitudinal control state machine""" stopping_condition = (v_ego < 2.0 and cruise_standstill) or \ - (v_ego < STOPPING_EGO_SPEED and \ + (v_ego < STOPPING_EGO_SPEED and ((v_pid < STOPPING_TARGET_SPEED and v_target < STOPPING_TARGET_SPEED) or brake_pressed)) diff --git a/selfdrive/controls/lib/pathplanner.py b/selfdrive/controls/lib/pathplanner.py index a92efa1ade..48ae4baca0 100644 --- a/selfdrive/controls/lib/pathplanner.py +++ b/selfdrive/controls/lib/pathplanner.py @@ -106,7 +106,7 @@ class PathPlanner(): self.lane_change_direction = LaneChangeDirection.none else: torque_applied = sm['carState'].steeringPressed and \ - ((sm['carState'].steeringTorque > 0 and self.lane_change_direction == LaneChangeDirection.left) or \ + ((sm['carState'].steeringTorque > 0 and self.lane_change_direction == LaneChangeDirection.left) or (sm['carState'].steeringTorque < 0 and self.lane_change_direction == LaneChangeDirection.right)) lane_change_prob = self.LP.l_lane_change_prob + self.LP.r_lane_change_prob diff --git a/selfdrive/controls/lib/pid.py b/selfdrive/controls/lib/pid.py index d374619c19..916b95c9ea 100644 --- a/selfdrive/controls/lib/pid.py +++ b/selfdrive/controls/lib/pid.py @@ -73,7 +73,7 @@ class PIController(): # Update when changing i will move the control away from the limits # or when i will move towards the sign of the error - if ((error >= 0 and (control <= self.pos_limit or i < 0.0)) or \ + if ((error >= 0 and (control <= self.pos_limit or i < 0.0)) or (error <= 0 and (control >= self.neg_limit or i > 0.0))) and \ not freeze_integrator: self.i = i diff --git a/selfdrive/controls/tests/test_monitoring.py b/selfdrive/controls/tests/test_monitoring.py index 2cf8f0fdda..0753300bf6 100644 --- a/selfdrive/controls/tests/test_monitoring.py +++ b/selfdrive/controls/tests/test_monitoring.py @@ -83,11 +83,11 @@ class TestMonitoring(unittest.TestCase): def test_fully_distracted_driver(self): events_output, d_status = run_DState_seq(always_distracted, always_false, always_true, always_false) self.assertTrue(len(events_output[int((_DISTRACTED_TIME-_DISTRACTED_PRE_TIME_TILL_TERMINAL)/2/DT_DMON)]) == 0) - self.assertEqual(events_output[int((_DISTRACTED_TIME-_DISTRACTED_PRE_TIME_TILL_TERMINAL +\ + self.assertEqual(events_output[int((_DISTRACTED_TIME-_DISTRACTED_PRE_TIME_TILL_TERMINAL + ((_DISTRACTED_PRE_TIME_TILL_TERMINAL-_DISTRACTED_PROMPT_TIME_TILL_TERMINAL)/2))/DT_DMON)].names[0], EventName.preDriverDistracted) - self.assertEqual(events_output[int((_DISTRACTED_TIME-_DISTRACTED_PROMPT_TIME_TILL_TERMINAL +\ + self.assertEqual(events_output[int((_DISTRACTED_TIME-_DISTRACTED_PROMPT_TIME_TILL_TERMINAL + ((_DISTRACTED_PROMPT_TIME_TILL_TERMINAL)/2))/DT_DMON)].names[0], EventName.promptDriverDistracted) - self.assertEqual(events_output[int((_DISTRACTED_TIME +\ + self.assertEqual(events_output[int((_DISTRACTED_TIME + ((_TEST_TIMESPAN-10-_DISTRACTED_TIME)/2))/DT_DMON)].names[0], EventName.driverDistracted) self.assertIs(type(d_status.awareness), float) @@ -95,11 +95,11 @@ class TestMonitoring(unittest.TestCase): def test_fully_invisible_driver(self): events_output = run_DState_seq(always_no_face, always_false, always_true, always_false)[0] self.assertTrue(len(events_output[int((_AWARENESS_TIME-_AWARENESS_PRE_TIME_TILL_TERMINAL)/2/DT_DMON)]) == 0) - self.assertEqual(events_output[int((_AWARENESS_TIME-_AWARENESS_PRE_TIME_TILL_TERMINAL +\ + self.assertEqual(events_output[int((_AWARENESS_TIME-_AWARENESS_PRE_TIME_TILL_TERMINAL + ((_AWARENESS_PRE_TIME_TILL_TERMINAL-_AWARENESS_PROMPT_TIME_TILL_TERMINAL)/2))/DT_DMON)].names[0], EventName.preDriverUnresponsive) - self.assertEqual(events_output[int((_AWARENESS_TIME-_AWARENESS_PROMPT_TIME_TILL_TERMINAL +\ + self.assertEqual(events_output[int((_AWARENESS_TIME-_AWARENESS_PROMPT_TIME_TILL_TERMINAL + ((_AWARENESS_PROMPT_TIME_TILL_TERMINAL)/2))/DT_DMON)].names[0], EventName.promptDriverUnresponsive) - self.assertEqual(events_output[int((_AWARENESS_TIME +\ + self.assertEqual(events_output[int((_AWARENESS_TIME + ((_TEST_TIMESPAN-10-_AWARENESS_TIME)/2))/DT_DMON)].names[0], EventName.driverUnresponsive) # 3. op engaged, down to orange, driver pays attention, back to normal; then down to orange, driver touches wheel diff --git a/tools/livedm/livedm.py b/tools/livedm/livedm.py index bb44cf56d3..d54b353680 100644 --- a/tools/livedm/livedm.py +++ b/tools/livedm/livedm.py @@ -49,23 +49,23 @@ if __name__ == "__main__": img = np.zeros((320, 160, 3)) if faceProb > 0.4: cv2.putText(img, 'you', (int(facePosition[0]*160+40), int(facePosition[1]*320+110)), cv2.FONT_ITALIC, 0.5, (255, 255, 0)) - cv2.rectangle(img, (int(facePosition[0]*160+40), int(facePosition[1]*320+120)),\ + cv2.rectangle(img, (int(facePosition[0]*160+40), int(facePosition[1]*320+120)), (int(facePosition[0]*160+120), int(facePosition[1]*320+200)), (255, 255, 0), 1) not_blink = evt.driverMonitoring.leftBlinkProb + evt.driverMonitoring.rightBlinkProb < 1 if evt.driverMonitoring.leftEyeProb > 0.6: - cv2.line(img, (int(facePosition[0]*160+95), int(facePosition[1]*320+140)),\ + cv2.line(img, (int(facePosition[0]*160+95), int(facePosition[1]*320+140)), (int(facePosition[0]*160+105), int(facePosition[1]*320+140)), (255, 255, 0), 2) if not_blink: - cv2.line(img, (int(facePosition[0]*160+99), int(facePosition[1]*320+143)),\ + cv2.line(img, (int(facePosition[0]*160+99), int(facePosition[1]*320+143)), (int(facePosition[0]*160+101), int(facePosition[1]*320+143)), (255, 255, 0), 2) if evt.driverMonitoring.rightEyeProb > 0.6: - cv2.line(img, (int(facePosition[0]*160+55), int(facePosition[1]*320+140)),\ + cv2.line(img, (int(facePosition[0]*160+55), int(facePosition[1]*320+140)), (int(facePosition[0]*160+65), int(facePosition[1]*320+140)), (255, 255, 0), 2) if not_blink: - cv2.line(img, (int(facePosition[0]*160+59), int(facePosition[1]*320+143)),\ + cv2.line(img, (int(facePosition[0]*160+59), int(facePosition[1]*320+143)), (int(facePosition[0]*160+61), int(facePosition[1]*320+143)), (255, 255, 0), 2) else: