Enable more flake8 checks (#1602)

* enable some more flake8 checks

* some more quick ones

* bump opendbc

* e401

* e711 e712

* e115 e116

* e222

* e301

* remove that

* e129

* e701 e702

* e125 e131

* e227

* e306

* e262

* W503

* e713

* e704

* e731

* bump opendbc

* fix some e722
albatross
Adeeb 2020-05-30 20:14:58 -07:00 committed by GitHub
parent 4fcf47812b
commit d9bf9f0a40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
79 changed files with 179 additions and 164 deletions

View File

@ -17,7 +17,8 @@ repos:
- id: flake8
exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/'
args:
- --select=F
- --ignore=E111,E114,E121,E122,E123,E124,E126,E127,E128,E201,E202,E203,E221,E225,E226,E231,E241,E251,E261,E265,E266,E302,E303,E305,E402,E501,E502,E722,E741,W504
- --statistics
- repo: local
hooks:
- id: pylint

View File

@ -25,7 +25,7 @@ def get_imei(slot):
ret = parse_service_call_string(service_call(["iphonesubinfo", "3" ,"i32", str(slot)]))
if not ret:
# allow non android to be identified differently
ret = "%015d" % random.randint(0, 1<<32)
ret = "%015d" % random.randint(0, 1 << 32)
return ret
def get_serial():
@ -132,6 +132,7 @@ def get_network_type():
def get_network_strength(network_type):
network_strength = NetworkStrength.unknown
# from SignalStrength.java
def get_lte_level(rsrp, rssnr):
INT_MAX = 2147483647

View File

@ -39,4 +39,3 @@ def api_get(endpoint, method='GET', timeout=None, access_token=None, **params):
headers['User-Agent'] = "openpilot-" + version
return requests.request(method, backend+endpoint, timeout=timeout, headers = headers, params=params)

View File

@ -8,4 +8,3 @@ if ANDROID:
else:
PERSIST = os.path.join(BASEDIR, "persist")
PARAMS = os.path.join(BASEDIR, "persist", "params")

View File

@ -44,7 +44,8 @@ class AutoMoveTempdir():
def close(self):
os.rename(self._path, self._target_path)
def __enter__(self): return self
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
if type is None:
@ -63,7 +64,8 @@ class NamedTemporaryDir():
def close(self):
shutil.rmtree(self._path)
def __enter__(self): return self
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()

View File

@ -68,8 +68,11 @@ class SwagErrorFilter(logging.Filter):
def filter(self, record):
return record.levelno < logging.ERROR
_tmpfunc = lambda: 0
_srcfile = os.path.normcase(_tmpfunc.__code__.co_filename)
def _tmpfunc():
return 0
def _srcfile():
return os.path.normcase(_tmpfunc.__code__.co_filename)
class SwagLogger(logging.Logger):
def __init__(self):

View File

@ -6,6 +6,7 @@ def clip(x, lo, hi):
def interp(x, xp, fp):
N = len(xp)
def get_interp(xv):
hi = 0
while hi < N and xv > xp[hi]:
@ -14,8 +15,8 @@ def interp(x, xp, fp):
return fp[-1] if hi == N and xv > xp[low] else (
fp[0] if hi == 0 else
(xv - xp[low]) * (fp[hi] - fp[low]) / (xp[hi] - xp[low]) + fp[low])
return [get_interp(v) for v in x] if hasattr(
x, '__iter__') else get_interp(x)
return [get_interp(v) for v in x] if hasattr(x, '__iter__') else get_interp(x)
def mean(x):
return sum(x) / len(x)

View File

@ -195,7 +195,8 @@ class DBReader(DBAccessor):
finally:
lock.release()
def __exit__(self, type, value, traceback): pass
def __exit__(self, type, value, traceback):
pass
class DBWriter(DBAccessor):

View File

@ -43,4 +43,3 @@ class Profiler():
else:
print("%30s: %9.2f percent: %3.0f" % (n, ms*1000.0, ms/self.tot*100))
print("Iter clock: %2.6f TOTAL: %2.2f" % (self.tot/self.iter, self.tot))

View File

@ -32,7 +32,7 @@ class RunningStat():
self.S_last = 0.
else:
self.M = self.M_last + (new_data - self.M_last) / self.n
self.S = self.S_last + (new_data - self.M_last) * (new_data - self.M);
self.S = self.S_last + (new_data - self.M_last) * (new_data - self.M)
self.M_last = self.M
self.S_last = self.S

View File

@ -6,4 +6,3 @@ def phone_only(x):
return x
else:
return nottest(x)

View File

@ -25,4 +25,3 @@ class Timeout:
def __exit__(self, exc_type, exc_val, exc_tb):
signal.alarm(0)

View File

@ -145,4 +145,3 @@ def pretransform_from_calib(calib):
camera_frame_from_road_frame = np.dot(eon_intrinsics, view_frame_from_road_frame)
camera_frame_from_calib_frame = get_camera_frame_from_calib_frame(camera_frame_from_road_frame)
return np.linalg.inv(camera_frame_from_calib_frame)

View File

@ -50,12 +50,16 @@ class URLFile(object):
if self._debug:
print("downloading", self._url)
def header(x):
if b'MISS' in x:
print(x.strip())
c.setopt(pycurl.HEADERFUNCTION, header)
def test(debug_type, debug_msg):
print(" debug(%d): %s" % (debug_type, debug_msg.strip()))
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.DEBUGFUNCTION, test)
t1 = time.time()

@ -1 +1 @@
Subproject commit 0430bfa5c2b08f9cc6ab32470fe8ac9465e7a876
Subproject commit b15edbc1b5a68fd725ea45ba9442a6c9be875971

View File

@ -20,6 +20,7 @@ class Analyzer(ast.NodeVisitor):
for alias in node.names:
imps.add(alias.name)
self.generic_visit(node)
def visit_ImportFrom(self, node):
imps.add(node.module)
self.generic_visit(node)
@ -38,4 +39,3 @@ for f in sorted(pyf):
print("%d lines of parsed openpilot python" % tlns)
#print(sorted(list(imps)))

View File

@ -21,7 +21,7 @@ SafetyModel = car.CarParams.SafetyModel
# USB is optional
try:
import usb1
from usb1 import USBErrorIO, USBErrorOverflow #pylint: disable=no-name-in-module
from usb1 import USBErrorIO, USBErrorOverflow # pylint: disable=no-name-in-module
except Exception:
pass
@ -57,7 +57,7 @@ def __parse_can_buffer(dat):
for j in range(0, len(dat), 0x10):
ddat = dat[j:j+0x10]
f1, f2 = struct.unpack("II", ddat[0:8])
ret.append((f1 >> 21, f2>>16, ddat[8:8+(f2&0xF)], (f2>>4)&0xFF))
ret.append((f1 >> 21, f2 >> 16, ddat[8:8 + (f2 & 0xF)], (f2 >> 4) & 0xFF))
return ret
def can_send_many(arr):

View File

@ -6,7 +6,7 @@ from PIL import ImageFont, ImageDraw, Image
font = ImageFont.truetype("arial", size=72)
def get_frame(idx):
img = np.zeros((874, 1164, 3), np.uint8)
img[100:400, 100:100+(idx%10)*100] = 255
img[100:400, 100:100+(idx % 10)* 100] = 255
# big number
im2 = Image.new("RGB", (200,200))
@ -28,7 +28,7 @@ if __name__ == "__main__":
dat.valid = True
dat.frame = {
"frameId": idx,
"image": frm[idx%len(frm)],
"image": frm[idx % len(frm)],
}
pm.send('frame', dat)

View File

@ -128,4 +128,3 @@ def is_ecu_disconnected(fingerprint, fingerprint_list, ecu_fingerprint, car, ecu
def make_can_msg(addr, dat, bus):
return [addr, 0, dat, bus]

View File

@ -78,7 +78,7 @@ class CarController():
static_msgs = range(1653, 1658)
for addr in static_msgs:
cnt = (frame % 10) + 1
can_sends.append(make_can_msg(addr, (cnt<<4).to_bytes(1, 'little') + b'\x00\x00\x00\x00\x00\x00\x00', 1))
can_sends.append(make_can_msg(addr, (cnt << 4).to_bytes(1, 'little') + b'\x00\x00\x00\x00\x00\x00\x00', 1))
self.enabled_last = enabled
self.main_on_last = CS.out.cruiseState.available

View File

@ -6,7 +6,7 @@ def create_steer_command(packer, angle_cmd, enabled, lkas_state, angle_steers, c
"""Creates a CAN message for the Ford Steer Command."""
#if enabled and lkas available:
if enabled and lkas_state in [2,3]: #and (frame % 500) >= 3:
if enabled and lkas_state in [2,3]: # and (frame % 500) >= 3:
action = lkas_action
else:
action = 0xf

View File

@ -161,8 +161,7 @@ class CarController():
lka_active = CS.lkas_status == 1
lka_critical = lka_active and abs(actuators.steer) > 0.9
lka_icon_status = (lka_active, lka_critical)
if frame % P.CAMERA_KEEPALIVE_STEP == 0 \
or lka_icon_status != self.lka_icon_status_last:
if frame % P.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last:
steer_alert = hud_alert == VisualAlert.steerRequired
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer_alert))
self.lka_icon_status_last = lka_icon_status

View File

@ -121,4 +121,3 @@ def create_lka_icon_command(bus, active, critical, steer):
else:
dat = b"\x00\x00\x00"
return make_can_msg(0x104c006c, dat, bus)

View File

@ -71,14 +71,14 @@ class CarInterface(CarInterfaceBase):
ret.minEnableSpeed = -1. # engage speed is decided by pcm
ret.mass = 4353. * CV.LB_TO_KG + STD_CARGO_KG
ret.wheelbase = 2.86
ret.steerRatio = 14.4 #end to end is 13.46
ret.steerRatio = 14.4 # end to end is 13.46
ret.steerRatioRear = 0.
ret.centerToFront = ret.wheelbase * 0.4
elif candidate == CAR.BUICK_REGAL:
ret.minEnableSpeed = 18 * CV.MPH_TO_MS
ret.mass = 3779. * CV.LB_TO_KG + STD_CARGO_KG # (3849+3708)/2
ret.wheelbase = 2.83 #111.4 inches in meters
ret.wheelbase = 2.83 # 111.4 inches in meters
ret.steerRatio = 14.4 # guess for tourx
ret.steerRatioRear = 0.
ret.centerToFront = ret.wheelbase * 0.4 # guess for tourx

View File

@ -103,7 +103,7 @@ class RadarInterface(RadarInterfaceBase):
self.pts[targetId].yvRel = float('nan')
for oldTarget in list(self.pts.keys()):
if not oldTarget in currentTargets:
if oldTarget not in currentTargets:
del self.pts[oldTarget]
ret.points = list(self.pts.values())

View File

