Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion leads/comm/prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def receive(self, chunk_size: int = 512) -> bytes | None:
msg += (chunk := self._require_open_socket().recv(chunk_size))
return self.with_remainder(msg)
except IOError:
return
return None

@_override
def send(self, msg: bytes) -> None:
Expand Down
10 changes: 5 additions & 5 deletions leads/data_persistence/analyzer/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self) -> None:
def complete(self, *rows: dict[str, _Any], backward: bool = False) -> dict[str, _Any] | None:
row = rows[0]
if SpeedInferenceBase.skip(row):
return
return None
speed = None
if not speed_invalid(s := row["front_wheel_speed"]):
speed = s
Expand All @@ -84,7 +84,7 @@ def complete(self, *rows: dict[str, _Any], backward: bool = False) -> dict[str,
if (SpeedInferenceBase.skip(target) or time_invalid(t_0) or
time_invalid(t) or speed_invalid(v_0) or
acceleration_invalid(a_0)):
return
return None
a = target["forward_acceleration"]
if acceleration_invalid(a):
a = a_0
Expand Down Expand Up @@ -205,11 +205,11 @@ def complete(self, *rows: dict[str, _Any], backward: bool = False) -> dict[str,
t_0, t, v_0, s_0 = base["t"], target["t"], base["speed"], base["mileage"]
if (MileageInferenceBase.skip(target) or time_invalid(t_0) or time_invalid(t) or
speed_invalid(v_0) or mileage_invalid(s_0)):
return
return None
v = target["speed"]
if speed_invalid(v):
v = v_0
return {"mileage": s_0 + .00000125 * (v_0 + v) * (t - t_0) / 9}
return {"mileage": s_0 + 125e-8 * (v_0 + v) * (t - t_0) / 9}


class MileageInferenceByGPSPosition(MileageInferenceBase):
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(self, *channels: _Literal["front", "left", "right", "rear"]) -> Non
@_override
def complete(self, *rows: dict[str, _Any], backward: bool = False) -> dict[str, _Any] | None:
if backward:
return
return None
target, base = rows
original_target = target.copy()
t_0, t = target["t"], base["t"]
Expand Down
4 changes: 2 additions & 2 deletions leads/data_persistence/analyzer/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def unit(row: dict[str, _Any], i: int) -> None:
else:
path.append(p)

self.foreach(asserted_unit if asserted else unit, True, not asserted)
self.foreach(asserted_unit if asserted else unit, skip_gps_invalid_rows=not asserted)

def suggest_on_lap(self, lap_index: int) -> tuple[str, str]:
a, b, duration, distance, avg_speed = self._laps[lap_index]
Expand Down Expand Up @@ -276,7 +276,7 @@ def unit(row: dict[str, _Any], index: int) -> None:
if self._max_lap_y is None or y > self._max_lap_y:
self._max_lap_y = y

self.foreach(unit, True, True)
self.foreach(unit, skip_gps_invalid_rows=True)
far = max(self._max_lap_x, self._max_lap_y)
self._lap_x.append(far)
self._lap_y.append(far)
Expand Down
2 changes: 1 addition & 1 deletion leads/ltm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def _load_ltm() -> None:
global _ltm
with open(f"{_abspath(__file__)[:-6]}_ltm/core", "r") as f:
with open(f"{_abspath(__file__)[:-6]}_ltm/core") as f:
ltm_content = f.read()
if not (ltm_content.startswith("{") and ltm_content.endswith("}")):
ltm_content = "{}"
Expand Down
11 changes: 6 additions & 5 deletions leads_arduino/wheel_speed_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def rpm2kmh(rpm: float, wheel_circumference: float) -> float:
:param wheel_circumference: wheel circumference in centimeters
:return: speed in kilometers per hour
"""
return rpm * wheel_circumference * .0006
return rpm * wheel_circumference * 6e-4


class WheelSpeedSensor(_Device):
Expand Down Expand Up @@ -56,19 +56,20 @@ def update(self, data: str) -> None:
if self._accelerometer and self._last_acceleration:
a = self._accelerometer.read().linear().forward_acceleration
v = (a + self._last_acceleration) * 1.8 * (t - self._last_valid)
if abs((ws - self._wheel_speed - v) / (v + .0000000001)) > 1.5:
# add a small constant to avoid zero division
if abs((ws - self._wheel_speed - v) / (v + 1e-10)) > 1.5:
return
self._last_acceleration = a
self._wheel_speed = ws
self._last_valid = t
if self._odometer:
self._odometer.write(self._wheel_circumference * .00001)
self._odometer.write(self._wheel_circumference * 1e-5)

@_override
def read(self) -> float:
"""
:return: speed in kilometers per hour
"""
# add .0000000001 to avoid zero division
r = rpm2kmh(60 / (.0000000001 + _time() - self._last_valid), self._wheel_circumference) / self._num_divisions
# add a small constant to avoid zero division
r = rpm2kmh(60 / (1e-10 + _time() - self._last_valid), self._wheel_circumference) / self._num_divisions
return 0 if r < .1 else r if r < 5 else self._wheel_speed
2 changes: 1 addition & 1 deletion leads_comm_serial/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def receive(self, chunk_size: int = 1) -> bytes | None:
msg += (chunk := self._require_open_serial().read(chunk_size))
return self.with_remainder(msg)
except IOError:
return
return None

@_override
def send(self, msg: bytes | _Literal[b"disconnect"]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions leads_gui/performance_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def net_delay(self) -> float:
return float(_average(self._net_delay_seq))

def record_frame(self, last_interval: float) -> None:
# add .0000000001 to avoid zero division
# add a small constant to avoid zero division
self._time_seq.append(t := _time())
self._delay_seq.append(delay := .0000000001 + t - self._last_frame)
self._delay_seq.append(delay := 1e-10 + t - self._last_frame)
self._net_delay_seq.append(delay - last_interval)
self._model = _poly1d(_polyfit(self._time_seq, self._net_delay_seq, 5))
self._last_frame = t
Expand Down
2 changes: 1 addition & 1 deletion leads_video/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def get_camera(tag: str, required_type: type[Camera] = Camera) -> Camera | None:
if not _has_device(tag):
return
return None
cam = _get_device(tag)
if not isinstance(cam, required_type):
raise TypeError(f"Device \"{tag}\" is supposed to be a camera")
Expand Down