Run mypy commit hook (#1591)
* run mypy commit hook
* fix mypy errors
old-commit-hash: 3d08dcc3b2
commatwo_master
parent
9aa70600dd
commit
2b60ee9531
39 changed files with 179 additions and 203 deletions
@ -1,3 +1,3 @@ |
|||||||
version https://git-lfs.github.com/spec/v1 |
version https://git-lfs.github.com/spec/v1 |
||||||
oid sha256:c4ea33acc8b1f639f0719f436989886263a67271decbcf29ab8907208161da03 |
oid sha256:7d81ff54962f8734b5c22f96167c7c4b74dfc09234e401c7d7e9b16db4a6a48f |
||||||
size 2043 |
size 2054 |
||||||
|
@ -1,3 +1,3 @@ |
|||||||
version https://git-lfs.github.com/spec/v1 |
version https://git-lfs.github.com/spec/v1 |
||||||
oid sha256:34b9162abbc667c0b14f418f43668422491613c32bfe8a7d8da86b3fc256350f |
oid sha256:93a390d4adf714de0f790b782b83b82301009f2ec74599b675bceb4b79d10fd7 |
||||||
size 165941 |
size 170223 |
||||||
|
@ -0,0 +1,4 @@ |
|||||||
|
[mypy] |
||||||
|
python_version = 3.8 |
||||||
|
ignore_missing_imports = True |
||||||
|
|
@ -1,119 +0,0 @@ |
|||||||
#!/usr/bin/env python3 |
|
||||||
import pygame # pylint: disable=import-error |
|
||||||
from selfdrive.test.longitudinal_maneuvers.plant import Plant |
|
||||||
from selfdrive.car.honda.values import CruiseButtons |
|
||||||
import numpy as np |
|
||||||
import cereal.messaging as messaging |
|
||||||
import math |
|
||||||
|
|
||||||
CAR_WIDTH = 2.0 |
|
||||||
CAR_LENGTH = 4.5 |
|
||||||
|
|
||||||
METER = 8 |
|
||||||
|
|
||||||
def rot_center(image, angle): |
|
||||||
"""rotate an image while keeping its center and size""" |
|
||||||
orig_rect = image.get_rect() |
|
||||||
rot_image = pygame.transform.rotate(image, angle) |
|
||||||
rot_rect = orig_rect.copy() |
|
||||||
rot_rect.center = rot_image.get_rect().center |
|
||||||
rot_image = rot_image.subsurface(rot_rect).copy() |
|
||||||
return rot_image |
|
||||||
|
|
||||||
def car_w_color(c): |
|
||||||
car = pygame.Surface((METER*CAR_LENGTH, METER*CAR_LENGTH)) # pylint: disable=too-many-function-args |
|
||||||
car.set_alpha(0) |
|
||||||
car.fill((10,10,10)) |
|
||||||
car.set_alpha(128) |
|
||||||
pygame.draw.rect(car, c, (METER*1.25, 0, METER*CAR_WIDTH, METER*CAR_LENGTH), 1) |
|
||||||
return car |
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
pygame.init() |
|
||||||
display = pygame.display.set_mode((1000, 1000)) |
|
||||||
pygame.display.set_caption('Plant UI') |
|
||||||
|
|
||||||
car = car_w_color((255,0,255)) |
|
||||||
leadcar = car_w_color((255,0,0)) |
|
||||||
|
|
||||||
carx, cary, heading = 10.0, 50.0, 0.0 |
|
||||||
|
|
||||||
plant = Plant(100, distance_lead = 40.0) |
|
||||||
|
|
||||||
control_offset = 2.0 |
|
||||||
control_pts = list(zip(np.arange(0, 100.0, 10.0), [50.0 + control_offset]*10)) |
|
||||||
|
|
||||||
def pt_to_car(pt): |
|
||||||
x,y = pt |
|
||||||
x -= carx |
|
||||||
y -= cary |
|
||||||
rx = x * math.cos(-heading) + y * -math.sin(-heading) |
|
||||||
ry = x * math.sin(-heading) + y * math.cos(-heading) |
|
||||||
return rx, ry |
|
||||||
|
|
||||||
def pt_from_car(pt): |
|
||||||
x,y = pt |
|
||||||
rx = x * math.cos(heading) + y * -math.sin(heading) |
|
||||||
ry = x * math.sin(heading) + y * math.cos(heading) |
|
||||||
rx += carx |
|
||||||
ry += cary |
|
||||||
return rx, ry |
|
||||||
|
|
||||||
while 1: |
|
||||||
if plant.rk.frame%100 >= 20 and plant.rk.frame%100 <= 25: |
|
||||||
cruise_buttons = CruiseButtons.RES_ACCEL |
|
||||||
else: |
|
||||||
cruise_buttons = 0 |
|
||||||
|
|
||||||
md = messaging.new_message('model') |
|
||||||
md.model.frameId = 0 |
|
||||||
for x in [md.model.path, md.model.leftLane, md.model.rightLane]: |
|
||||||
x.points = [0.0]*50 |
|
||||||
x.prob = 0.0 |
|
||||||
x.std = 1.0 |
|
||||||
|
|
||||||
car_pts = [pt_to_car(pt) for pt in control_pts] |
|
||||||
|
|
||||||
print(car_pts) |
|
||||||
|
|
||||||
car_poly = np.polyfit([x[0] for x in car_pts], [x[1] for x in car_pts], 3) |
|
||||||
md.model.path.points = np.polyval(car_poly, np.arange(0, 50)).tolist() |
|
||||||
md.model.path.prob = 1.0 |
|
||||||
Plant.model.send(md.to_bytes()) |
|
||||||
|
|
||||||
plant.step(cruise_buttons = cruise_buttons, v_lead = 2.0, publish_model = False) |
|
||||||
|
|
||||||
display.fill((10,10,10)) |
|
||||||
|
|
||||||
carx += plant.speed * plant.ts * math.cos(heading) |
|
||||||
cary += plant.speed * plant.ts * math.sin(heading) |
|
||||||
|
|
||||||
# positive steering angle = steering right |
|
||||||
print(plant.angle_steer) |
|
||||||
heading += plant.angle_steer * plant.ts |
|
||||||
print(heading) |
|
||||||
|
|
||||||
# draw my car |
|
||||||
display.blit(pygame.transform.rotate(car, 90-math.degrees(heading)), (carx*METER, cary*METER)) |
|
||||||
|
|
||||||
# draw control pts |
|
||||||
for x,y in control_pts: |
|
||||||
pygame.draw.circle(display, (255,255,0), (int(x * METER),int(y * METER)), 2) |
|
||||||
|
|
||||||
# draw path |
|
||||||
path_pts = zip(np.arange(0, 50), md.model.path.points) |
|
||||||
|
|
||||||
for x,y in path_pts: |
|
||||||
x,y = pt_from_car((x,y)) |
|
||||||
pygame.draw.circle(display, (0,255,0), (int(x * METER),int(y * METER)), 1) |
|
||||||
|
|
||||||
""" |
|
||||||
# draw lead car |
|
||||||
dl = (plant.distance_lead - plant.distance) + 4.5 |
|
||||||
lx = carx + dl * math.cos(heading) |
|
||||||
ly = cary + dl * math.sin(heading) |
|
||||||
|
|
||||||
display.blit(pygame.transform.rotate(leadcar, 90-math.degrees(heading)), (lx*METER, ly*METER)) |
|
||||||
""" |
|
||||||
|
|
||||||
pygame.display.flip() |
|
@ -0,0 +1,72 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
import bz2 |
||||||
|
import os |
||||||
|
import sys |
||||||
|
import numbers |
||||||
|
|
||||||
|
import dictdiffer |
||||||
|
if "CI" in os.environ: |
||||||
|
tqdm = lambda x: x |
||||||
|
else: |
||||||
|
from tqdm import tqdm # type: ignore |
||||||
|
|
||||||
|
from tools.lib.logreader import LogReader |
||||||
|
|
||||||
|
def save_log(dest, log_msgs): |
||||||
|
dat = b"" |
||||||
|
for msg in tqdm(log_msgs): |
||||||
|
dat += msg.as_builder().to_bytes() |
||||||
|
dat = bz2.compress(dat) |
||||||
|
|
||||||
|
with open(dest, "wb") as f: |
||||||
|
f.write(dat) |
||||||
|
|
||||||
|
def remove_ignored_fields(msg, ignore): |
||||||
|
msg = msg.as_builder() |
||||||
|
for key in ignore: |
||||||
|
attr = msg |
||||||
|
keys = key.split(".") |
||||||
|
if msg.which() not in key and len(keys) > 1: |
||||||
|
continue |
||||||
|
|
||||||
|
for k in keys[:-1]: |
||||||
|
try: |
||||||
|
attr = getattr(msg, k) |
||||||
|
except: |
||||||
|
break |
||||||
|
else: |
||||||
|
v = getattr(attr, keys[-1]) |
||||||
|
if isinstance(v, bool): |
||||||
|
val = False |
||||||
|
elif isinstance(v, numbers.Number): |
||||||
|
val = 0 |
||||||
|
else: |
||||||
|
raise NotImplementedError |
||||||
|
setattr(attr, keys[-1], val) |
||||||
|
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)] |
||||||
|
assert len(log1) == len(log2), "logs are not same length: " + str(len(log1)) + " VS " + str(len(log2)) |
||||||
|
|
||||||
|
diff = [] |
||||||
|
for msg1, msg2 in tqdm(zip(log1, log2)): |
||||||
|
if msg1.which() != msg2.which(): |
||||||
|
print(msg1, msg2) |
||||||
|
raise Exception("msgs not aligned between logs") |
||||||
|
|
||||||
|
msg1_bytes = remove_ignored_fields(msg1, ignore_fields).as_builder().to_bytes() |
||||||
|
msg2_bytes = remove_ignored_fields(msg2, ignore_fields).as_builder().to_bytes() |
||||||
|
|
||||||
|
if msg1_bytes != msg2_bytes: |
||||||
|
msg1_dict = msg1.to_dict(verbose=True) |
||||||
|
msg2_dict = msg2.to_dict(verbose=True) |
||||||
|
dd = dictdiffer.diff(msg1_dict, msg2_dict, ignore=ignore_fields, tolerance=0) |
||||||
|
diff.extend(dd) |
||||||
|
return diff |
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
log1 = list(LogReader(sys.argv[1])) |
||||||
|
log2 = list(LogReader(sys.argv[2])) |
||||||
|
print(compare_logs(log1, log2, sys.argv[3:])) |
Loading…
Reference in new issue