Topic: Curve algorithms (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30357" title="Pages that link to Topic: Curve algorithms (Page 1 of 1)" rel="nofollow" >Topic: Curve algorithms <span class="small">(Page 1 of 1)</span>\

 
Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 06-22-2008 13:51

I've got a bit of a strange request... I'm trying to work out an algorithm to calculate a set of points along an acceleration/deceleration curve. The curve itself I suppose could be your average exponential curve up to a set point after which speed is constant. My problem is the algorithm to let me work out the points along the line so I can work out the values I'll need to feed into the program that sets the acceleration at those points.

In the end it'll be about 20 points along a 2 second curve, with the Y-axis of the curve being time and the X-axis being a value between 0 and 128. I don't know if I'm explaining this particularly clearly... what I intend to use it for is setting the duty cycle period of a PWM (Pulse Width Modulation) signal to control the speed of a motor in a project I'm working on now. I'll be using an Arduino (google it if you don't know what it is. They're really cool) to control the motor, but I need to feed it the points of the curve.


Justice 4 Pat Richard

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 06-22-2008 14:22

Not 100% sure what you want : a curve accelerating, or one accelerating then decelerating, ... one whose speed max out at some point.

The following formula might do the trick ( time is the time in ms ) :

speed = 128 * sin( PI/2 * (time%2000)/2000 )

speed = 128 * ( (time%2000)/2000 )^N ... tweak N to your liking

If they don't, could you please upload a sketch of the curve's profile you're after.

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 06-22-2008 15:16

Something like this for acceleration:



and deceleration:




Justice 4 Pat Richard

(Edited by Skaarjj on 06-22-2008 15:18)

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 06-22-2008 16:09

Regular expontial and rotate/offset?

The first one, regular expont and use (-y,x).

Something like that feasible?

I don't know.

One time I needed something similiar. I normalized everything to (0,0)-(1,1) space. Gamma/exponent it, did a few other things, and all was dandy.

(Edited by warjournal on 06-22-2008 16:23)

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 06-23-2008 06:56

Uh-huh...

*blank look*

My mathematical skills in this area are practically non-existent, so I have almost no idea what you just said wj. Sorry. The points along these lines need to be calculated on the fly, I know that. I can't hard-code them because other factors in the program can affect the gradient of the (inverse) exponential curve that's being plotted. Things like current speed of the vehicle, and its length. I've already got my work for that part plotted into an algorithm, and I know what the ceiling point for speed will be, I just need to work out the algorithm to plot the increase/reduction in the PWM duty cycle at 100ms intervals along a 2 second curve. So, Y is constant, it's just X I need to worry about, I suppose.


Justice 4 Pat Richard

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 06-23-2008 08:12

// define the ceilings
ceilingX = this
ceilingY = that

// normalize to (0.0,0.0)-(1.0,1.0) space
workX = inputX / ceilingX
workY = inputY / ceilingY

// define a power
pow = 2.0

// one or the other... not sure which one you want
workX = workY^pow
workY = workX^pow

outputX = workX * ceilingX
outputY = workY * ceilingY

That's the basic power/gamma function. Should get you your acceleration curve, but you may need to mirror it or something. The decceleration should be nearly identical, but with some offset or something on the output.

That's about all I got right now. I got a touch of the brain fry.

(Edited by warjournal on 06-23-2008 08:13)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 06-23-2008 08:58

That is basically the 2nd formula I gave

warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 06-23-2008 10:05

What Poi said. But he threw in some trig, which is prolly a damn good idea. It's prolly easier to grab a quarter circle for squashing than do the post-transform junk that I vaguely tossed out.

When will I learn to read a little closer? And where's Petskull when you need him? Heh.

On a side note, trig functions always throw me off. Too many programming languages and a great of them are different. Why am I getting artifacts instead of smooth transitions? Oh, because the output range is -512 to +511. Ugh.

(Edited by warjournal on 06-23-2008 10:06)

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 06-24-2008 13:46

With the able assistance of one of my co-workers (who was a mathematician before he decided to become a developer) I wrapped my head around what you guys have been saying, and I get it. I understand now how I can create my bounded curve and get what I need out of it. Thanks!


Justice 4 Pat Richard

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 06-25-2008 18:33

Somebody knock on my cell?

Tao
Maniac (V) Inmate

From: The Pool Of Life
Insane since: Nov 2003

posted posted 06-25-2008 22:40

~runs in stage left, thwacks Petskull with a wet Trout, escapes through previously unseen trap door~



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu