Page 1 of 1

Quadratic throttle pedal map

Posted: Sun Dec 07, 2025 1:14 pm
by johu
I added a contribution to some random project :)
https://github.com/jsphuebner/stm32-sin ... 977ee9066e

I was always bugged by the harsh clonk even when carefully stepping onto the pedal. I tried adding a second, slower ramp from 0-20% but that doesn't help. Then I lowered throtcur to 1 and the clonk was gone. So pedal control just isn't fine grained enough at standstill.

Therefor I added what many have been asking for: added a quadratic pedal map. So first it comes in slowly and then most torque is towards the end of the pedal travel.

I made it x²+x with a factor called "potlinearity". It maxes out and defaults to 99.9% to achieve the former linear throttle map (100% would result in div by 0). By lowering the value you can make it increasingly more quadratic and at 0% it is purely quadratic.

I ended up setting it to 20%.
The regen part is still purely linear.
With potnom normalized 0-1 the formula is

Code: Select all

x = potnom²/(1-potlinearity) + potnom * potlinearity

Re: Quadratic throttle pedal map

Posted: Wed Dec 10, 2025 12:56 pm
by davefiddes
I wondered what this would look like as the linearity changed so I got a computer to draw me a picture:
throttle-linearity.png

Re: Quadratic throttle pedal map

Posted: Wed Dec 10, 2025 1:50 pm
by muehlpower
I don't understand that.
johu wrote: Sun Dec 07, 2025 1:14 pm CODE: SELECT ALL

x = potnom²/(1-potlinearity) + potnom * potlinearity

Shouldn't that be
x = potnom²*(1-potlinearity) + potnom * potlinearity

Code: Select all

 
   potnom /= 100;
   float quad = potnom * potnom;
   quad *= (1 - linearity);
   float quadlinear = quad + potnom * linearity;
then there is no division by “0” at 100%

Re: Quadratic throttle pedal map

Posted: Wed Dec 10, 2025 2:44 pm
by johu
ah, sorry potlinearity is divided by 100 before being passed to the throttle module

Re: Quadratic throttle pedal map

Posted: Wed Dec 10, 2025 5:20 pm
by muehlpower
I noticed the division by 100, but the question is why the code says

Code: Select all

   quad /= 1 / (1 - linearity);
instead of

Code: Select all

   quad *= (1 - linearity);

Re: Quadratic throttle pedal map

Posted: Wed Dec 10, 2025 7:41 pm
by johu
doh! of course

Won't release again but still fixed it. I mean either version works

Re: Quadratic throttle pedal map

Posted: Thu Dec 11, 2025 12:49 am
by arber333
May i offer Lebowski polynomal throttle function i was fascinated by it from the start...

There are three coefficients you can set in code that determine the curve. a, b, and c are floats because they can be less then 1.
x is the throttle value and y is the result.
y = a*x + b*x^2 + c*x^3

a, b and c are preset coefficients. Using them you can shape your throttle curve to your liking.
See here the excerpt from the manual...
Upto 2 analog throttles can be connected to the controller IC. Options a and b are for calibration. The IC
will measure the throttle voltage for throttle closed and throttle open. The throttle closed voltage must be
lower than the throttle open voltage.
Either one of the throttle channels can be used for variable strength regen. This can be achieved by
using negative polynomal coefficients (see the next slide)
When analog throttles are used also the 'reverse' switch can be used to select reverse.
Based on the calibration information the throttle voltage will be transformed into variable x (x1 for throttle 1,
x2 for throttle 2) in the range of 0 to 1. Out of range voltages are rounded to 0 or 1.
Variables x1,2 are transformed into variables y1,2 by means of a polynomal function (the purpose of which
is to be able to make different types of throttle response curves):

y1 = a1 x1 + b1 x12 + c1 x13
y2 = a2 x2 + b2 x22 + c2 x23

Options c and d are used to input the coefficients a1,2 , b1,2 and c1,2. Valid values are between -7.999 and
+7.999.
Based on the throttle information the motor's phase current is given by:
phase current = maximum phase current * (y1 + y2)

A negative phase current means current will flow to the battery, this is how variable strength regen can
be obtained. When the conditions are such that the throttle requested phase current means that the
maximum battery current or maximum battery regen current will be violated the phase current is
automatically reduced.
image.png

Re: Quadratic throttle pedal map

Posted: Thu Dec 11, 2025 8:41 pm
by johu
Not bad!
Go, new maintainers ;)