Skip to content

Commit

Permalink
fix torque derating calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Sep 21, 2024
1 parent 39d056a commit 00c59bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Core/Inc/cerberus_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

/* Torque Tuning */
#define MAX_TORQUE 220 /* Nm */
#define PIT_MAX_TORQUE 0.3 * MAX_TORQUE

/* Endurance Mode Thresholds */
#define REGEN_THRESHOLD 0.01
Expand Down
16 changes: 8 additions & 8 deletions Core/Src/pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ static int16_t derate_torque(float mph, float accel)
if (mph > PIT_MAX_SPEED) {
torque = 0;
} else {
/* Highest torque % in pit mode */
static const float max_torque_percent = 0.3;
/* Linearly derate torque from 30% to 0% as speed increases */
float torque_derating_factor =
max_torque_percent -
(max_torque_percent / PIT_MAX_SPEED);
accel *= torque_derating_factor;
torque = MAX_TORQUE * accel;
/* Linearly derate torque as speed increases */
torque = accel * PIT_MAX_TORQUE;
/* Max torque based on mph */
int16_t max_torque = PIT_MAX_TORQUE -
(mph * (PIT_MAX_TORQUE / PIT_MAX_SPEED));

if (torque > max_torque)
torque = max_torque;
}

/* Add value to moving average */
Expand Down

0 comments on commit 00c59bb

Please sign in to comment.