Acceleration profiles

Added toggle to use DragonPilot's acceleration profiles.

Credit goes to DragonPilot!

https: //github.com/dragonpilot-community/dragonpilot
Co-Authored-By: eFini <16603033+efinilan@users.noreply.github.com>
Co-Authored-By: Kumar <36933347+rav4kumar@users.noreply.github.com>
This commit is contained in:
FrogAi
2024-01-12 22:39:30 -07:00
parent 7308c1b35c
commit 3d6097b6a6
35 changed files with 141 additions and 47 deletions

View File

@@ -35,7 +35,7 @@ class CarController:
self.lkas_enabled_last = False
self.steer_alert_last = False
def update(self, CC, CS, now_nanos):
def update(self, CC, CS, now_nanos, sport_plus):
can_sends = []
actuators = CC.actuators
@@ -85,7 +85,10 @@ class CarController:
# send acc msg at 50Hz
if self.CP.openpilotLongitudinalControl and (self.frame % CarControllerParams.ACC_CONTROL_STEP) == 0:
# Both gas and accel are in m/s^2, accel is used solely for braking
accel = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)
if sport_plus:
accel = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX_PLUS)
else:
accel = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)
gas = accel
if not CC.longActive or gas < CarControllerParams.MIN_GAS:
gas = CarControllerParams.INACTIVE_GAS

View File

@@ -112,5 +112,5 @@ class CarInterface(CarInterfaceBase):
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)
def apply(self, c, now_nanos, sport_plus):
return self.CC.update(c, self.CS, now_nanos, sport_plus)

View File

@@ -32,6 +32,7 @@ class CarControllerParams:
CURVATURE_ERROR = 0.002 # ~6 degrees at 10 m/s, ~10 degrees at 35 m/s
ACCEL_MAX = 2.0 # m/s^2 max acceleration
ACCEL_MAX_PLUS = 4.0 # m/s^2 max acceleration
ACCEL_MIN = -3.5 # m/s^2 max deceleration
MIN_GAS = -0.5
INACTIVE_GAS = -5.0