-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HKG Longitudinal Tuning #80
base: master-new
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis pull request introduces custom longitudinal tuning for HKG vehicles, allowing for adjustments to jerk limits and comfort bands. It also implements a smoother braking feature using custom acceleration logic to filter and smooth acceleration/braking transitions. The changes involve creating new classes and functions for managing tuning parameters, integrating them into the car controller, and modifying CAN message creation to include the new parameters. Sequence diagram for longitudinal control update with HKGLongitudinalControllersequenceDiagram
participant CC as CarController
participant HKGLC as HKGLongitudinalController
participant HKGLT as HKGLongitudinalTuning
CC->HKGLC: update(longControlState, actuators, CS, CP_SP)
activate HKGLC
HKGLC->HKGLC: calculate_accel(actuators, CS, CP_SP)
HKGLC->HKGLC: calculate_and_get_jerk(actuators, CS, longControlState)
alt HKGLC.tuning is not None
HKGLC->HKGLT: make_jerk(CS, actuators)
activate HKGLT
HKGLT-->HKGLC: jerk_output
deactivate HKGLT
else
HKGLC-->HKGLC: jerk_limit
end
HKGLC-->CC: None
deactivate HKGLC
Updated class diagram for HKGLongitudinalControllerclassDiagram
class HKGLongitudinalController {
-CP: structs.CarParams
-tuning: HKGLongitudinalTuning
-jerk: None
-jerk_upper: float
-jerk_lower: float
-cb_upper: float
-cb_lower: float
-accel: float
+__init__(CP: structs.CarParams, CP_SP: structs.CarParamsSP)
+apply_tune(CP: structs.CarParams, CP_SP: structs.CarParamsSP)
+get_jerk(): JerkOutput
+calculate_and_get_jerk(actuators: structs.CarControl.Actuators, CS: structs.CarState, long_control_state: LongCtrlState): JerkOutput
+calculate_accel(actuators: structs.CarControl.Actuators, CS: structs.CarState, CP_SP: structs.CarParamsSP): float
+update(long_control_state: LongCtrlState, actuators: structs.CarControl.Actuators, CS: structs.CarState, CP_SP: structs.CarParamsSP): None
}
class HKGLongitudinalTuning {
-CP: structs.CarParams
-DT_CTRL: float
-accel_last: float
-accel_last_jerk: float
-jerk: float
-jerk_count: float
-jerk_upper_limit: float
-jerk_lower_limit: float
-cb_upper: float
-cb_lower: float
-last_decel_time: float
-min_cancel_delay: float
-car_config: CarTuningConfig
+__init__(CP: structs.CarParams)
-_setup_controllers(): None
-_init_state(): None
-_setup_car_config(): None
+make_jerk(CS: structs.CarState, actuators: structs.CarControl.Actuators): float
+handle_cruise_cancel(CS: structs.CarState): bool
+calculate_limited_accel(actuators: structs.CarControl.Actuators, CS: structs.CarState): float
+calculate_accel(actuators: structs.CarControl.Actuators, CS: structs.CarState): float
+apply_tune(CP: structs.CarParams): None
}
class CarTuningConfig {
-vego_stopping: float
-vego_starting: float
-stopping_decel_rate: float
-start_accel: float
-jerk_limits: tuple[float, float]
-brake_response: tuple[float, float, float, float]
-accel_limits: tuple[float, float]
}
class Cartuning {
+get_car_config(CP: structs.CarParams): CarTuningConfig
}
class JerkOutput {
-jerk_upper_limit: float
-jerk_lower_limit: float
-cb_upper: float
-cb_lower: float
+__init__(jerk_upper_limit: float, jerk_lower_limit: float, cb_upper: float, cb_lower: float)
}
HKGLongitudinalController -- HKGLongitudinalTuning : has
HKGLongitudinalTuning -- CarTuningConfig : uses
HKGLongitudinalController -- JerkOutput : returns
Cartuning -- CarTuningConfig : returns
note for HKGLongitudinalController "This class manages the longitudinal control with custom tuning."
note for HKGLongitudinalTuning "This class handles the longitudinal tuning logic."
note for CarTuningConfig "This class holds the tuning parameters for different car types."
note for Cartuning "This class provides the car-specific tuning configurations."
note for JerkOutput "This class represents the output of jerk calculation."
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
a409c31
to
11a85b2
Compare
This resolves the issues caused by the incorrect sequence.
Moved Hyundai-specific flag handling logic to utilize CP_SP flags instead of CP flags. This ensures better separation of parameters and aligns with the updated parameter structure. Updated related functions and class initializations for consistency.
…e CP_SP parameter to default to `None`, improving compatibility
…e CP_SP parameter to default to `None`, improving compatibility
8eed78b
to
6c3bd40
Compare
73b2cd0
to
9b2c1bf
Compare
opendbc/sunnypilot/car/hyundai/longitudinal/tuning_controller.py
Outdated
Show resolved
Hide resolved
` "aReqValue": long_state.accel_value if enabled else a_val` its only to not have merge conflicts with syncs from this file, because if not enabled a_val is already at 0 anyways.
Custom tuning for HKG vehicles, taking into account lower, upper jerk, and comfort bands. When the user selects toggles, these plus interface tuning will be applied. Furthermore, if the user presses the button to enable smoother braking, my custom accel logic will be utilized to greatly filter and smoothen accel/braking transitions for a more chill open pilot experience.
Current issue:
--While CB calculation works excellent to limit rough transitions from acceleration costs, there needs to be changes in the logic.. Zero'd out for now.
Summary by Sourcery
New Features: