-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dumbed down dynamic regen travel for now and turn it off by default
- Loading branch information
1 parent
5355da4
commit b668864
Showing
6 changed files
with
33 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,6 @@ float Throttle::fmax; | |
int Throttle::accelmax; | ||
int Throttle::accelflt; | ||
float Throttle::maxregentravelhz; | ||
float Throttle::regenrampstr; | ||
|
||
bool Throttle::CheckAndLimitRange(int* potval, uint8_t potIdx) | ||
{ | ||
|
@@ -85,87 +84,44 @@ float Throttle::DigitsToPercent(int potval, int potidx) | |
return (100 * (potval - potmin[potidx])) / (potmax[potidx] - potmin[potidx]); | ||
} | ||
|
||
|
||
/** | ||
* Calculate throttle and regen. | ||
* - Increase regentravel when lifting accelerator using historical pedal values. | ||
* - Decrease regentravel when speed goes below regenrampstr. | ||
* | ||
* Parameters: | ||
* potnom = accelerator pedal pressed percentage | ||
* pot2nom = optional potentiometer for adjusting regen braking | ||
* brkpedal = is brake pedal pressed | ||
* rotorfreq = rotor rotation freqyency in hz | ||
* | ||
* Used variables: | ||
* brkmax = regen percentage to apply, when brake is pressed | ||
* brknompedal = regen percentage to apply, when accelerator is lifted | ||
* brknom = percentage of how much of accelerator is assigned for adjusting regen | ||
* regenrampstr = rotor hz where regen strenght start to decrease linearly | ||
*/ | ||
float Throttle::CalcThrottle(float potnom, float pot2nom, bool brkpedal, float rotorfreq) | ||
void Throttle::UpdateDynamicRegenTravel(float regenTravelMax, float frequency) | ||
{ | ||
// variables for rolling average calculation | ||
static const int history = 20; // 20 events, 10ms delta = 200ms of history to calculate | ||
static int currentArrayIndex = 0; // pointer where to pu the next value | ||
static float prevPotnom[history] = {}; // array holding previous potnom value | ||
static float potnomSums = 0; // sum of values in array | ||
|
||
// current dynamic regentravel | ||
static float currentRegentravel = 0.0; | ||
|
||
float scaledBrkMax = brkpedal ? brknompedal : brkmax; | ||
// Never reach 0, because that can spin up the motor | ||
scaledBrkMax = -0.1 + (scaledBrkMax * pot2nom) / 100.0f; | ||
if (maxregentravelhz == 0) //dynamic travel turned off | ||
{ | ||
brknom = regenTravelMax; | ||
return; | ||
} | ||
|
||
// increase speedBasedRegenTravel linearly until rotorfreq reaches maxregentravelhz, then stay at max. | ||
// Don't go over max regentravel (brknom). | ||
float speedBasedRegenTravel = MIN(brknom * rotorfreq / maxregentravelhz, brknom); | ||
// Don't go over max regentravel | ||
float speedBasedRegenTravel = 3 + regenTravelMax * frequency / maxregentravelhz; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jsphuebner
Author
Owner
|
||
speedBasedRegenTravel = MIN(regenTravelMax, speedBasedRegenTravel); | ||
|
||
// decreasing regentravel when rotor hz is goes below "regen ramp start" | ||
if (rotorfreq < regenrampstr) | ||
{ | ||
float decreasingRegenTravel = brknom * rotorfreq / regenrampstr; | ||
// decrease only if it's been higher before (don't start to increase on low speeds to keep linear curve) | ||
if (currentRegentravel > decreasingRegenTravel) | ||
{ | ||
currentRegentravel = decreasingRegenTravel; | ||
} | ||
} | ||
brknom = speedBasedRegenTravel; | ||
} | ||
|
||
// increase currentRegenTravel when lifting accelerator | ||
if (currentRegentravel < speedBasedRegenTravel) // if currentregentravel is smaller than speedBaseRegenTravel | ||
{ | ||
// current pedal position delta compared against average of last 200ms | ||
float acceleratorDelta = potnom - potnomSums / history; | ||
if (acceleratorDelta < 0) // accelerator is being lifted (acceleratorDelta is negative) | ||
{ | ||
currentRegentravel = RAMPUP(currentRegentravel, speedBasedRegenTravel, -acceleratorDelta); | ||
} | ||
} | ||
float Throttle::CalcThrottle(float potnom, float pot2nom, bool brkpedal) | ||
{ | ||
float scaledBrkMax = brkpedal ? brknompedal : brkmax; | ||
|
||
//Never reach 0, because that can spin up the motor | ||
scaledBrkMax = -0.1 + (scaledBrkMax * pot2nom) / 100.0f; | ||
|
||
if (brkpedal) // give max brake regen | ||
if (brkpedal) | ||
{ | ||
potnom = scaledBrkMax; | ||
} | ||
else if (potnom < currentRegentravel) // calculate regen | ||
else if (potnom < brknom) | ||
{ | ||
potnom -= currentRegentravel; | ||
potnom = -(potnom * scaledBrkMax / currentRegentravel); | ||
potnom -= brknom; | ||
potnom = -(potnom * scaledBrkMax / brknom); | ||
} | ||
else // calculate thorttle | ||
else | ||
{ | ||
potnom -= currentRegentravel; | ||
potnom = 100.0f * potnom / (100.0f - currentRegentravel); | ||
potnom -= brknom; | ||
potnom = 100.0f * potnom / (100.0f - brknom); | ||
} | ||
|
||
// there next 4 lines are for calculating rolling average for historical pedal (potnom) position | ||
// and saving current potnom | ||
potnomSums -= prevPotnom[currentArrayIndex]; // remove old potnom value from average calculation sums | ||
potnomSums += potnom; // replace it with new potnom value | ||
prevPotnom[currentArrayIndex] = potnom; // put current potnom to array | ||
currentArrayIndex = (currentArrayIndex + 1) % history; // loop array index from 0 - history, start again from 0 | ||
|
||
return potnom; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Curious, what is this 3 + for?