diff --git a/opendbc_repo b/opendbc_repo index 400609b68..8d855e63d 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 400609b68644fb0b324bf56791e5469c39fdc4a9 +Subproject commit 8d855e63d012789ce7acd4d110965315658d5a10 diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index e756cfc6a..5aa2491b9 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -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 diff --git a/selfdrive/controls/lib/latcontrol_curvature.py b/selfdrive/controls/lib/latcontrol_curvature.py index 7f0a86453..e56e8c3f7 100644 --- a/selfdrive/controls/lib/latcontrol_curvature.py +++ b/selfdrive/controls/lib/latcontrol_curvature.py @@ -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 diff --git a/selfdrive/controls/lib/latcontrol_curvature_pid_backup.py b/selfdrive/controls/lib/latcontrol_curvature_pid_backup.py new file mode 100644 index 000000000..50eb23bf5 --- /dev/null +++ b/selfdrive/controls/lib/latcontrol_curvature_pid_backup.py @@ -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