Skip to content

Commit

Permalink
Add Volt NNFF
Browse files Browse the repository at this point in the history
  • Loading branch information
nworb-cire committed Aug 10, 2024
1 parent f036071 commit fb9db2f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
28 changes: 7 additions & 21 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
import json
import os
from cereal import car
from math import fabs, exp
from math import exp
from panda import Panda

from openpilot.common.basedir import BASEDIR
Expand Down Expand Up @@ -38,19 +39,6 @@ class CarInterface(CarInterfaceBase):
def get_pid_accel_limits(CP, current_speed, cruise_speed):
return CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX

# Determined by iteratively plotting and minimizing error for f(angle, speed) = steer.
@staticmethod
def get_steer_feedforward_volt(desired_angle, v_ego):
desired_angle *= 0.02904609
sigmoid = desired_angle / (1 + fabs(desired_angle))
return 0.10006696 * sigmoid * (v_ego + 3.12485927)

def get_steer_feedforward_function(self):
if self.CP.carFingerprint in (CAR.CHEVROLET_VOLT, CAR.CHEVROLET_VOLT_CC):
return self.get_steer_feedforward_volt
else:
return CarInterfaceBase.get_steer_feedforward_default

def torque_from_lateral_accel_siglin(self, latcontrol_inputs: LatControlInputs, torque_params: car.CarParams.LateralTorqueTuning, lateral_accel_error: float,
lateral_accel_deadzone: float, friction_compensation: bool, gravity_adjusted: bool) -> float:
friction = get_friction(lateral_accel_error, lateral_accel_deadzone, FRICTION_THRESHOLD, torque_params, friction_compensation)
Expand Down Expand Up @@ -82,7 +70,9 @@ def torque_from_lateral_accel_neural(self, latcontrol_inputs: LatControlInputs,
return float(self.neural_ff_model.predict(inputs)) + friction

def torque_from_lateral_accel(self) -> TorqueFromLateralAccelCallbackType:
if self.CP.carFingerprint in (CAR.CHEVROLET_BOLT_EUV, CAR.CHEVROLET_BOLT_CC):
with open(NEURAL_PARAMS_PATH) as f:
neural_ff_cars = json.load(f).keys()
if self.CP.carFingerprint in neural_ff_cars:
self.neural_ff_model = NanoFFModel(NEURAL_PARAMS_PATH, self.CP.carFingerprint)
return self.torque_from_lateral_accel_neural
elif self.CP.carFingerprint in NON_LINEAR_TORQUE_PARAMS:
Expand Down Expand Up @@ -162,14 +152,10 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
ret.radarTimeStep = 0.0667 # GM radar runs at 15Hz instead of standard 20Hz
ret.longitudinalActuatorDelay = 0.5 # large delay to initially start braking

if candidate in (CAR.CHEVROLET_VOLT, CAR.CHEVROLET_VOLT_CC):
if candidate == CAR.CHEVROLET_VOLT:
ret.minEnableSpeed = -1
ret.lateralTuning.pid.kpBP = [0., 40.]
ret.lateralTuning.pid.kpV = [0., 0.17]
ret.lateralTuning.pid.kiBP = [0.]
ret.lateralTuning.pid.kiV = [0.]
ret.lateralTuning.pid.kf = 1. # get_steer_feedforward_volt()
ret.steerActuatorDelay = 0.2
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)

elif candidate == CAR.GMC_ACADIA:
ret.minEnableSpeed = -1. # engage speed is decided by pcm
Expand Down
8 changes: 0 additions & 8 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ def _get_params(ret: car.CarParams, candidate, fingerprint: dict[int, dict[int,
def init(CP: car.CarParams, can_recv: CanRecvCallable, can_send: CanSendCallable):
pass

@staticmethod
def get_steer_feedforward_default(desired_angle, v_ego):
# Proportional to realigning tire momentum: lateral acceleration.
return desired_angle * (v_ego**2)

def get_steer_feedforward_function(self):
return self.get_steer_feedforward_default

def torque_from_lateral_accel_linear(self, latcontrol_inputs: LatControlInputs, torque_params: car.CarParams.LateralTorqueTuning,
lateral_accel_error: float, lateral_accel_deadzone: float, friction_compensation: bool, gravity_adjusted: bool) -> float:
# The default is a linear relationship between torque and lateral acceleration (accounting for road roll and steering friction)
Expand Down
Loading

0 comments on commit fb9db2f

Please sign in to comment.