From db987fa29174f2d26f48d179fa483b3d5dc80784 Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Sun, 16 Jun 2024 10:27:06 -0400 Subject: [PATCH] Comp code changes (#98) * just in case * Fixed different regen torque scales and added safety for regen braking in load cell vectoring * pit determined pedals params * made power limit safer, changed pedal params again to shayan's feet, and made power limit for CASE good to match mode power limits * Lowering power limit by 3% and increasing launch rate * at autox tuning :skull: ryan spun out so we changed things up for CASE parameters. * reduced power limit for endurance. flashed at comp in pits --------- Co-authored-by: walkermburns --- include/MCU_rev15_defs.h | 13 +-- lib/systems/include/TorqueControllers.h | 12 +-- lib/systems/src/TorqueControllers.cpp | 31 +++++-- src/main.cpp | 102 ++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 26 deletions(-) diff --git a/include/MCU_rev15_defs.h b/include/MCU_rev15_defs.h index 249e6c891..16ed0f851 100644 --- a/include/MCU_rev15_defs.h +++ b/include/MCU_rev15_defs.h @@ -60,11 +60,11 @@ const int ACCEL2_PEDAL_MAX = 259; // 388 const int ACCEL1_PEDAL_MIN = 2129; const int ACCEL2_PEDAL_MIN = 1517; -const int BRAKE1_PEDAL_MAX = 1828; // 2200; -const int BRAKE2_PEDAL_MAX = 1857; // 2200; +const int BRAKE1_PEDAL_MAX = 1945; // 2200; +const int BRAKE2_PEDAL_MAX = 1742; // 2200; -const int BRAKE1_PEDAL_MIN = 1184; // 785; // 1230 to 1750 -const int BRAKE2_PEDAL_MIN = 2486; // 785; // 2450 to 1930 +const int BRAKE1_PEDAL_MIN = 1230; // 785; // 1230 to 1750 +const int BRAKE2_PEDAL_MIN = 2437; // 785; // 2450 to 1930 const int ACCEL1_PEDAL_OOR_MIN = 90; const int ACCEL2_PEDAL_OOR_MIN = 90; @@ -83,7 +83,7 @@ const float DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN = 0.12f; const float APPS_ACTIVATION_PERCENTAGE = 0.1f; const float BRAKE_ACTIVATION_PERCENTAGE = 0.05f; -const float BRAKE_MECH_THRESH = 0.40f; +const float BRAKE_MECH_THRESH = 0.46f; // Load Cell Defs to convert raw to lbs // lbs = (raw + offset) * scale @@ -110,6 +110,7 @@ const float STEERING_IIR_ALPHA = 0.7f; // shaves off around 1 deg of max discre // TC parameters const float SIMPLE_TC_REAR_TORQUE_SCALE = 1.0; -const float SIMPLE_TC_REGEN_TORQUE_SCALE = 0.4; +// percent front wheels +const float SIMPLE_TC_REGEN_TORQUE_SCALE = 0.6; #endif /* __MCU15_H__ */ \ No newline at end of file diff --git a/lib/systems/include/TorqueControllers.h b/lib/systems/include/TorqueControllers.h index 783d5350c..198d4c118 100644 --- a/lib/systems/include/TorqueControllers.h +++ b/lib/systems/include/TorqueControllers.h @@ -18,7 +18,7 @@ /* CONTROLLER CONSTANTS */ -const float MAX_POWER_LIMIT = 63000.0; // max mechanical power limit in KW +const float MAX_POWER_LIMIT = 51500.0; // max mechanical power limit in KW /* MOTOR CONSTANTS */ @@ -34,7 +34,7 @@ const float MAX_REGEN_TORQUE = 10.0; /* LAUNCH CONSTANTS */ -const float DEFAULT_LAUNCH_RATE = 1.4 * 9.8; +const float DEFAULT_LAUNCH_RATE = 1.5 * 9.8; const int16_t DEFAULT_LAUNCH_SPEED_TARGET = 1500; const float DEFAULT_SLIP_RATIO = 0.2f; @@ -137,8 +137,8 @@ class TorqueControllerSimple : public TorqueController : writeout_(writeout), frontTorqueScale_(2.0 - rearTorqueScale), rearTorqueScale_(rearTorqueScale), - frontRegenTorqueScale_(2.0 - regenTorqueScale), - rearRegenTorqueScale_(regenTorqueScale) + frontRegenTorqueScale_(regenTorqueScale), + rearRegenTorqueScale_(1.0 - regenTorqueScale) { writeout_.command = TC_COMMAND_NO_TORQUE; writeout_.ready = true; @@ -197,8 +197,8 @@ class TorqueControllerLoadCellVectoring : public TorqueController .5) { + normalForcePercentFL = .25; + normalForcePercentFR = .25; + normalForcePercentRL = .25; + normalForcePercentRR = .25; + } + + writeout_.command.torqueSetpoints[FL] = torquePool * frontRegenTorqueScale_ * normalForcePercentFL; + writeout_.command.torqueSetpoints[FR] = torquePool * frontRegenTorqueScale_ * normalForcePercentFR; + writeout_.command.torqueSetpoints[RL] = torquePool * rearRegenTorqueScale_ * normalForcePercentRL; + writeout_.command.torqueSetpoints[RR] = torquePool * rearRegenTorqueScale_ * normalForcePercentRR; // No load cell vectoring on regen // writeout_.command.torqueSetpoints[FL] = torqueRequest * frontRegenTorqueScale_; diff --git a/src/main.cpp b/src/main.cpp index f159b590b..9af88b81d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,35 @@ const TelemetryInterfaceReadChannels telem_read_channels = { .therm_fl_channel = MCU15_THERM_FL_CHANNEL, .therm_fr_channel = MCU15_THERM_FR_CHANNEL}; +const PedalsParams accel1_only_params = { + .min_pedal_1 = ACCEL1_PEDAL_MIN, + .min_pedal_2 = ACCEL1_PEDAL_MIN, + .max_pedal_1 = ACCEL1_PEDAL_MAX, + .max_pedal_2 = ACCEL1_PEDAL_MAX, + .min_sensor_pedal_1 = ACCEL1_PEDAL_OOR_MIN, + .min_sensor_pedal_2 = ACCEL1_PEDAL_OOR_MIN, + .max_sensor_pedal_1 = ACCEL1_PEDAL_OOR_MAX, + .max_sensor_pedal_2 = ACCEL1_PEDAL_OOR_MAX, + .activation_percentage = APPS_ACTIVATION_PERCENTAGE, + .deadzone_margin = DEFAULT_PEDAL_DEADZONE, + .implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, + .mechanical_activation_percentage = APPS_ACTIVATION_PERCENTAGE}; + +const PedalsParams accel2_only_params = { + .min_pedal_1 = ACCEL2_PEDAL_MIN, + .min_pedal_2 = ACCEL2_PEDAL_MIN, + .max_pedal_1 = ACCEL2_PEDAL_MAX, + .max_pedal_2 = ACCEL2_PEDAL_MAX, + .min_sensor_pedal_1 = ACCEL2_PEDAL_OOR_MIN, + .min_sensor_pedal_2 = ACCEL2_PEDAL_OOR_MIN, + .max_sensor_pedal_1 = ACCEL2_PEDAL_OOR_MAX, + .max_sensor_pedal_2 = ACCEL2_PEDAL_OOR_MAX, + .activation_percentage = APPS_ACTIVATION_PERCENTAGE, + .deadzone_margin = DEFAULT_PEDAL_DEADZONE, + .implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, + .mechanical_activation_percentage = APPS_ACTIVATION_PERCENTAGE}; + + const PedalsParams accel_params = { .min_pedal_1 = ACCEL1_PEDAL_MIN, .min_pedal_2 = ACCEL2_PEDAL_MIN, @@ -72,6 +101,37 @@ const PedalsParams accel_params = { .implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, .mechanical_activation_percentage = APPS_ACTIVATION_PERCENTAGE}; + +const PedalsParams brake1_only_params = { + .min_pedal_1 = BRAKE1_PEDAL_MIN, + .min_pedal_2 = BRAKE1_PEDAL_MIN, + .max_pedal_1 = BRAKE1_PEDAL_MAX, + .max_pedal_2 = BRAKE1_PEDAL_MAX, + .min_sensor_pedal_1 = BRAKE1_PEDAL_OOR_MIN, + .min_sensor_pedal_2 = BRAKE1_PEDAL_OOR_MIN, + .max_sensor_pedal_1 = BRAKE1_PEDAL_OOR_MAX, + .max_sensor_pedal_2 = BRAKE1_PEDAL_OOR_MAX, + .activation_percentage = BRAKE_ACTIVATION_PERCENTAGE, + .deadzone_margin = DEFAULT_PEDAL_DEADZONE, + .implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, + .mechanical_activation_percentage = BRAKE_MECH_THRESH, +}; + +const PedalsParams brake2_only_params = { + .min_pedal_1 = BRAKE2_PEDAL_MIN, + .min_pedal_2 = BRAKE2_PEDAL_MIN, + .max_pedal_1 = BRAKE2_PEDAL_MAX, + .max_pedal_2 = BRAKE2_PEDAL_MAX, + .min_sensor_pedal_1 = BRAKE2_PEDAL_OOR_MIN, + .min_sensor_pedal_2 = BRAKE2_PEDAL_OOR_MIN, + .max_sensor_pedal_1 = BRAKE2_PEDAL_OOR_MAX, + .max_sensor_pedal_2 = BRAKE2_PEDAL_OOR_MAX, + .activation_percentage = BRAKE_ACTIVATION_PERCENTAGE, + .deadzone_margin = DEFAULT_PEDAL_DEADZONE, + .implausibility_margin = DEFAULT_PEDAL_IMPLAUSIBILITY_MARGIN, + .mechanical_activation_percentage = BRAKE_MECH_THRESH, +}; + const PedalsParams brake_params = { .min_pedal_1 = BRAKE1_PEDAL_MIN, .min_pedal_2 = BRAKE2_PEDAL_MIN, @@ -157,8 +217,8 @@ TorqueControllerMux torque_controller_mux(SIMPLE_TC_REAR_TORQUE_SCALE, SIMPLE_TC CASEConfiguration case_config = { // Following used for generated code .AbsoluteTorqueLimit = 21.42, // N-m, Torque limit used for yaw pid torque split overflow - .yaw_pid_p = 1.5, - .yaw_pid_i = 0.25, + .yaw_pid_p = 1.15, + .yaw_pid_i = 0.0, .yaw_pid_d = 0.0, .tcs_pid_p_lowerBound_front = 55.0, // if tcs_pid_p_lowerBound_front > tcs_pid_p_upperBound_front, inverse relationship, no error .tcs_pid_p_upperBound_front = 42.0, @@ -182,7 +242,7 @@ CASEConfiguration case_config = { .yawPIDErrorThreshold = 0.1, // rad/s .yawPIDVelThreshold = 0.35, // m/s .yawPIDCoastThreshold = 2.5, // m/s - .yaw_pid_brakes_p = 0.25, + .yaw_pid_brakes_p = 0.1, .yaw_pid_brakes_i = 0.0, .yaw_pid_brakes_d = 0.0, .decoupledYawPIDBrakesMaxDIfference = 2, // N-m @@ -192,14 +252,14 @@ CASEConfiguration case_config = { .useNoRegen5kph = true, .useTorqueBias = true, .DriveTorquePercentFront = 0.5, // DON'T TOUCH UNTIL LOAD CELL ADHERES TO DRIVE BIAS - .BrakeTorquePercentFront = 0.7, - .MechPowerMaxkW = 63.0, // kW + .BrakeTorquePercentFront = 0.6, + .MechPowerMaxkW =51.5, // kW .launchLeftRightMaxDiff = 2.0, // N-m .tcs_pid_lower_rpm_front = 0.0, // RPM .tcs_pid_upper_rpm_front = 5000.0, // RPM .tcs_pid_lower_rpm_rear = 0.0, // RPM .tcs_pid_upper_rpm_rear = 5000.0, // RPM - .maxNormalLoadBrakeScalingFront = 1.25, + .maxNormalLoadBrakeScalingFront = 1.15, .tcs_saturation_front = 20, .tcs_saturation_rear = 20, .TCSGenLeftRightDiffLowerBound = 2, // N-m @@ -531,6 +591,36 @@ void tick_all_systems(const SysTick_s ¤t_system_tick) a1.get().conversions[MCU15_BRAKE1_CHANNEL], a1.get().conversions[MCU15_BRAKE2_CHANNEL]); + // accel 1 only accel 2 dead, brake normal + // pedals_system.tick( + // current_system_tick, + // a1.get().conversions[MCU15_ACCEL1_CHANNEL], + // a1.get().conversions[MCU15_ACCEL1_CHANNEL], + // a1.get().conversions[MCU15_BRAKE1_CHANNEL], + // a1.get().conversions[MCU15_BRAKE2_CHANNEL]); + // accel 2 only accel 1 dead, brake normal + // pedals_system.tick( + // current_system_tick, + // a1.get().conversions[MCU15_ACCEL2_CHANNEL], + // a1.get().conversions[MCU15_ACCEL2_CHANNEL], + // a1.get().conversions[MCU15_BRAKE1_CHANNEL], + // a1.get().conversions[MCU15_BRAKE2_CHANNEL]); + // brake 1 only brake 2 dead, accel normal + // pedals_system.tick( + // current_system_tick, + // a1.get().conversions[MCU15_ACCEL1_CHANNEL], + // a1.get().conversions[MCU15_ACCEL2_CHANNEL], + // a1.get().conversions[MCU15_BRAKE1_CHANNEL], + // a1.get().conversions[MCU15_BRAKE1_CHANNEL]); + // brake 2 only brake 1 dead, accel normal + // pedals_system.tick( + // current_system_tick, + // a1.get().conversions[MCU15_ACCEL1_CHANNEL], + // a1.get().conversions[MCU15_ACCEL2_CHANNEL], + // a1.get().conversions[MCU15_BRAKE2_CHANNEL], + // a1.get().conversions[MCU15_BRAKE2_CHANNEL]); + + // tick steering system steering_system.tick( (SteeringSystemTick_s){