Some math questions (Acceleration Curves)

I am working on a stepper based motion control device. It is to help me animate somethings. I am trying to recreate the feature of my animation software in hardware, and need some help discerning what is going on. The way it works is a start frame and end frame are put in, an 'ease in\out value' and then the 'position' is the movement. So, for instance, in the top graph, from frame 1 to frame 100 each frame progression will cause the motion control axis to move an amount that will get it to the stop position.. As you can see there are some simple acceleration curves thrown in. I do not know how to recreate these. I am no math wiz!

Any insight would be awesome!

Here is a screenshot of the software.

What you're looking for is some kind of Interpolation

You should make a function along these lines: NOT AT ALL TESTED, 'PSEUDOCODE'

float animatedValue(int currentFrame, int startFrame, int endFrame, int easeIn, int easeOut, int positionFrom, int positionTo) {
  float positionModifier = 0;
  float easeInProgress = (currentFrame - startFrame) / easeIn;
  //use easeInProgress (which is from 0 to 1 and above) to generate your position while it eases in
  //calculate positionModifier 

  float easeOutProgress = (currentFrame - (endFrame - easeOut)) / easeOut;
  //same as the previous
  //calculate positionModifier 

  //if neither ease in or ease out
  return positionTo;

  //else
  return (float)positionFrom +  positionModifier;
}

Apha,

You rule! Truly rule these forums. Thanks for the immediate input!

So. If you wanted to graph these functions, how would you start? I want to show this exact interface on a tft. I basically understood the part you described, as I once coded a HPGL plotter in Quick BASIC… It had accleration curves defined as ‘Unit/Minute’… It had no requirement to graph the curves.

I am trying to figure out how to show this interface on a GLCD TFT… Thanks!

Hey guys,
Hi im working ina very similar idea,
a have a very nice acceleration and deccelleration program which works with the sparkfunks easy driver, v4.4
i found the arduino code in the old arduino forum and it works very very nice. i made also to many diferent experiments with the accelstepper library,
You could attach your variables with the following code and dont forget say thanks to C Eckert…

/*

= Project: S curve
= Language: Arduiino r12
= Date: January 2008
= Author: C. Eckert

*/

// Givens
long ta = 3e6; // acceleration time (microsec)
long td = 3e6; // decelleration time (microsec)
long Vm = 3200; // steady state velocity (pulse/sec)
long Pt = 12800; // total number of pulses for move (1600 steps per rev)

// Other variables
long dly; // stepper pulse delay (microsec)
long t = td/9; // current time (microsec) - You need to seed the initial time with something > 0
// so you don’t calculate to long of a delay
long t12; // time during constant velocity (microsec)

int count = 0; // count the number of pulses
int Perr = 0; // error in position

// Arduino pins
#define dirPin 3
#define stepPin 12

void setup() {
Serial.begin(9600);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);

// Calculate the time at constant velocity
t12 = (Pt/(Vm/1e6))-0.5*(ta+td);
Serial.println(); Serial.println();

Serial.println(“Setup Done”);
}
void loop()
{
digitalWrite(dirPin, LOW); // Set the stepper direction

// Decide which part of the velocity curve your at
if (t<ta) { // Acceleration
//Serial.println (“Acceleration Curve”);
dly = (ta)/(2*(Vm/1e6)t);
}
else if (t>=ta && t<(ta+t12)){ // Constant velocity
//Serial.println (“Constant Velocity”);
dly = 1/(2
(Vm/1e6));
}
else if (t>=(ta+t12) && t<(ta+t12+td)){ // Deceleration
//Serial.println (“Deceleration Curve”);
dly = 1/(2*((Vm/1e6)-(Vm/(1e6td))(t-ta-t12)));
}

t = t+2*dly; // update the current time
//Serial.print(“dly: “); Serial.print (dly); Serial.println(” microsec”);
//Serial.print (“Current time: “); Serial.print(t); Serial.println(” microsec”);

// Move stepper one pulse using delay just calculated
digitalWrite(stepPin, HIGH);
delayMicroseconds(dly);
digitalWrite(stepPin, LOW);
delayMicroseconds(dly);
count ++;

// The move is finished
if (t>(ta+t12+td)){
Serial.println (“Move Complete”);
Serial.print ("Total steps indexed: "); Serial.println (count);

// Correct for any position error due to rounding
Perr = Pt-count;
if (Perr < 0) {
digitalWrite(dirPin, 1^digitalRead(dirPin)); // reverse the stepper direction
delay(50);
Perr = -1*Perr;
}
for (;Perr>0;){
digitalWrite(stepPin, HIGH);
delayMicroseconds(dly);
digitalWrite(stepPin, LOW);
delayMicroseconds(dly);
Perr–;
}

count=0;
t=td/9;

delay (1000);
}

}