Go Down

### Topic: motor controller velocity profile (easeInOutCubic) (Read 593 times)previous topic - next topic

#### roypardi

##### Aug 25, 2007, 04:51 pm
Maybe some can give me a nudge in the right direction:

I am writing a motor controller (will be in C/Wiring but modeling it in Actionscript). To avoid "jerking" when the motor starts and stops I want to ramp the motor speed. The standard way of doing this is through a trapezoidal velocity profile: constant acceleration by fixed amount at beginning + end of move. i.e.:

-----------------------------------------
/                                                 \
/                                                   \

This works fine but gives a rather "flat" motion profile and I am trying to use Penner's 'easeInOutCubic' function instead.

Ok - here's the question (if you have read this far...;-):
I need to map the  distance-based acceleration that the function yields to values for controlling the motor speed so I can ramp up/down the motor speed based on the distance to be traveled.

The motor is being PWM with a start speed of 60 and a max speed of 255 - so I need to ramp proportionally from 60 > 255 and back down to 60 over an arbitrary distance.

Seems like it is a simple math problem since I know the acceleration- ut I am having trouble getting my brain around it. Code below.

Whew!~

--Roy

Code: [Select]
`//this is AS 2- function easeInOutCubic(t, b, c, d) {  if ((t /= d/2)<1) {     return c/2*Math.pow(t, 3)+b;  } return c/2*(Math.pow(t-2, 3)+2)+b;}///ball_mc = this.createEmptyMovieClip("ball", this.getNextHighestDepth());ball_mc.moveTo(0, 0);ball_mc.lineStyle(8, 0x000000);ball_mc.lineTo(50, 0);ball_mc.lineTo(50, 50);ball_mc.lineTo(0, 50);ball_mc.lineTo(0, 0); ball_mc._y = 100; // ball_mc.time     = 0; //timeball_mc.begin    = ball_mc._x; //beginball_mc.change   =  Stage.width - (ball_mc.begin + ball_mc._width); //changeball_mc.duration = 20; //durationball_mc.active   = true;ball_mc.lastX    = ball_mc.begin;//ball_mc.onEnterFrame = function() {   if (this.active) {         xPos = easeInOutCubic(ball_mc.time++, this.begin, this.change, this.duration);         acceleration =xPos-this.lastX;      //         trace(acceleration);      //         this.lastX = xPos;         this._x = xPos;         if (this.time >this.duration) {      this.active = false;         }    }};`

Go Up

Please enter a valid email to subscribe