base LatControl class (#21967)
* base LatControl class, move sat check out of pid.py clean up clean up * fix * global variable for min control speed * nicer name * unify latcontrol class init arguments * add to release files * saturated if close to limit * move angle mode saturation checks into class * check_saturation function takes in current saturated status undo * apply latcontrol_angle's active checking to all controllers * clean up * move those back * make abstract baseclass * add test for saturation * keep clip * update ref * fix static analysis Co-authored-by: Willem Melching <willem.melching@gmail.com>pull/23243/head
parent
1d4191956b
commit
9de8f8cd8c
14 changed files with 115 additions and 105 deletions
@ -0,0 +1,28 @@ |
|||||||
|
from abc import abstractmethod, ABC |
||||||
|
|
||||||
|
from common.realtime import DT_CTRL |
||||||
|
from common.numpy_fast import clip |
||||||
|
|
||||||
|
MIN_STEER_SPEED = 0.3 |
||||||
|
|
||||||
|
|
||||||
|
class LatControl(ABC): |
||||||
|
def __init__(self, CP, CI): |
||||||
|
self.sat_count_rate = 1.0 * DT_CTRL |
||||||
|
self.sat_limit = CP.steerLimitTimer |
||||||
|
self.sat_count = 0. |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def update(self, active, CS, CP, VM, params, last_actuators, desired_curvature, desired_curvature_rate): |
||||||
|
pass |
||||||
|
|
||||||
|
def reset(self): |
||||||
|
self.sat_count = 0. |
||||||
|
|
||||||
|
def _check_saturation(self, saturated, CS): |
||||||
|
if saturated and CS.vEgo > 10. and not CS.steeringRateLimited and not CS.steeringPressed: |
||||||
|
self.sat_count += self.sat_count_rate |
||||||
|
else: |
||||||
|
self.sat_count -= self.sat_count_rate |
||||||
|
self.sat_count = clip(self.sat_count, 0.0, 1.0) |
||||||
|
return self.sat_count > self.sat_limit |
@ -0,0 +1,44 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
import unittest |
||||||
|
|
||||||
|
from parameterized import parameterized |
||||||
|
|
||||||
|
from cereal import car, log |
||||||
|
from selfdrive.car.car_helpers import interfaces |
||||||
|
from selfdrive.car.honda.values import CAR as HONDA |
||||||
|
from selfdrive.car.toyota.values import CAR as TOYOTA |
||||||
|
from selfdrive.car.nissan.values import CAR as NISSAN |
||||||
|
from selfdrive.controls.lib.latcontrol_pid import LatControlPID |
||||||
|
from selfdrive.controls.lib.latcontrol_lqr import LatControlLQR |
||||||
|
from selfdrive.controls.lib.latcontrol_indi import LatControlINDI |
||||||
|
from selfdrive.controls.lib.latcontrol_angle import LatControlAngle |
||||||
|
from selfdrive.controls.lib.vehicle_model import VehicleModel |
||||||
|
|
||||||
|
|
||||||
|
class TestLatControl(unittest.TestCase): |
||||||
|
|
||||||
|
@parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlLQR), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)]) |
||||||
|
def test_saturation(self, car_name, controller): |
||||||
|
CarInterface, CarController, CarState = interfaces[car_name] |
||||||
|
CP = CarInterface.get_params(car_name) |
||||||
|
CI = CarInterface(CP, CarController, CarState) |
||||||
|
VM = VehicleModel(CP) |
||||||
|
|
||||||
|
controller = controller(CP, CI) |
||||||
|
|
||||||
|
|
||||||
|
CS = car.CarState.new_message() |
||||||
|
CS.vEgo = 30 |
||||||
|
|
||||||
|
last_actuators = car.CarControl.Actuators.new_message() |
||||||
|
|
||||||
|
params = log.LiveParametersData.new_message() |
||||||
|
|
||||||
|
for _ in range(1000): |
||||||
|
_, _, lac_log = controller.update(True, CS, CP, VM, params, last_actuators, 1, 0) |
||||||
|
|
||||||
|
self.assertTrue(lac_log.saturated) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
unittest.main() |
@ -1 +1 @@ |
|||||||
0c0b75ef36ef657208995a5e474ce7dcdc0fc00b |
2cd40ceff3c326a45c6ddf5f23e7ae2883bf55a2 |
Loading…
Reference in new issue