Page 1 of 1

Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 10:57 am
by mjc506
'ning All,

I've been playing with regen settings on my bench, and have either stumbled across a potential concern, or more likely uncovered a(nother) fundamental misunderstanding of the openinverter code :) The below is mainly from my reading of the code - I don't have a good enough setup to test regen very accurately at all.

From throttle.cpp

Code: Select all

s32fp Throttle::CalcThrottle(s32fp potnom, s32fp pot2nom, bool brkpedal)
{
   s32fp scaledBrkMax = brkpedal ? brknompedal : brkmax;

   //Never reach 0, because that can spin up the motor
   scaledBrkMax = -1 + FP_MUL(scaledBrkMax, pot2nom) / 100;

   if (brkpedal)
   {
      potnom = scaledBrkMax;
   }
   else if (potnom < brknom)
   {
      potnom -= brknom;
      potnom = -FP_DIV(FP_MUL(potnom, scaledBrkMax), brknom);
   }
   else
   {
      potnom -= brknom;
      potnom = FP_DIV(100 * potnom, FP_FROMINT(100) - brknom);
   }

   return potnom;
}
So the code sets scaledBrkMax to either brknompedal or brkmax depending whether or not the brake switch is 'on', and then scales it based on pot2

On a setup with a brake switch only, everything seems to act as expected - pressing the brake will result in the throttle being ignored, and brknompedal regen being applied. Fine.

On a setup with a brake switch and pot2, pressing the brake will ignore the throttle and apply brknompedal*pot2 regen. Also fine.

On a setup with no switch, but pot2 tied to the brake pedal, I'm finding that you only get regen if pot1 (throttle) is below brknom. If pot1 is above brknom, you get no braking, even if pot2 is maxed out.

Maybe not an immediate problem, but a failed (or no) brake switch plus a stuck throttle could get exciting! Or, in my case, no brake switch and brknom=0 (so the vehicle just rolls with no inputs) means no braking ever...

Here's the stock firmware pot1/pot2 map: (assuming no brake switch) pot1/throttle across the top, pot2/brake down the left. I've used the default parameters.
Image

Here's a possible alternative - with no brake input, it outputs brkmax at pot1=0, 0 at pot1=brknom and 100 at pot1=100. With pot1=0, output goes from brkmax at pot2=0 to brknompedal at pot2=100. You can also see that braking overrides throttle - if pot2=100, output is always brknompedal no matter what pot1 is doing. (perhaps brkmax and brknompedal should be swapped)
Image
This gives a set amount of 'engine braking' with no input, which increases as pot2 increases. And no effective change with pot2=0.

Any thoughts?

Re: Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 11:41 am
by arber333
That is why you have mechanical brakes still.
I consider throttle priority over regen, but mechanical brakes over throttle allways. That is why you have to move your foot from throttle pedal to the brake pedal.
Granted some 30% of throttle travel could be used for control of regen. With brake switch you could apply greater regen force BEFORE mechanical brakes become effective. Maybe 2mm of travel before brakes grab? But brakes need to have the final word :).
Also you need to be able to remove regen in case of icing in winter.

Re: Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 11:50 am
by mjc506
Oh yeah, definitely keep mechanical brakes!

Re: Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 2:43 pm
by johu
Conclusion: always have a brake pedal switch or modify the software so that a certain threshold of pot2 forms a "virtual" brake pedal switch.

Re: Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 2:48 pm
by mjc506
That'd work!

Re: Brake/regen hardware and settings

Posted: Thu Mar 25, 2021 3:13 pm
by muehlpower
the first diagram tells me that I won't connect a brake light switch, how else do you want to make a burn out? brknom to almost 0, pot2 as a poti to the travel of the brake pedal, not the pressure, mainly before the hydraulic brake works.

This should result in little idle travel on the accelerator and hardly any regeneration when the accelerator is released. The vehicle only decelerates when the brake pedal is depressed. Initially electrically, and if that is not enough, also hydraulically.