Skip to content

Commit

Permalink
Comp code changes (#98)
Browse files Browse the repository at this point in the history
* 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 💀 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 <walkermburns@gmail.com>
  • Loading branch information
RCMast3r and walkermburns committed Jun 16, 2024
1 parent cead7ab commit db987fa
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 26 deletions.
13 changes: 7 additions & 6 deletions include/MCU_rev15_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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__ */
12 changes: 6 additions & 6 deletions lib/systems/include/TorqueControllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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;
Expand Down Expand Up @@ -137,8 +137,8 @@ class TorqueControllerSimple : public TorqueController<TC_SAFE_MODE>
: 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;
Expand Down Expand Up @@ -197,8 +197,8 @@ class TorqueControllerLoadCellVectoring : public TorqueController<TC_LOAD_CELL_V
: 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 = false;
Expand Down
31 changes: 23 additions & 8 deletions lib/systems/src/TorqueControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ void TorqueControllerSimple::tick(const SysTick_s &tick, const PedalsSystemData_
{
// Negative torque request
torqueRequest = MAX_REGEN_TORQUE * accelRequest * -1.0;
float netTorqueRequest = torqueRequest * 4;

writeout_.command.speeds_rpm[FL] = 0.0;
writeout_.command.speeds_rpm[FR] = 0.0;
writeout_.command.speeds_rpm[RL] = 0.0;
writeout_.command.speeds_rpm[RR] = 0.0;

writeout_.command.torqueSetpoints[FL] = torqueRequest * frontRegenTorqueScale_;
writeout_.command.torqueSetpoints[FR] = torqueRequest * frontRegenTorqueScale_;
writeout_.command.torqueSetpoints[RL] = torqueRequest * rearRegenTorqueScale_;
writeout_.command.torqueSetpoints[RR] = torqueRequest * rearRegenTorqueScale_;


writeout_.command.torqueSetpoints[FL] = (netTorqueRequest * frontRegenTorqueScale_) / 2;
writeout_.command.torqueSetpoints[FR] = (netTorqueRequest * frontRegenTorqueScale_) / 2;
writeout_.command.torqueSetpoints[RL] = (netTorqueRequest * rearRegenTorqueScale_) / 2;
writeout_.command.torqueSetpoints[RR] = (netTorqueRequest * rearRegenTorqueScale_) / 2;
}
}
}
Expand Down Expand Up @@ -135,10 +138,22 @@ void TorqueControllerLoadCellVectoring::tick(
writeout_.command.speeds_rpm[RL] = 0.0;
writeout_.command.speeds_rpm[RR] = 0.0;

writeout_.command.torqueSetpoints[FL] = torquePool * frontRegenTorqueScale_ * loadCellForcesFiltered_[0] / sumNormalForce;
writeout_.command.torqueSetpoints[FR] = torquePool * frontRegenTorqueScale_ * loadCellForcesFiltered_[1] / sumNormalForce;
writeout_.command.torqueSetpoints[RL] = torquePool * rearRegenTorqueScale_ * loadCellForcesFiltered_[2] / sumNormalForce;
writeout_.command.torqueSetpoints[RR] = torquePool * rearRegenTorqueScale_ * loadCellForcesFiltered_[3] / sumNormalForce;
float normalForcePercentFL = loadCellForcesFiltered_[0] / sumNormalForce;
float normalForcePercentFR = loadCellForcesFiltered_[1] / sumNormalForce;
float normalForcePercentRL = loadCellForcesFiltered_[2] / sumNormalForce;
float normalForcePercentRR = loadCellForcesFiltered_[3] / sumNormalForce;

if (normalForcePercentFL + normalForcePercentFR < .5 || normalForcePercentRL + normalForcePercentRR > .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_;
Expand Down
102 changes: 96 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -531,6 +591,36 @@ void tick_all_systems(const SysTick_s &current_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){
Expand Down

0 comments on commit db987fa

Please sign in to comment.