@ -20,7 +20,7 @@ def calc_cruise_offset(offset, speed):
def get_can_signals(CP):
# this function generates lists for signal, messages and initial values
# this function generates lists for signal, messages and initial values
signals = [
("XMISSION_SPEED", "ENGINE_DATA", 0),
("WHEEL_SPEED_FL", "WHEEL_SPEEDS", 0),

View File

@ -13,7 +13,7 @@ def process_hud_alert(enabled, fingerprint, visual_alert, left_lane,
# initialize to no line visible
sys_state = 1
if left_lane and right_lane or sys_warning: #HUD alert only display when LKAS status is active
if left_lane and right_lane or sys_warning: # HUD alert only display when LKAS status is active
if enabled or sys_warning:
sys_state = 3
else:

View File

@ -113,7 +113,7 @@ class CarState(CarStateBase):
self.lkas11 = cp_cam.vl["LKAS11"]
self.clu11 = cp.vl["CLU11"]
self.park_brake = cp.vl["CGW1"]['CF_Gway_ParkBrakeSw']
self.steer_state = cp.vl["MDPS12"]['CF_Mdps_ToiActive'] #0 NOT ACTIVE, 1 ACTIVE
self.steer_state = cp.vl["MDPS12"]['CF_Mdps_ToiActive'] # 0 NOT ACTIVE, 1 ACTIVE
self.lead_distance = cp.vl["SCC11"]['ACC_ObjDist']
return ret
@ -163,7 +163,7 @@ class CarState(CarStateBase):
("ESC_Off_Step", "TCS15", 0),
("CF_Lvr_GearInf", "LVR11", 0), #Transmission Gear (0 = N or P, 1-8 = Fwd, 14 = Rev)
("CF_Lvr_GearInf", "LVR11", 0), # Transmission Gear (0 = N or P, 1-8 = Fwd, 14 = Rev)
("CR_Mdps_StrColTq", "MDPS12", 0),
("CF_Mdps_ToiActive", "MDPS12", 0),

View File

@ -113,7 +113,7 @@ class CarInterface(CarInterfaceBase):
ret.lateralTuning.pid.kf = 0.00006
ret.mass = 1275. + STD_CARGO_KG
ret.wheelbase = 2.7
ret.steerRatio = 13.73 #Spec
ret.steerRatio = 13.73 # Spec
tire_stiffness_factor = 0.385
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
@ -121,7 +121,7 @@ class CarInterface(CarInterfaceBase):
ret.lateralTuning.pid.kf = 0.00006
ret.mass = 1685. + STD_CARGO_KG
ret.wheelbase = 2.7
ret.steerRatio = 13.73 #Spec
ret.steerRatio = 13.73 # Spec
tire_stiffness_factor = 0.385
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]

View File

@ -1 +0,0 @@

View File

@ -182,4 +182,3 @@ class CarState(CarStateBase):
]
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2)

View File

@ -3,4 +3,3 @@ from selfdrive.car.interfaces import RadarInterfaceBase
class RadarInterface(RadarInterfaceBase):
pass

View File

@ -19,8 +19,8 @@ class CAR:
class LKAS_LIMITS:
STEER_THRESHOLD = 15
DISABLE_SPEED = 45 #kph
ENABLE_SPEED = 52 #kph
DISABLE_SPEED = 45 # kph
ENABLE_SPEED = 52 # kph
class Buttons:
NONE = 0

View File

@ -1 +0,0 @@

View File

@ -42,8 +42,10 @@ class CarController():
self.steer_rate_limited = False
self.fake_ecus = set()
if CP.enableCamera: self.fake_ecus.add(Ecu.fwdCamera)
if CP.enableDsu: self.fake_ecus.add(Ecu.dsu)
if CP.enableCamera:
self.fake_ecus.add(Ecu.fwdCamera)
if CP.enableDsu:
self.fake_ecus.add(Ecu.dsu)
self.packer = CANPacker(dbc_name)

View File

@ -127,7 +127,7 @@ class CarInterface(CarInterfaceBase):
ret.wheelbase = 2.82448
ret.steerRatio = 13.7
tire_stiffness_factor = 0.7933
ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG #mean between normal and hybrid
ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
ret.lateralTuning.pid.kf = 0.00006
@ -147,7 +147,7 @@ class CarInterface(CarInterfaceBase):
ret.wheelbase = 2.78
ret.steerRatio = 16.0
tire_stiffness_factor = 0.8
ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG #mean between normal and hybrid limited
ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid limited
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.18], [0.015]] # community tuning
ret.lateralTuning.pid.kf = 0.00012 # community tuning
@ -155,7 +155,7 @@ class CarInterface(CarInterfaceBase):
stop_and_go = False
ret.safetyParam = 73
ret.wheelbase = 2.82
ret.steerRatio = 14.8 #Found at https://pressroom.toyota.com/releases/2016+avalon+product+specs.download
ret.steerRatio = 14.8 # Found at https://pressroom.toyota.com/releases/2016+avalon+product+specs.download
tire_stiffness_factor = 0.7983
ret.mass = 3505. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.17], [0.03]]

