2020-01-17 12:48:30 -08:00
|
|
|
#!/usr/bin/env python3
|
2021-03-12 06:08:51 +01:00
|
|
|
import math
|
2025-08-02 00:08:18 -07:00
|
|
|
from numbers import Number
|
2021-09-06 18:45:59 -07:00
|
|
|
|
2025-05-15 20:13:40 -07:00
|
|
|
from cereal import car, log
|
2024-09-06 17:16:32 -07:00
|
|
|
import cereal.messaging as messaging
|
2025-08-02 20:20:18 +02:00
|
|
|
from openpilot.common.constants import CV
|
2024-02-21 14:58:04 -05:00
|
|
|
from openpilot.common.params import Params
|
2025-10-08 14:39:05 -07:00
|
|
|
from openpilot.common.realtime import config_realtime_process, DT_CTRL, Priority, Ratekeeper
|
2023-12-06 17:27:51 -08:00
|
|
|
from openpilot.common.swaglog import cloudlog
|
2024-02-21 14:58:04 -05:00
|
|
|
|
2025-03-14 22:37:49 -07:00
|
|
|
from opendbc.car.car_helpers import interfaces
|
2025-02-26 19:35:43 -06:00
|
|
|
from opendbc.car.vehicle_model import VehicleModel
|
2024-09-06 17:16:32 -07:00
|
|
|
from openpilot.selfdrive.controls.lib.drive_helpers import clip_curvature
|
2025-03-25 14:00:24 -07:00
|
|
|
from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID
|
|
|
|
|
from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle, STEER_ANGLE_SATURATION_THRESHOLD
|
|
|
|
|
from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque
|
2024-02-21 14:58:04 -05:00
|
|
|
from openpilot.selfdrive.controls.lib.longcontrol import LongControl
|
2025-10-08 18:29:54 -07:00
|
|
|
from openpilot.selfdrive.modeld.modeld import LAT_SMOOTH_SECONDS
|
2024-08-13 21:11:16 -07:00
|
|
|
from openpilot.selfdrive.locationd.helpers import PoseCalibrator, Pose
|
2024-02-21 14:58:04 -05:00
|
|
|
|
2025-05-15 20:13:40 -07:00
|
|
|
from openpilot.sunnypilot.selfdrive.controls.controlsd_ext import ControlsExt
|
|
|
|
|
|
2024-08-31 18:48:17 -07:00
|
|
|
State = log.SelfdriveState.OpenpilotState
|
2024-01-21 12:09:48 -08:00
|
|
|
LaneChangeState = log.LaneChangeState
|
|
|
|
|
LaneChangeDirection = log.LaneChangeDirection
|
2020-01-17 12:48:30 -08:00
|
|
|
|
2022-04-04 17:13:29 -07:00
|
|
|
ACTUATOR_FIELDS = tuple(car.CarControl.Actuators.schema.fields.keys())
|
|
|
|
|
|
2025-02-27 18:12:55 -06:00
|
|
|
|
2025-11-29 03:58:58 -05:00
|
|
|
class Controls(ControlsExt):
|
2024-09-06 17:16:32 -07:00
|
|
|
def __init__(self) -> None:
|
2024-03-04 12:53:42 -05:00
|
|
|
self.params = Params()
|
2024-09-06 17:16:32 -07:00
|
|
|
cloudlog.info("controlsd is waiting for CarParams")
|
|
|
|
|
self.CP = messaging.log_from_bytes(self.params.get("CarParams", block=True), car.CarParams)
|
|
|
|
|
cloudlog.info("controlsd got CarParams")
|
2024-03-04 12:53:42 -05:00
|
|
|
|
2025-08-09 22:50:29 -04:00
|
|
|
# Initialize sunnypilot controlsd extension and base model state
|
2025-05-24 16:20:57 -04:00
|
|
|
ControlsExt.__init__(self, self.CP, self.params)
|
2025-01-22 14:22:32 -05:00
|
|
|
|
2025-03-17 09:11:51 +01:00
|
|
|
self.CI = interfaces[self.CP.carFingerprint](self.CP, self.CP_SP)
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2025-10-08 18:29:54 -07:00
|
|
|
self.sm = messaging.SubMaster(['liveDelay', 'liveParameters', 'liveTorqueParameters', 'modelV2', 'selfdriveState',
|
2024-09-06 17:16:32 -07:00
|
|
|
'liveCalibration', 'livePose', 'longitudinalPlan', 'carState', 'carOutput',
|
2025-06-24 10:28:49 -06:00
|
|
|
'driverMonitoringState', 'onroadEvents', 'driverAssistance', 'liveDelay'] + self.sm_services_ext,
|
2025-01-22 14:22:32 -05:00
|
|
|
poll='selfdriveState')
|
2025-05-15 20:13:40 -07:00
|
|
|
self.pm = messaging.PubMaster(['carControl', 'controlsState'] + self.pm_services_ext)
|
2021-05-19 21:28:16 -07:00
|
|
|
|
2025-08-11 14:25:29 -07:00
|
|
|
self.steer_limited_by_safety = False
|
2025-03-26 22:41:26 -07:00
|
|
|
self.curvature = 0.0
|
2024-09-06 17:16:32 -07:00
|
|
|
self.desired_curvature = 0.0
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2024-08-13 21:11:16 -07:00
|
|
|
self.pose_calibrator = PoseCalibrator()
|
2025-02-27 18:12:55 -06:00
|
|
|
self.calibrated_pose: Pose | None = None
|
2024-08-13 21:11:16 -07:00
|
|
|
|
2025-09-30 22:37:13 -04:00
|
|
|
self.LoC = LongControl(self.CP, self.CP_SP)
|
2020-05-12 15:06:48 -07:00
|
|
|
self.VM = VehicleModel(self.CP)
|
2022-05-12 14:08:11 +02:00
|
|
|
self.LaC: LatControl
|
2021-03-12 06:08:51 +01:00
|
|
|
if self.CP.steerControlType == car.CarParams.SteerControlType.angle:
|
2025-11-16 02:00:29 -05:00
|
|
|
self.LaC = LatControlAngle(self.CP, self.CP_SP, self.CI, DT_CTRL)
|
2021-03-12 06:08:51 +01:00
|
|
|
elif self.CP.lateralTuning.which() == 'pid':
|
2025-11-16 02:00:29 -05:00
|
|
|
self.LaC = LatControlPID(self.CP, self.CP_SP, self.CI, DT_CTRL)
|
2022-04-19 19:34:31 -07:00
|
|
|
elif self.CP.lateralTuning.which() == 'torque':
|
2025-11-16 02:00:29 -05:00
|
|
|
self.LaC = LatControlTorque(self.CP, self.CP_SP, self.CI, DT_CTRL)
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
def update(self):
|
|
|
|
|
self.sm.update(15)
|
2024-08-13 21:11:16 -07:00
|
|
|
if self.sm.updated["liveCalibration"]:
|
|
|
|
|
self.pose_calibrator.feed_live_calib(self.sm['liveCalibration'])
|
|
|
|
|
if self.sm.updated["livePose"]:
|
|
|
|
|
device_pose = Pose.from_live_pose(self.sm['livePose'])
|
|
|
|
|
self.calibrated_pose = self.pose_calibrator.build_calibrated_pose(device_pose)
|
|
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
def state_control(self):
|
|
|
|
|
CS = self.sm['carState']
|
2020-01-17 12:48:30 -08:00
|
|
|
|
2021-03-12 06:08:51 +01:00
|
|
|
# Update VehicleModel
|
2022-10-25 15:51:39 -07:00
|
|
|
lp = self.sm['liveParameters']
|
|
|
|
|
x = max(lp.stiffnessFactor, 0.1)
|
|
|
|
|
sr = max(lp.steerRatio, 0.1)
|
2021-03-12 06:08:51 +01:00
|
|
|
self.VM.update_params(x, sr)
|
|
|
|
|
|
2025-03-26 22:41:26 -07:00
|
|
|
steer_angle_without_offset = math.radians(CS.steeringAngleDeg - lp.angleOffsetDeg)
|
|
|
|
|
self.curvature = -self.VM.calc_curvature(steer_angle_without_offset, CS.vEgo, lp.roll)
|
|
|
|
|
|
Live torque (#25456)
* wip torqued
* add basic logic
* setup in manager
* check sanity and publish msg
* add first order filter to outputs
* wire up controlsd, and update gains
* rename intercept to offset
* add cloudlog, live values are not updated
* fix bugs, do not reset points for now
* fix crashes
* rename to main
* fix bugs, works offline
* fix float in cereal bug
* add latacc filter
* randomly choose points, approx for iid
* add variable decay
* local param to capnp instead of dict
* verify works in replay
* use torqued output in controlsd
* use in controlsd; use points from past routes
* controlsd bugfix
* filter before updating gains, needs to be replaced
* save all points to ensure smooth transition across routes, revert friction factor to 1.5
* add filters to prevent noisy low-speed data points; improve fit sanity
* add engaged buffer
* revert lat_acc thresh
* use paramsd realtime process config
* make latacc-to-torque generic, and overrideable
* move freq to 4Hz, avoid storing in np.array, don't publish points in the message
* float instead of np
* remove constant while storing pts
* rename slope, offset to lat_accet_factor, offset
* resolve issues
* use camelcase in all capnp params
* use camelcase everywhere
* reduce latacc threshold or sanity, add car_sane todo, save points properly
* add and check tag
* write param to disk at end of route
* remove args
* rebase op, cereal
* save on exit
* restore default handler
* cpu usage check
* add to process replay
* handle reset better, reduce unnecessary computation
* always publish raw values - useful for debug
* regen routes
* update refs
* checks on cache restore
* check tuning vals too
* clean that up
* reduce cpu usage
* reduce cpu usage by 75%
* cleanup
* optimize further
* handle reset condition better, don't put points in init, use only in corolla
* bump cereal after rebasing
* update refs
* Update common/params.cc
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
* remove unnecessary checks
* Update RELEASES.md
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 4fa62f146426f76c9c1c2867d9729b33ec612b59
2022-09-19 15:19:26 -07:00
|
|
|
# Update Torque Params
|
|
|
|
|
if self.CP.lateralTuning.which() == 'torque':
|
|
|
|
|
torque_params = self.sm['liveTorqueParameters']
|
|
|
|
|
if self.sm.all_checks(['liveTorqueParameters']) and torque_params.useParams:
|
2023-08-08 17:13:35 -07:00
|
|
|
self.LaC.update_live_torque_params(torque_params.latAccelFactorFiltered, torque_params.latAccelOffsetFiltered,
|
|
|
|
|
torque_params.frictionCoefficientFiltered)
|
Live torque (#25456)
* wip torqued
* add basic logic
* setup in manager
* check sanity and publish msg
* add first order filter to outputs
* wire up controlsd, and update gains
* rename intercept to offset
* add cloudlog, live values are not updated
* fix bugs, do not reset points for now
* fix crashes
* rename to main
* fix bugs, works offline
* fix float in cereal bug
* add latacc filter
* randomly choose points, approx for iid
* add variable decay
* local param to capnp instead of dict
* verify works in replay
* use torqued output in controlsd
* use in controlsd; use points from past routes
* controlsd bugfix
* filter before updating gains, needs to be replaced
* save all points to ensure smooth transition across routes, revert friction factor to 1.5
* add filters to prevent noisy low-speed data points; improve fit sanity
* add engaged buffer
* revert lat_acc thresh
* use paramsd realtime process config
* make latacc-to-torque generic, and overrideable
* move freq to 4Hz, avoid storing in np.array, don't publish points in the message
* float instead of np
* remove constant while storing pts
* rename slope, offset to lat_accet_factor, offset
* resolve issues
* use camelcase in all capnp params
* use camelcase everywhere
* reduce latacc threshold or sanity, add car_sane todo, save points properly
* add and check tag
* write param to disk at end of route
* remove args
* rebase op, cereal
* save on exit
* restore default handler
* cpu usage check
* add to process replay
* handle reset better, reduce unnecessary computation
* always publish raw values - useful for debug
* regen routes
* update refs
* checks on cache restore
* check tuning vals too
* clean that up
* reduce cpu usage
* reduce cpu usage by 75%
* cleanup
* optimize further
* handle reset condition better, don't put points in init, use only in corolla
* bump cereal after rebasing
* update refs
* Update common/params.cc
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
* remove unnecessary checks
* Update RELEASES.md
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 4fa62f146426f76c9c1c2867d9729b33ec612b59
2022-09-19 15:19:26 -07:00
|
|
|
|
2025-08-29 16:39:25 -04:00
|
|
|
self.LaC.extension.update_limits()
|
|
|
|
|
|
2025-03-20 16:01:08 -04:00
|
|
|
self.LaC.extension.update_model_v2(self.sm['modelV2'])
|
2025-08-09 22:50:29 -04:00
|
|
|
|
|
|
|
|
self.LaC.extension.update_lateral_lag(self.lat_delay)
|
2025-03-20 16:01:08 -04:00
|
|
|
|
2021-02-16 21:39:32 -08:00
|
|
|
long_plan = self.sm['longitudinalPlan']
|
2024-01-21 12:09:48 -08:00
|
|
|
model_v2 = self.sm['modelV2']
|
2020-01-17 12:48:30 -08:00
|
|
|
|
2022-03-13 20:58:44 -07:00
|
|
|
CC = car.CarControl.new_message()
|
2024-09-06 17:16:32 -07:00
|
|
|
CC.enabled = self.sm['selfdriveState'].enabled
|
2023-01-10 23:51:10 -05:00
|
|
|
|
2022-03-13 20:58:44 -07:00
|
|
|
# Check which actuators can be enabled
|
2025-03-25 14:00:24 -07:00
|
|
|
standstill = abs(CS.vEgo) <= max(self.CP.minSteerSpeed, 0.3) or CS.standstill
|
2025-01-05 02:48:02 +01:00
|
|
|
|
2025-05-15 20:13:40 -07:00
|
|
|
# Get which state to use for active lateral control
|
|
|
|
|
_lat_active = self.get_lat_active(self.sm)
|
2025-01-05 02:48:02 +01:00
|
|
|
|
2025-04-03 21:53:04 -04:00
|
|
|
CC.latActive = _lat_active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \
|
2025-03-25 14:00:24 -07:00
|
|
|
(not standstill or self.CP.steerAtStandstill)
|
2025-09-18 16:47:40 -04:00
|
|
|
CC.longActive = CC.enabled and not any(e.overrideLongitudinal for e in self.sm['onroadEvents']) and \
|
|
|
|
|
(self.CP.openpilotLongitudinalControl or not self.CP_SP.pcmCruiseSpeed)
|
2022-03-13 20:58:44 -07:00
|
|
|
|
|
|
|
|
actuators = CC.actuators
|
2021-09-06 20:14:01 -07:00
|
|
|
actuators.longControlState = self.LoC.long_control_state
|
2020-01-17 12:48:30 -08:00
|
|
|
|
2022-12-12 14:03:09 -08:00
|
|
|
# Enable blinkers while lane changing
|
2024-01-21 12:09:48 -08:00
|
|
|
if model_v2.meta.laneChangeState != LaneChangeState.off:
|
|
|
|
|
CC.leftBlinker = model_v2.meta.laneChangeDirection == LaneChangeDirection.left
|
|
|
|
|
CC.rightBlinker = model_v2.meta.laneChangeDirection == LaneChangeDirection.right
|
2022-12-12 14:03:09 -08:00
|
|
|
|
2022-03-13 20:58:44 -07:00
|
|
|
if not CC.latActive:
|
2020-05-12 15:06:48 -07:00
|
|
|
self.LaC.reset()
|
2022-03-13 20:58:44 -07:00
|
|
|
if not CC.longActive:
|
2024-06-14 00:08:58 -07:00
|
|
|
self.LoC.reset()
|
2020-01-17 12:48:30 -08:00
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
# accel PID loop
|
2025-10-28 22:13:39 -04:00
|
|
|
pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, self.CP_SP, CS.vEgo, CS.vCruise * CV.KPH_TO_MS)
|
2025-01-15 04:22:56 +05:30
|
|
|
actuators.accel = float(self.LoC.update(CC.longActive, CS, long_plan.aTarget, long_plan.shouldStop, pid_accel_limits))
|
2024-09-06 17:16:32 -07:00
|
|
|
|
|
|
|
|
# Steering PID loop and lateral MPC
|
2025-03-26 22:41:26 -07:00
|
|
|
# Reset desired curvature to current to avoid violating the limits on engage
|
|
|
|
|
new_desired_curvature = model_v2.action.desiredCurvature if CC.latActive else self.curvature
|
|
|
|
|
self.desired_curvature, curvature_limited = clip_curvature(CS.vEgo, self.desired_curvature, new_desired_curvature, lp.roll)
|
2025-10-08 18:29:54 -07:00
|
|
|
lat_delay = self.sm["liveDelay"].lateralDelay + LAT_SMOOTH_SECONDS
|
2025-03-26 22:41:26 -07:00
|
|
|
|
2025-03-03 21:47:52 -06:00
|
|
|
actuators.curvature = self.desired_curvature
|
2025-01-15 04:22:56 +05:30
|
|
|
steer, steeringAngleDeg, lac_log = self.LaC.update(CC.latActive, CS, self.VM, lp,
|
2025-08-11 14:25:29 -07:00
|
|
|
self.steer_limited_by_safety, self.desired_curvature,
|
2025-11-16 02:00:29 -05:00
|
|
|
self.calibrated_pose, curvature_limited, lat_delay)
|
2025-02-27 18:12:55 -06:00
|
|
|
actuators.torque = float(steer)
|
2025-01-15 04:22:56 +05:30
|
|
|
actuators.steeringAngleDeg = float(steeringAngleDeg)
|
2021-08-19 19:00:03 +02:00
|
|
|
# Ensure no NaNs/Infs
|
|
|
|
|
for p in ACTUATOR_FIELDS:
|
2021-09-06 18:45:59 -07:00
|
|
|
attr = getattr(actuators, p)
|
2025-08-02 00:08:18 -07:00
|
|
|
if not isinstance(attr, Number):
|
2021-09-06 18:45:59 -07:00
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not math.isfinite(attr):
|
2021-08-19 19:00:03 +02:00
|
|
|
cloudlog.error(f"actuators.{p} not finite {actuators.to_dict()}")
|
|
|
|
|
setattr(actuators, p, 0.0)
|
|
|
|
|
|
2025-05-15 20:13:40 -07:00
|
|
|
return CC, lac_log
|
2020-04-16 11:38:31 -07:00
|
|
|
|
2025-05-15 20:13:40 -07:00
|
|
|
def publish(self, CC, lac_log):
|
2024-09-06 17:16:32 -07:00
|
|
|
CS = self.sm['carState']
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2022-03-16 21:12:11 -07:00
|
|
|
# Orientation and angle rates can be useful for carcontroller
|
|
|
|
|
# Only calibrated (car) frame is relevant for the carcontroller
|
2025-04-25 16:57:18 -04:00
|
|
|
CC.currentCurvature = self.curvature
|
2024-08-13 21:11:16 -07:00
|
|
|
if self.calibrated_pose is not None:
|
|
|
|
|
CC.orientationNED = self.calibrated_pose.orientation.xyz.tolist()
|
|
|
|
|
CC.angularVelocity = self.calibrated_pose.angular_velocity.xyz.tolist()
|
2021-11-12 12:21:22 -08:00
|
|
|
|
2025-09-18 16:47:40 -04:00
|
|
|
CC.cruiseControl.override = CC.enabled and not CC.longActive and (self.CP.openpilotLongitudinalControl or not self.CP_SP.pcmCruiseSpeed)
|
2024-09-06 17:16:32 -07:00
|
|
|
CC.cruiseControl.cancel = CS.cruiseState.enabled and (not CC.enabled or not self.CP.pcmCruise)
|
2025-07-11 14:59:27 -07:00
|
|
|
CC.cruiseControl.resume = CC.enabled and CS.cruiseState.standstill and not self.sm['longitudinalPlan'].shouldStop
|
2022-07-07 00:24:03 -07:00
|
|
|
|
2022-01-04 19:04:03 +08:00
|
|
|
hudControl = CC.hudControl
|
2024-09-02 17:18:43 -07:00
|
|
|
hudControl.setSpeed = float(CS.vCruiseCluster * CV.KPH_TO_MS)
|
2024-09-06 17:16:32 -07:00
|
|
|
hudControl.speedVisible = CC.enabled
|
|
|
|
|
hudControl.lanesVisible = CC.enabled
|
2022-01-04 19:04:03 +08:00
|
|
|
hudControl.leadVisible = self.sm['longitudinalPlan'].hasLead
|
2024-09-06 17:16:32 -07:00
|
|
|
hudControl.leadDistanceBars = self.sm['selfdriveState'].personality.raw + 1
|
|
|
|
|
hudControl.visualAlert = self.sm['selfdriveState'].alertHudVisual
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2022-01-04 19:04:03 +08:00
|
|
|
hudControl.rightLaneVisible = True
|
|
|
|
|
hudControl.leftLaneVisible = True
|
2024-09-06 17:16:32 -07:00
|
|
|
if self.sm.valid['driverAssistance']:
|
2024-09-06 15:30:14 -07:00
|
|
|
hudControl.leftLaneDepart = self.sm['driverAssistance'].leftLaneDeparture
|
|
|
|
|
hudControl.rightLaneDepart = self.sm['driverAssistance'].rightLaneDeparture
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
if self.sm['selfdriveState'].active:
|
2024-05-10 21:00:01 -07:00
|
|
|
CO = self.sm['carOutput']
|
2022-12-09 21:43:27 -08:00
|
|
|
if self.CP.steerControlType == car.CarParams.SteerControlType.angle:
|
2025-08-11 14:25:29 -07:00
|
|
|
self.steer_limited_by_safety = abs(CC.actuators.steeringAngleDeg - CO.actuatorsOutput.steeringAngleDeg) > \
|
2025-03-03 18:28:49 -06:00
|
|
|
STEER_ANGLE_SATURATION_THRESHOLD
|
2022-12-09 21:43:27 -08:00
|
|
|
else:
|
2025-08-11 14:25:29 -07:00
|
|
|
self.steer_limited_by_safety = abs(CC.actuators.torque - CO.actuatorsOutput.torque) > 1e-2
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
# TODO: both controlsState and carControl valids should be set by
|
|
|
|
|
# sm.all_checks(), but this creates a circular dependency
|
2020-05-12 15:06:48 -07:00
|
|
|
|
|
|
|
|
# controlsState
|
|
|
|
|
dat = messaging.new_message('controlsState')
|
|
|
|
|
dat.valid = CS.canValid
|
2024-09-05 16:28:57 -07:00
|
|
|
cs = dat.controlsState
|
|
|
|
|
|
2025-03-26 22:41:26 -07:00
|
|
|
cs.curvature = self.curvature
|
2024-09-05 16:28:57 -07:00
|
|
|
cs.longitudinalPlanMonoTime = self.sm.logMonoTime['longitudinalPlan']
|
|
|
|
|
cs.lateralPlanMonoTime = self.sm.logMonoTime['modelV2']
|
2025-03-03 21:47:52 -06:00
|
|
|
cs.desiredCurvature = self.desired_curvature
|
2024-09-05 16:28:57 -07:00
|
|
|
cs.longControlState = self.LoC.long_control_state
|
|
|
|
|
cs.upAccelCmd = float(self.LoC.pid.p)
|
|
|
|
|
cs.uiAccelCmd = float(self.LoC.pid.i)
|
|
|
|
|
cs.ufAccelCmd = float(self.LoC.pid.f)
|
|
|
|
|
cs.forceDecel = bool((self.sm['driverMonitoringState'].awarenessStatus < 0.) or
|
2024-09-06 17:16:32 -07:00
|
|
|
(self.sm['selfdriveState'].state == State.softDisabling))
|
2020-05-12 15:06:48 -07:00
|
|
|
|
2022-01-04 19:04:03 +08:00
|
|
|
lat_tuning = self.CP.lateralTuning.which()
|
2024-09-06 17:16:32 -07:00
|
|
|
if self.CP.steerControlType == car.CarParams.SteerControlType.angle:
|
2024-09-05 16:28:57 -07:00
|
|
|
cs.lateralControlState.angleState = lac_log
|
2022-01-04 19:04:03 +08:00
|
|
|
elif lat_tuning == 'pid':
|
2024-09-05 16:28:57 -07:00
|
|
|
cs.lateralControlState.pidState = lac_log
|
2022-04-19 19:34:31 -07:00
|
|
|
elif lat_tuning == 'torque':
|
2024-09-05 16:28:57 -07:00
|
|
|
cs.lateralControlState.torqueState = lac_log
|
2022-01-04 19:04:03 +08:00
|
|
|
|
2020-05-12 15:06:48 -07:00
|
|
|
self.pm.send('controlsState', dat)
|
|
|
|
|
|
2024-09-05 16:28:57 -07:00
|
|
|
# carControl
|
|
|
|
|
cc_send = messaging.new_message('carControl')
|
|
|
|
|
cc_send.valid = CS.canValid
|
|
|
|
|
cc_send.carControl = CC
|
|
|
|
|
self.pm.send('carControl', cc_send)
|
|
|
|
|
|
2024-09-06 17:16:32 -07:00
|
|
|
def run(self):
|
|
|
|
|
rk = Ratekeeper(100, print_delay_threshold=None)
|
2025-11-29 03:58:58 -05:00
|
|
|
while True:
|
|
|
|
|
self.update()
|
|
|
|
|
CC, lac_log = self.state_control()
|
|
|
|
|
self.publish(CC, lac_log)
|
|
|
|
|
self.get_params_sp(self.sm)
|
|
|
|
|
self.run_ext(self.sm, self.pm)
|
|
|
|
|
rk.monitor_time()
|
2022-11-11 18:53:48 -08:00
|
|
|
|
2025-02-27 18:12:55 -06:00
|
|
|
|
2023-10-13 23:27:04 -07:00
|
|
|
def main():
|
2024-03-04 12:53:42 -05:00
|
|
|
config_realtime_process(4, Priority.CTRL_HIGH)
|
2023-10-13 23:27:04 -07:00
|
|
|
controls = Controls()
|
2024-09-06 17:16:32 -07:00
|
|
|
controls.run()
|
2020-01-17 12:48:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|