mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 16:23:46 +08:00
Run mypy commit hook (#1591)
* run mypy commit hook * fix mypy errors old-commit-hash: 3d08dcc3b27936cb14c0eae63605be9a6c077380
This commit is contained in:
@@ -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()
|
||||
@@ -8,7 +8,7 @@ import dictdiffer
|
||||
if "CI" in os.environ:
|
||||
tqdm = lambda x: x
|
||||
else:
|
||||
from tqdm import tqdm
|
||||
from tqdm import tqdm # type: ignore
|
||||
|
||||
from tools.lib.logreader import LogReader
|
||||
|
||||
|
||||
@@ -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:]))
|
||||
@@ -7,7 +7,7 @@ import importlib
|
||||
if "CI" in os.environ:
|
||||
tqdm = lambda x: x
|
||||
else:
|
||||
from tqdm import tqdm
|
||||
from tqdm import tqdm # type: ignore
|
||||
|
||||
from cereal import car, log
|
||||
from selfdrive.car.car_helpers import get_car
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from selfdrive.car.car_helpers import interface_names
|
||||
from selfdrive.test.process_replay.process_replay import replay_process, CONFIGS
|
||||
from selfdrive.test.process_replay.compare_logs import compare_logs
|
||||
from selfdrive.test.process_replay.process_replay import (CONFIGS,
|
||||
replay_process)
|
||||
from tools.lib.logreader import LogReader
|
||||
|
||||
|
||||
INJECT_MODEL = 0
|
||||
|
||||
segments = [
|
||||
@@ -134,7 +135,7 @@ if __name__ == "__main__":
|
||||
untested = (set(interface_names) - set(excluded_interfaces)) - tested_cars
|
||||
assert len(untested) == 0, "Cars missing routes: %s" % (str(untested))
|
||||
|
||||
results = {}
|
||||
results: Any = {}
|
||||
for car_brand, segment in segments:
|
||||
if (cars_whitelisted and car_brand.upper() not in args.whitelist_cars) or \
|
||||
(not cars_whitelisted and car_brand.upper() in args.blacklist_cars):
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from typing import List, cast
|
||||
|
||||
import requests
|
||||
from cereal import car
|
||||
|
||||
import selfdrive.manager as manager
|
||||
import cereal.messaging as messaging
|
||||
from common.params import Params
|
||||
import selfdrive.manager as manager
|
||||
from cereal import car
|
||||
from common.basedir import BASEDIR
|
||||
from selfdrive.car.fingerprints import all_known_cars
|
||||
from selfdrive.car.honda.values import CAR as HONDA
|
||||
from selfdrive.car.toyota.values import CAR as TOYOTA
|
||||
from selfdrive.car.gm.values import CAR as GM
|
||||
from selfdrive.car.ford.values import CAR as FORD
|
||||
from selfdrive.car.hyundai.values import CAR as HYUNDAI
|
||||
from common.params import Params
|
||||
from selfdrive.car.chrysler.values import CAR as CHRYSLER
|
||||
from selfdrive.car.subaru.values import CAR as SUBARU
|
||||
from selfdrive.car.volkswagen.values import CAR as VOLKSWAGEN
|
||||
from selfdrive.car.fingerprints import all_known_cars
|
||||
from selfdrive.car.ford.values import CAR as FORD
|
||||
from selfdrive.car.gm.values import CAR as GM
|
||||
from selfdrive.car.honda.values import CAR as HONDA
|
||||
from selfdrive.car.hyundai.values import CAR as HYUNDAI
|
||||
from selfdrive.car.nissan.values import CAR as NISSAN
|
||||
|
||||
from selfdrive.car.subaru.values import CAR as SUBARU
|
||||
from selfdrive.car.toyota.values import CAR as TOYOTA
|
||||
from selfdrive.car.volkswagen.values import CAR as VOLKSWAGEN
|
||||
|
||||
os.environ['NOCRASH'] = '1'
|
||||
|
||||
@@ -363,7 +364,7 @@ routes = {
|
||||
},
|
||||
}
|
||||
|
||||
passive_routes = [
|
||||
passive_routes: List[str] = [
|
||||
]
|
||||
|
||||
forced_dashcam_routes = [
|
||||
@@ -436,7 +437,7 @@ if __name__ == "__main__":
|
||||
|
||||
os.environ['SKIP_FW_QUERY'] = "1"
|
||||
if checks.get('fingerprintSource', None) == 'fixed':
|
||||
os.environ['FINGERPRINT'] = checks['carFingerprint']
|
||||
os.environ['FINGERPRINT'] = cast(str, checks['carFingerprint'])
|
||||
else:
|
||||
os.environ['FINGERPRINT'] = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user