View File

@ -1 +0,0 @@

View File

@ -27,4 +27,3 @@ class UIParams:
car_front = 2.6924 * lidar_zoom
car_back = 1.8796 * lidar_zoom
car_color = 110

View File

@ -79,8 +79,8 @@ class LatControlLQR():
i = self.i_lqr + self.ki * self.i_rate * error
control = lqr_output + i
if ((error >= 0 and (control <= steers_max or i < 0.0)) or \
(error <= 0 and (control >= -steers_max or i > 0.0))):
if (error >= 0 and (control <= steers_max or i < 0.0)) or \
(error <= 0 and (control >= -steers_max or i > 0.0)):
self.i_lqr = i
self.output_steer = lqr_output + self.i_lqr

View File

@ -194,4 +194,3 @@ class VehicleModel():
Yaw rate [rad/s]
"""
return self.calc_curvature(sa, u) * u

View File

@ -52,7 +52,8 @@ class TestAlerts(unittest.TestCase):
continue
for i, txt in enumerate([alert.alert_text_1, alert.alert_text_2]):
if i >= len(fonts[alert.alert_size]): break
if i >= len(fonts[alert.alert_size]):
break
font = fonts[alert.alert_size][i]
w, h = draw.textsize(txt, font)

View File

@ -11,10 +11,13 @@ from common.android import ANDROID
if os.getenv("NOLOG") or os.getenv("NOCRASH") or not ANDROID:
def capture_exception(*args, **kwargs):
pass
def bind_user(**kwargs):
pass
def bind_extra(**kwargs):
pass
def install():
pass
else:
@ -38,6 +41,7 @@ else:
def install():
# installs a sys.excepthook
__excepthook__ = sys.excepthook
def handle_exception(*exc_info):
if exc_info[0] not in (KeyboardInterrupt, SystemExit):
capture_exception()

View File

@ -1,5 +1,5 @@
import importlib
from setproctitle import setproctitle #pylint: disable=no-name-in-module
from setproctitle import setproctitle # pylint: disable=no-name-in-module
import cereal.messaging as messaging
import selfdrive.crash as crash

View File

@ -8,4 +8,3 @@ class Calibration:
UNCALIBRATED = 0
CALIBRATED = 1
INVALID = 2

View File

@ -133,5 +133,3 @@ on of this parser
self.ionoAlpha = []
self.ionoBeta = []
self.ionoCoeffsValid = False

View File

@ -12,7 +12,8 @@ for ublox version 8, not all functions may work.
import struct
import time, os
import os
import time
# protocol constants
PREAMBLE1 = 0xb5
@ -291,7 +292,7 @@ class UBloxDescriptor:
fields = self.fields[:]
for f in fields:
(fieldname, alen) = ArrayParse(f)
if not fieldname in msg._fields:
if fieldname not in msg._fields:
break
if alen == -1:
f1.append(msg._fields[fieldname])
@ -327,7 +328,7 @@ class UBloxDescriptor:
ret = self.name + ': '
for f in self.fields:
(fieldname, alen) = ArrayParse(f)
if not fieldname in msg._fields:
if fieldname not in msg._fields:
continue
v = msg._fields[fieldname]
if isinstance(v, list):
@ -591,7 +592,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
msg_types[type].unpack(self)
return self._fields, self._recs
@ -601,7 +602,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s' % str(type))
msg_types[type].pack(self)
@ -610,7 +611,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
return msg_types[type].name

View File

@ -83,7 +83,7 @@ def configure_ublox(dev):
def int_to_bool_list(num):
# for parsing bool bytes
return [bool(num & (1<<n)) for n in range(8)]
return [bool(num & (1 << n)) for n in range(8)]
def gen_ephemeris(ephem_data):
@ -134,9 +134,9 @@ def gen_solution(msg):
msg_data['day'],
msg_data['hour'],
msg_data['min'],
msg_data['sec'])
- datetime.datetime(1970,1,1)).total_seconds())*1e+03
+ msg_data['nano']*1e-06)
msg_data['sec']) -
datetime.datetime(1970,1,1)).total_seconds())*1e+03 +
msg_data['nano']*1e-06)
gps_fix = {'bearing': msg_data['headMot']*1e-05, # heading of motion in degrees
'altitude': msg_data['height']*1e-03, # altitude above ellipsoid
'latitude': msg_data['lat']*1e-07, # latitude in degrees
@ -244,7 +244,7 @@ def init_reader():
return dev
except serial.serialutil.SerialException as e:
print(e)
port_counter = (port_counter + 1)%len(ports)
port_counter = (port_counter + 1) % len(ports)
time.sleep(2)
def handle_msg(dev, msg, nav_frame_buffer):

View File

@ -6,4 +6,3 @@ from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME
for fn in sys.argv[1:]:
print("unmarking %s" % fn)
removexattr(fn, UPLOAD_ATTR_NAME)

View File

@ -174,9 +174,11 @@ class Uploader():
if fake_upload:
cloudlog.info("*** WARNING, THIS IS A FAKE UPLOAD TO %s ***" % url)
class FakeResponse():
def __init__(self):
self.status_code = 200
self.last_resp = FakeResponse()
else:
with open(fn, "rb") as f:

View File

@ -140,4 +140,3 @@ class ManeuverPlot():
pylab.savefig("/".join([path, maneuver_name, 'distance.svg']), dpi=1000)
plt.close("all")

View File

@ -29,7 +29,7 @@ CP = CarInterface.get_params(CAR.CIVIC, {0: {0x201: 6}, 1: {}, 2: {}, 3: {}})
def can_cksum(mm):
s = 0
for c in mm:
s += (c>>4)
s += (c >> 4)
s += c & 0xF
s = 8-s
s %= 0x10
@ -45,7 +45,7 @@ def car_plant(pos, speed, grade, gas, brake):
mass = 1700
aero_cd = 0.3
force_peak = mass*3.
force_brake_peak = -mass*10. #1g
force_brake_peak = -mass*10. # 1g
power_peak = 100000 # 100kW
speed_base = power_peak/force_peak
rolling_res = 0.01
@ -277,13 +277,13 @@ class Plant():
vls = vls_tuple(
self.speed_sensor(speed),
self.speed_sensor(speed), self.speed_sensor(speed), self.speed_sensor(speed), self.speed_sensor(speed),
self.angle_steer, self.angle_steer_rate, 0, 0,#Steer torque sensor
self.angle_steer, self.angle_steer_rate, 0, 0, # Steer torque sensor
0, 0, # Blinkers
self.gear_choice,
speed != 0,
self.brake_error, self.brake_error,
not self.seatbelt, self.seatbelt, # Seatbelt
self.brake_pressed, 0., #Brake pressed, Brake switch
self.brake_pressed, 0., # Brake pressed, Brake switch
cruise_buttons,
self.esp_disabled,
0, # HUD lead
@ -339,9 +339,9 @@ class Plant():
# TODO: use the DBC
if self.frame % 5 == 0:
radar_state_msg = b'\x79\x00\x00\x00\x00\x00\x00\x00'
radar_msg = to_3_byte(d_rel*16.0) + \
to_3_byte(int(lateral_pos_rel*16.0)&0x3ff) + \
to_3s_byte(int(v_rel*32.0)) + \
radar_msg = to_3_byte(d_rel * 16.0) + \
to_3_byte(int(lateral_pos_rel * 16.0) & 0x3ff) + \
to_3s_byte(int(v_rel * 32.0)) + \
b"0f00000"
radar_msg = binascii.unhexlify(radar_msg)

View File

@ -6,7 +6,8 @@ import numbers
import dictdiffer
if "CI" in os.environ:
tqdm = lambda x: x
def tqdm(x):
return x
else:
from tqdm import tqdm # type: ignore
@ -32,7 +33,7 @@ def remove_ignored_fields(msg, ignore):
for k in keys[:-1]:
try:
attr = getattr(msg, k)
except:
except AttributeError:
break
else:
v = getattr(attr, keys[-1])
@ -46,8 +47,7 @@ def remove_ignored_fields(msg, ignore):
return msg.as_reader()
def compare_logs(log1, log2, ignore_fields=[], ignore_msgs=[]):
filter_msgs = lambda m: m.which() not in ignore_msgs
log1, log2 = [list(filter(filter_msgs, log)) for log in (log1, log2)]
log1, log2 = [list(filter(lambda m: m.which() not in ignore_msgs, log)) for log in (log1, log2)]
assert len(log1) == len(log2), "logs are not same length: " + str(len(log1)) + " VS " + str(len(log2))
diff = []

View File

@ -1,11 +1,13 @@
#!/usr/bin/env python3
import capnp
import os
import sys
import threading
import importlib
if "CI" in os.environ:
tqdm = lambda x: x
def tqdm(x):
return x
else:
from tqdm import tqdm # type: ignore
@ -110,7 +112,7 @@ class FakePubMaster(messaging.PubMaster):
for s in services:
try:
data = messaging.new_message(s)
except:
except capnp.lib.capnp.KjException:
data = messaging.new_message(s, 0)
self.data[s] = data.as_reader()
self.sock[s] = DumbSocket()

View File

@ -124,7 +124,7 @@ if __name__ == "__main__":
process_replay_dir = os.path.dirname(os.path.abspath(__file__))
try:
ref_commit = open(os.path.join(process_replay_dir, "ref_commit")).read().strip()
except:
except FileNotFoundError:
print("couldn't find reference commit")
sys.exit(1)

View File

@ -14,7 +14,7 @@ def setup_leon_fan():
bus.write_i2c_block_data(0x67, 0xa, [0])
else:
bus.write_i2c_block_data(0x67, 0xa, [0x20])
bus.write_i2c_block_data(0x67, 0x8, [(i-1)<<6])
bus.write_i2c_block_data(0x67, 0x8, [(i - 1) << 6])
time.sleep(1)
bus.close()

View File

@ -100,7 +100,7 @@ def set_eon_fan(val):
else:
#bus.write_i2c_block_data(0x67, 0x45, [0])
bus.write_i2c_block_data(0x67, 0xa, [0x20])
bus.write_i2c_block_data(0x67, 0x8, [(val-1)<<6])
bus.write_i2c_block_data(0x67, 0x8, [(val - 1) << 6])
else:
bus.write_byte_data(0x21, 0x04, 0x2)
bus.write_byte_data(0x21, 0x03, (val*2)+1)

View File

@ -51,7 +51,7 @@ pygame.joystick.init()
textPrint = TextPrint()
# -------- Main Program Loop -----------
while done==False:
while not done:
# EVENT PROCESSING STEP
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
@ -122,4 +122,4 @@ while done==False:
# Close the window and quit.
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
pygame.quit ()
pygame.quit()

View File

@ -111,10 +111,12 @@ class RouteSegment(object):
self.camera_path = camera_path
@property
def name(self): return str(self._name)
def name(self):
return str(self._name)
@property
def canonical_name(self): return self._name
def canonical_name(self):
return self._name
class RouteSegmentName(object):
def __init__(self, name_str):
@ -123,6 +125,8 @@ class RouteSegmentName(object):
self._num = int(num_str)
@property
def segment_num(self): return self._num
def segment_num(self):
return self._num
def __str__(self): return self._segment_name_str
def __str__(self):
return self._segment_name_str

View File

@ -82,5 +82,8 @@ class RouteFrameReader(object):
for fr in frs:
fr.close()
def __enter__(self): return self
def __exit__(self, type, value, traceback): self.close()
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()

View File

@ -93,7 +93,7 @@ def draw_steer_path(speed_ms, curvature, color, img,
draw_path(path_y, path_x, color, img, calibration, top_down, lid_color)
def draw_lead_car(closest, top_down):
if closest != None:
if closest is not None:
closest_y = int(round(UP.lidar_car_y - closest * UP.lidar_zoom))
if closest_y > 0:
top_down[1][int(round(UP.lidar_car_x - METER_WIDTH * 2)):int(
@ -118,12 +118,10 @@ def init_plots(arr, name_to_arr_idx, plot_xlims, plot_ylims, plot_names, plot_co
"p": (0,1,1),
"m": (1,0,1) }
if bigplots == True:
if bigplots:
fig = plt.figure(figsize=(6.4, 7.0))
elif bigplots == False:
fig = plt.figure()
else:
fig = plt.figure(figsize=bigplots)
fig = plt.figure()
fig.set_facecolor((0.2,0.2,0.2))
@ -135,7 +133,7 @@ def init_plots(arr, name_to_arr_idx, plot_xlims, plot_ylims, plot_names, plot_co
ax.patch.set_facecolor((0.4, 0.4, 0.4))
axs.append(ax)
plots = [] ;idxs = [] ;plot_select = []
plots, idxs, plot_select = [], [], []
for i, pl_list in enumerate(plot_names):
for j, item in enumerate(pl_list):
plot, = axs[i].plot(arr[:, name_to_arr_idx[item]],

View File

@ -345,11 +345,15 @@ def get_arg_parser():
parser.add_argument("--no-loop", action="store_true", help="Stop at the end of the replay.")
key_value_pair = lambda x: x.split("=")
def key_value_pair(x):
return x.split("=")
parser.add_argument("address_mapping", nargs="*", type=key_value_pair,
help="Pairs <service>=<zmq_addr> to publish <service> on <zmq_addr>.")
comma_list = lambda x: x.split(",")
def comma_list(x):
return x.split(",")
to_mock_group = parser.add_mutually_exclusive_group()
to_mock_group.add_argument("--min", action="store_true", default=os.getenv("MIN"))
to_mock_group.add_argument("--enabled", default=os.getenv("ENABLED"), type=comma_list)

View File

@ -200,7 +200,7 @@ def go(q):
speed = math.sqrt(vel.x**2 + vel.y**2 + vel.z**2) * 3.6
can_function(pm, speed, fake_wheel.angle, rk.frame, cruise_button=cruise_button, is_engaged=is_openpilot_engaged)
if rk.frame%1 == 0: # 20Hz?
if rk.frame % 1 == 0: # 20Hz?
throttle_op, brake_op, steer_torque_op = sendcan_function(sendcan)
# print(" === torq, ",steer_torque_op, " ===")
if is_openpilot_engaged:

View File

@ -28,8 +28,8 @@ def can_function(pm, speed, angle, idx, cruise_button=0, is_engaged=False):
msg.append(packer.make_can_msg("SCM_BUTTONS", 0, {"CRUISE_BUTTONS": cruise_button}, idx))
values = {"COUNTER_PEDAL": idx&0xF}
checksum = crc8_pedal(packer.make_can_msg("GAS_SENSOR", 0, {"COUNTER_PEDAL": idx&0xF}, -1)[2][:-1])
values = {"COUNTER_PEDAL": idx & 0xF}
checksum = crc8_pedal(packer.make_can_msg("GAS_SENSOR", 0, {"COUNTER_PEDAL": idx & 0xF}, -1)[2][:-1])
values["CHECKSUM_PEDAL"] = checksum
msg.append(packer.make_can_msg("GAS_SENSOR", 0, values, -1))
@ -56,7 +56,7 @@ def can_function(pm, speed, angle, idx, cruise_button=0, is_engaged=False):
msg.append(packer.make_can_msg("BRAKE_COMMAND", 2, {}, idx))
# radar
if idx%5 == 0:
if idx % 5 == 0:
msg.append(rpacker.make_can_msg("RADAR_DIAGNOSTIC", 1, {"RADAR_STATE": 0x79}, -1))
for i in range(16):
msg.append(rpacker.make_can_msg("TRACK_%d" % i, 1, {"LONG_DIST": 255.5}, -1))

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python3
# set up wheel
import os, struct, array
import array
import os
import struct
from fcntl import ioctl
# Iterate over the joystick devices.