gradual increase and decrease in motor movements instead of a constant speed.

Greetings everyone in arduino land.

I am making a computer/arduino controlled camera dolly system for shooting camera moves in animation.

The way it works is that when I hit capture on the software which triggers my camera to take a photo, the software sends the letter 'P' across the serial port to an arduino with motor shield i have hooked up to a motor, which will run for a bit, pushing the camera along a stage by 1mm.

so when we put all the photos together as a sequence we have a steady movement like this:

http://www.vimeo.com/18345232

and you can see the setup working here:

http://www.vimeo.com/18343986

Now here is my problem: The director doesn't simply want constant movement in one direction, he wants a gradual increase in speed from a stop until hitting a constant speed. In animation we call it a 'tween'.... most movements require a couple of frames with tiny movement you can barely see, then a couple slightly bigger movement, and on until you reach your constant, then it slows down to a halt. This makes the movement appear much more graceful and natural.

So here is the script i have spliced together from a couple i found which is the firmware for my arduino:

*/

include

AF_Stepper motor(48, 2); byte inbyte = 0;

void setup() { Serial.begin(56000); //open the serial port motor.setSpeed(200); // 200 rpm }

void loop() { /* Read one byte (one character) from serial port. If Dragon Stop Motion sends the character "P" it must be the "PF" (Position Frame) command. Lets move the camera to the next position. */ inbyte = Serial.read(); if (inbyte == 'P') motor.step(50, BACKWARD, MICROSTEP); //(number of steps, direction, step type) }

So as you can see, when it receives a P, my motor moves 50 steps. So if you could view it in a table it would be like:

frame distance in steps 1 50 2 100 3 150

and so on.

but what i want is:

1 4 2 4 3 4 4 8 5 8 6 8 7 8 8 12 9 12 10 12 11 16 12 16 13 16 14 16

until reaching 50 steps, maintaining that for maybe 200 frames, before doing the reverse and slowing to a halt.

Any ideas are welcome, i am still very new to programming in general.

I think the micro controllers firmware has to somehow count each P que as it receives them, assigning them a value which will correspond with the frame number we are up to in the software,

then it needs to move the motor in increments i have already written.

I don't need a formula or algorithm to work out the tweening for me i am happy to type out how much movement is needed in every frame, probably in excel and then copy past to arduino somehow.

thanks in advance, mark.

First: Looking cool!

Second:
This might get you on the right track: NOT TESTED

#include "AF_Stepper.h" //THIS LINE WAS MISSING, CHECK THAT IT IS RIGHT

AF_Stepper motor(48, 2);

unsigned long currentFrame = 0;
byte inbyte = 0;

void setup() {
	Serial.begin(56000); //open the serial port
	motor.setSpeed(200); // 200 rpm
}

void loop() {
	/*
	Read one byte (one character) from serial port.
	If Dragon Stop Motion sends the character "P"
	it must be the "PF" (Position Frame) command.
	Lets move the camera to the next position.
	*/
	inbyte = Serial.read();
	if (inbyte == 'P') {
		int steps = stepsFromFrame(currentFrame++);
		motor.step(50, BACKWARD, MICROSTEP); //(number of steps, direction, step type)
	}
	//TODO set or reset the framecounter?
}  

/*
	Here we define a set of rules for how the number of steps relate to the current frame
	This could be an algorithm or a set of if, else if
*/
int stepsFromFrame(unsigned long frame) {
	if (frame<3) {return 4;}
	else if (frame<7) {return 8;}
	else if (frame<10) {return 12;}
	else if (frame<14) {return 16;}
	//if no rules apply, do not move
	return 0;
}

Hi there

How about this?

 (#include "AF_Stepper.h" //THIS LINE WAS MISSING, CHECK THAT IT IS RIGHT

 AF_Stepper motor(48, 2);

unsigned long currentFrame = 0;
unsigned long nextStep;
byte inbyte = 0;

void setup() {
  Serial.begin(56000); //open the serial port
  motor.setSpeed(200); // 200 rpm
}

void loop() {
  /*
	Read one byte (one character) from serial port.
   	If Dragon Stop Motion sends the character "P"
   	it must be the "PF" (Position Frame) command.
   	Lets move the camera to the next position.
   	*/
  inbyte = Serial.read();
  if (inbyte == 'P') {
    currentFrame = currentFrame + 1;
    if (currentFrame <=49) {nextStep = currentFrame/3*4 + 4;} // Ramping up - integer math helps here
    if ((currentFrame >= 50) && (currentFrame <=200)) {nextStep = 68;} // Constant speed
    if ((currentFrame >= 200) && (currentFrame <=250)) {nextStep = 68 - ((currentFrame - 200)/3*4 + 4);} //Ramping down
    motor.step(nextStep, BACKWARD, MICROSTEP); //(number of steps, direction, step type)
  }
}

It might be a good idea to check if Serial is avaible before reading?

-Fletcher

oh wow thanks for the rapid responses.. and for doing it for me! reading through it looks very promising, just working on the mechanical side of things but hopefully very soon will try doing a motorised camera move on a motorised object, both easing in and out of movements will post the results.

It looks like the AccelStepper library now supports that motorshield:

http://www.open.com.au/mikem/arduino/AccelStepper/

Personally I prefer the more natural acceleration/deceleration motion as opposed to a linear ramp up/ramp down motion. Can't speak for your director.

thanks for the link spambake, looks good i will download and check it out.

Hi. I have actually the same problem. Did you had any success with the 'accelStepper' link? I would appreciate if you could post your final script (I'm more into animation than programming...)

cheers

...this is a nice basic instruction (unfortunetly with no ease in/out): http://canon-hf100.blogspot.com/2009/07/diy-camera-motion-control_09.html

no i haven’t gotten any further with this because the electronics i was using died and now the boss is getting me to work on other things for now…

but the above script is a pretty good start no?

What is the "AF_stepper.h"? I can't find it anywhere and it's not possible to include it in the script!

thanks

you have to download it, it's for the electronics i bought (motor shield from ada fruit) though since i blew one of the H-bridges pretty easily i'm now using a stepper driver (with a knob for voltage limiting) and using the existing arduino stepper library, go to examples and choose stepper and i think the example is called motor knob.