Skip to content

Commit

Permalink
Derate only on CASE + fix derate regen
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynoorani committed May 31, 2024
1 parent 30a5878 commit ef13541
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/systems/src/TorqueControllerMux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ void TorqueControllerMux::tick(

// Apply setpoints value limits
// Derating for endurance
applyDerate(&drivetrainCommand_, accDerateFactor);



if (muxMode_ != TC_CASE_SYSTEM)
{
{
// Safety checks for CASE: CASE handles regen, torque, and power limit internally
applyRegenLimit(&drivetrainCommand_, &drivetrainData);
// Apply torque limit before power limit to not power limit
applyTorqueLimit(&drivetrainCommand_);
applyPowerLimit(&drivetrainCommand_, &drivetrainData);
}
} else{
applyDerate(&drivetrainCommand_, accDerateFactor);
}

// Uniformly apply speed limit to all controller modes
applyPosSpeedLimit(&drivetrainCommand_);
Expand Down Expand Up @@ -178,10 +181,18 @@ void TorqueControllerMux::applyRegenLimit(DrivetrainCommand_s *command, const Dr
*/
void TorqueControllerMux::applyDerate(DrivetrainCommand_s *command, float accDerateFactor)
{
for (int i = 0; i < NUM_MOTORS; i++)
{
command->torqueSetpoints[i] *= accDerateFactor;
if( command->speeds_rpm[0] != 0 &&
command->speeds_rpm[1] != 0 &&
command->speeds_rpm[2] != 0 &&
command->speeds_rpm[3] != 0) {
for (int i = 0; i < NUM_MOTORS; i++)
{
command->torqueSetpoints[i] *= accDerateFactor;
}

}


}

/*
Expand Down

0 comments on commit ef13541

Please sign in to comment.