Go Down

Topic: From linear to exponential PWM output (Read 19 times) previous topic - next topic

backbone

New excel file added.  :)
Both formula options are used from Rob and Techyla

Paco
Never to old to learn and I learn every day

el_supremo

Looking at a curve in Excel isn't going to tell you how it actually "feels" in practice. Instead of meddling with Excel why not just implement the equation I gave and see how it goes? Once you have a feel for how it really responds you can decide whether to leave it as it is or adjust it.

Replace this:
Code: [Select]
>>>>>>>> speedcurveValue = speedvalueWorked with the quotation to calculate the exponential power curve // added speedcurve value
with this:
Code: [Select]

// Pick one or the other version of the curve
// This is the "negative" curve
speedcurveValue = round(speedvalueWorked * speedvalueWorked / 255.0);
// This is the "positive" curve
// speedcurveValue = round(sqrt(speedvalueWorked * 255.0));


Pete

robtillaart


The excel formulas seems similar to 6 digits for almost all values of n, so you might check which one is most time / size efficient.

And yes, follow Pete's advice as "the proof is in eating the pudding"
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

backbone

Hi Pete and Rob

I will use the code dont worry.
As getting the formula correct and I like to learn what I am doing (not just copy and paste) I did the homework first in Excel.
Learned today again some valuable stuff in Arduino and Excel world.

I whished the slot car world would be that easy that one fixed curve would do the trick.
All cars and motors behave different on the tracks and then there is also different lanes that require different feel (set up).
So ONE fixed curve positive or negative is a no go....  :-)

The powercurve should be adjustable (currently is) by push buttons + and - for direct setting on the control handle or through menu structure by display.
The MEGA powered project is still prototype as the power board is still under construction so no real life testing with a motor or at the track.
I currently use two LED's for the PWM output (speed and brake) to see what happens while operating the trigger.
The speedcurveValue now is adjustable from 0 to125 and BYTE declared.
As I need both sides of the curves I have to switch formulas at the 1 value point.
if speedcurveValue = 0.1 to 0.99 then formula positive
if speedcurveValue = 1 to 2 then formula negative
speedcurveValue was initially set up as BYTE length but I guess I have to change all after this line and declare to FLOAT?

Paco
Never to old to learn and I learn every day

Techylah

I hope I was helpful.  Glad to help if I was.

I'm thinking of something totally new and better for these slot cars.  I know only the kid controllers I used 50 years ago!
I do know programming and have linearized many processes in the prepress world.

I think I'm seeing what you want to accomplish - a perfectly linear (with speed) hand controller for forward and reverse.
Since you're going to implement a lookup table anyway for speed and flexibility, let the lookup table do the whole thing, both sides of the curve and the dead zone,
say values 121 - 135, (16 values centered on 128) are zero.

Then for both the forward and the reverse you take actual speed readings for say 10 forward and 10 reverse controller settings.
You "invert" the response curves, either mathematically or graphically, and enter those values into the lookup table, interpolating the inbetweens.

Say your top speed is measured at 50 mph at full, 255 throttle.   135 is to be 0 (top of dead zone).  That means you want your controller to have 120 steps from 0 to 50 mph.
The exact middle settting, 60 + 135 = 195 should cause 25 mph.    You look at your response curve (draw a hor line) and see that 25 mph actually happened at
controller position 100.  Therefore you store a 100 in lookuptable[195].     lookuptable is an array of 255 bytes.
So far lookuptable of  135 is 0, 195 is 100, and 255 is 255.  You do this for all 120 positive speeds and all 120 reverse speeds.
You now have your table.  No on-the-fly calculations; just near instant table lookups.  Outside the dead zone, speed is perfectly linear with throttle position.
(Your code makes sure to switch the voltage direction for values below 121).

This brings up an interesting question about slot car racing.   Do people indeed want and implement a "velocity pedal", rather than an "acceleration pedal".
If so, is that only because it is hard to get the current velocity, which is what would be needed for a true accelerator pedal like in a car?
If you could read back velocity (wheel speed) and implement an accelerator in the mathemeematic sense of the term, would that be better or worse for slot car racing.
In other words, if you push the throttle position forward a little, the velocity starts constantly increasing at a slow constant rate. Push it further and the rat of speedup increases, like in a real car. 
The above described lookuptable implements a perfect, calibrated velocity pedal.

Go Up