selfdrive/car: ban common (#33210)
* ban all of common & copy numpy_fast * add numpy_fast * these are okay * and ban controls * better name * Conversions * do utils, kalman * clean up * sorting * don't forgetpull/33214/head
parent
a4de8739e9
commit
8d961a12e5
41 changed files with 136 additions and 70 deletions
@ -1,11 +0,0 @@ |
|||||||
class Freezable: |
|
||||||
_frozen: bool = False |
|
||||||
|
|
||||||
def freeze(self): |
|
||||||
if not self._frozen: |
|
||||||
self._frozen = True |
|
||||||
|
|
||||||
def __setattr__(self, *args, **kwargs): |
|
||||||
if self._frozen: |
|
||||||
raise Exception("cannot modify frozen object") |
|
||||||
super().__setattr__(*args, **kwargs) |
|
@ -0,0 +1,19 @@ |
|||||||
|
import numpy as np |
||||||
|
|
||||||
|
class Conversions: |
||||||
|
# Speed |
||||||
|
MPH_TO_KPH = 1.609344 |
||||||
|
KPH_TO_MPH = 1. / MPH_TO_KPH |
||||||
|
MS_TO_KPH = 3.6 |
||||||
|
KPH_TO_MS = 1. / MS_TO_KPH |
||||||
|
MS_TO_MPH = MS_TO_KPH * KPH_TO_MPH |
||||||
|
MPH_TO_MS = MPH_TO_KPH * KPH_TO_MS |
||||||
|
MS_TO_KNOTS = 1.9438 |
||||||
|
KNOTS_TO_MS = 1. / MS_TO_KNOTS |
||||||
|
|
||||||
|
# Angle |
||||||
|
DEG_TO_RAD = np.pi / 180. |
||||||
|
RAD_TO_DEG = 1. / DEG_TO_RAD |
||||||
|
|
||||||
|
# Mass |
||||||
|
LB_TO_KG = 0.453592 |
@ -0,0 +1,18 @@ |
|||||||
|
class FirstOrderFilter: |
||||||
|
# first order filter |
||||||
|
def __init__(self, x0, rc, dt, initialized=True): |
||||||
|
self.x = x0 |
||||||
|
self.dt = dt |
||||||
|
self.update_alpha(rc) |
||||||
|
self.initialized = initialized |
||||||
|
|
||||||
|
def update_alpha(self, rc): |
||||||
|
self.alpha = self.dt / (rc + self.dt) |
||||||
|
|
||||||
|
def update(self, x): |
||||||
|
if self.initialized: |
||||||
|
self.x = (1. - self.alpha) * self.x + self.alpha * x |
||||||
|
else: |
||||||
|
self.initialized = True |
||||||
|
self.x = x |
||||||
|
return self.x |
@ -0,0 +1,22 @@ |
|||||||
|
def clip(x, lo, hi): |
||||||
|
return max(lo, min(hi, x)) |
||||||
|
|
||||||
|
|
||||||
|
def interp(x, xp, fp): |
||||||
|
N = len(xp) |
||||||
|
|
||||||
|
def get_interp(xv): |
||||||
|
hi = 0 |
||||||
|
while hi < N and xv > xp[hi]: |
||||||
|
hi += 1 |
||||||
|
low = hi - 1 |
||||||
|
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) |
||||||
|
|
||||||
|
|
||||||
|
def mean(x): |
||||||
|
return sum(x) / len(x) |
||||||
|
|
Loading…
Reference in new issue