mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-04 15:23:42 +08:00
Merge pull request #3 from infiniteCable2/corr_car_contr_no_roll
Remove Curvature PID Correction
This commit is contained in:
+1
-1
Submodule opendbc_repo updated: 400609b686...8d855e63d0
@@ -172,7 +172,7 @@ class Controls(ControlsExt, ModelStateBase):
|
||||
steer, steeringAngleDeg, curvature, lac_log = self.LaC.update(CC.latActive, CS, self.VM, lp,
|
||||
self.steer_limited_by_safety, self.desired_curvature,
|
||||
self.calibrated_pose, curvature_limited) # TODO what if not available
|
||||
actuators.curvature = float(curvature) if self.enable_curvature_controller else self.desired_curvature
|
||||
actuators.curvature = float(curvature)
|
||||
actuators.torque = float(steer)
|
||||
actuators.steeringAngleDeg = float(steeringAngleDeg)
|
||||
# Ensure no NaNs/Infs
|
||||
@@ -193,6 +193,7 @@ class Controls(ControlsExt, ModelStateBase):
|
||||
CC.curvatureControllerActive = self.enable_curvature_controller # for car controller curvature correction activation
|
||||
CC.currentCurvatureNoRoll = self.curvature_no_roll
|
||||
CC.rollDEPRECATED = self.roll # for lateral iso limit calculation
|
||||
CC.steerLimited = self.steer_limited_by_safety
|
||||
|
||||
# Orientation and angle rates can be useful for carcontroller
|
||||
# Only calibrated (car) frame is relevant for the carcontroller
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import math
|
||||
import numpy as np
|
||||
|
||||
from cereal import log
|
||||
from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
||||
from openpilot.common.pid_mu import MultiplicativeUnwindPID
|
||||
|
||||
CURVATURE_SATURATION_THRESHOLD = 5e-4 # rad/m
|
||||
|
||||
@@ -11,46 +9,19 @@ CURVATURE_SATURATION_THRESHOLD = 5e-4 # rad/m
|
||||
class LatControlCurvature(LatControl):
|
||||
def __init__(self, CP, CP_SP, CI):
|
||||
super().__init__(CP, CP_SP, CI)
|
||||
self.useCarSteerCurvature = CP.useCarSteerCurvature
|
||||
self.pid = MultiplicativeUnwindPID((CP.lateralTuning.pid.kpBP, CP.lateralTuning.pid.kpV),
|
||||
(CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV),
|
||||
k_f=CP.lateralTuning.pid.kf, pos_limit=self.curvature_max, neg_limit=-self.curvature_max)
|
||||
|
||||
def reset(self):
|
||||
super().reset()
|
||||
self.pid.reset()
|
||||
|
||||
def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, calibrated_pose, curvature_limited):
|
||||
pid_log = log.ControlsState.LateralCurvatureState.new_message()
|
||||
if not active:
|
||||
output_curvature = 0.0
|
||||
pid_log.active = False
|
||||
self.pid.reset()
|
||||
else:
|
||||
roll_compensation = -VM.roll_compensation(params.roll, CS.vEgo)
|
||||
actual_curvature_vm_no_roll = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, 0.)
|
||||
actual_curvature_vm = actual_curvature_vm_no_roll - roll_compensation
|
||||
assert calibrated_pose is not None
|
||||
actual_curvature_pose = calibrated_pose.angular_velocity.yaw / CS.vEgo
|
||||
actual_curvature = np.interp(CS.vEgo, [2.0, 5.0], [actual_curvature_vm, actual_curvature_pose])
|
||||
curvature_log = log.ControlsState.LateralCurvatureState.new_message()
|
||||
actual_curvature = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll)
|
||||
output_curvature = desired_curvature
|
||||
|
||||
curvature_log.active = active
|
||||
curvature_log.output = float(output_curvature)
|
||||
curvature_log.actualCurvature = float(actual_curvature)
|
||||
curvature_log.desiredCurvature = float(output_curvature)
|
||||
curvature_log.saturated = bool(self._check_saturation(steer_limited_by_safety, CS, False, curvature_limited)) if active else False
|
||||
|
||||
desired_curvature_corr = desired_curvature - roll_compensation
|
||||
|
||||
pid_log.error = float(desired_curvature - actual_curvature)
|
||||
freeze_integrator = steer_limited_by_safety or CS.vEgo < 5 or CS.steeringPressed
|
||||
|
||||
pid_curvature = self.pid.update(pid_log.error, feedforward=desired_curvature_corr, speed=CS.vEgo,
|
||||
freeze_integrator=freeze_integrator, override=CS.steeringPressed)
|
||||
|
||||
output_curvature = pid_curvature + (CS.steeringCurvature - actual_curvature_vm_no_roll) if self.useCarSteerCurvature else pid_curvature
|
||||
|
||||
pid_log.active = True
|
||||
pid_log.p = float(self.pid.p)
|
||||
pid_log.i = float(self.pid.i)
|
||||
pid_log.f = float(self.pid.f)
|
||||
pid_log.output = float(output_curvature)
|
||||
pid_log.actualCurvature = float(actual_curvature)
|
||||
pid_log.desiredCurvature = float(desired_curvature)
|
||||
pid_log.saturated = bool(self._check_saturation(steer_limited_by_safety, CS, False, curvature_limited))
|
||||
|
||||
return 0.0, 0.0, output_curvature, pid_log
|
||||
return 0.0, 0.0, output_curvature, curvature_log
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#import math
|
||||
#import numpy as np
|
||||
#
|
||||
#from cereal import log
|
||||
#from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
||||
#from openpilot.common.pid_mu import MultiplicativeUnwindPID
|
||||
#
|
||||
#CURVATURE_SATURATION_THRESHOLD = 5e-4 # rad/m
|
||||
#
|
||||
#
|
||||
#class LatControlCurvature(LatControl):
|
||||
# def __init__(self, CP, CP_SP, CI):
|
||||
# super().__init__(CP, CP_SP, CI)
|
||||
# self.useCarSteerCurvature = CP.useCarSteerCurvature
|
||||
# self.pid = MultiplicativeUnwindPID((CP.lateralTuning.pid.kpBP, CP.lateralTuning.pid.kpV),
|
||||
# (CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV),
|
||||
# k_f=CP.lateralTuning.pid.kf, pos_limit=self.curvature_max, neg_limit=-self.curvature_max)
|
||||
#
|
||||
# def reset(self):
|
||||
# super().reset()
|
||||
# self.pid.reset()
|
||||
#
|
||||
# def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, calibrated_pose, curvature_limited):
|
||||
# pid_log = log.ControlsState.LateralCurvatureState.new_message()
|
||||
# if not active:
|
||||
# output_curvature = 0.0
|
||||
# pid_log.active = False
|
||||
# self.pid.reset()
|
||||
# else:
|
||||
# roll_compensation = -VM.roll_compensation(params.roll, CS.vEgo)
|
||||
# actual_curvature_vm_no_roll = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, 0.)
|
||||
# actual_curvature_vm = actual_curvature_vm_no_roll - roll_compensation
|
||||
# assert calibrated_pose is not None
|
||||
# actual_curvature_pose = calibrated_pose.angular_velocity.yaw / CS.vEgo
|
||||
# actual_curvature = np.interp(CS.vEgo, [2.0, 5.0], [actual_curvature_vm, actual_curvature_pose])
|
||||
#
|
||||
# desired_curvature_corr = desired_curvature - roll_compensation
|
||||
#
|
||||
# pid_log.error = float(desired_curvature - actual_curvature)
|
||||
# freeze_integrator = steer_limited_by_safety or CS.vEgo < 5 or CS.steeringPressed
|
||||
#
|
||||
# pid_curvature = self.pid.update(pid_log.error, feedforward=desired_curvature_corr, speed=CS.vEgo,
|
||||
# freeze_integrator=freeze_integrator, override=CS.steeringPressed)
|
||||
#
|
||||
# output_curvature = pid_curvature + (CS.steeringCurvature - actual_curvature_vm_no_roll) if self.useCarSteerCurvature else pid_curvature
|
||||
#
|
||||
# pid_log.active = True
|
||||
# pid_log.p = float(self.pid.p)
|
||||
# pid_log.i = float(self.pid.i)
|
||||
# pid_log.f = float(self.pid.f)
|
||||
# pid_log.output = float(output_curvature)
|
||||
# pid_log.actualCurvature = float(actual_curvature)
|
||||
# pid_log.desiredCurvature = float(desired_curvature)
|
||||
# pid_log.saturated = bool(self._check_saturation(steer_limited_by_safety, CS, False, curvature_limited))
|
||||
#
|
||||
# return 0.0, 0.0, output_curvature, pid_log
|
||||
Reference in New Issue
Block a user