Go Down

Topic: Animation Easing w servos AND steppers together (Read 2158 times) previous topic - next topic


I've finished another library!  It does animation easing or Tweening with 6 servos and 2 steppers at the same time.  You are not limited to just one easing template.  Each servo can have it's own script.  They run simultaneously and are non-blocking with much processing power left over.  The beauty is that both servos and steppers can use the same easing data template to generate the exact same movement on their shaft.  The major difference is the maximum speed and resolution by a factor of 10x.  Servo wins one, Stepper the other.  You can vary the speed and range independently.  Sorry if I'm using the wrong language here.  Maybe this link will help. 


I am unfamiliar with the 3D animation software that is available on a PC or Mac.  How do I get the data from the PC to Uno without a lot of manual effort?  So you can experiment and try each new idea within a minute?  So far I've used a spreadsheet to transfer it into the compiler as an array.

I would love to be able to read a native 3D animation file from an SD card.  I don't even know which vendor to look at to begin.


Should I move this to the motor forum instead? 
It's not really a motor question.  I got that part working already.
Nor is it a PC interface problem.  I want to read it from an SD card.
I just don't know which PC application data file format to use.
Is there a common format like CSV for 3D animation?


Do you want to help by testing this when I'm finished the next version?  Anyone?
What is the best way to get Easing data into the Sketch?


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"


This is the single motor version.  Not so different from 8 motors, but easier to understand.
Works with either Steppers OR Servos.  Next version both together.

Code: [Select]
// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, which is readily available on eBay for $4.25 inc shipping,
// using a ULN2003 interface board to drive the stepper.
#include <Servo.h>
#define dw digitalWrite
#define dm delayMicroseconds
#define wr32 Serial.write(32);
#define wr13 Serial.write(10);
const int mp1 = 4; // Blue   - 28BYJ48 pin 1
const int mp2 = 5; // Pink   - 28BYJ48 pin 2
const int mp3 = 6; // Yellow - 28BYJ48 pin 3
const int mp4 = 7; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 VCC
int motorSpeed=3000;    // set stepper speed, period actually
int stepnum=0;          // current microstep 0-7
int movecnt=0;          // running total of steps taken in move(), &=4095 in moveto
long ems,mst,m;         // millis()
int maxmove=0;          // ease()
float prev=45;          // eo_servo
Servo myservo;          // 22-155 deg

void setup() {
  pinMode(mp1, OUTPUT);
  pinMode(mp2, OUTPUT);
  pinMode(mp3, OUTPUT);
  pinMode(mp4, OUTPUT);
  pinMode(13, OUTPUT);  //onboard LED
  myservo.attach(11);  //pin 11 end of row
  ems=micros(); //init easeoften() end of setup
void loop(){
//delay(10);  // <chgms/multsp-10
delayMicroseconds(m/2); //m/2 safe
int eo_servo(){
//multsp <1 jerky >4 plateau shaped
const float cellD2=6514; //ease.xls
const float multsp=3,multdeg=1.1;
const int degoffset=-22; //-22
const int chgms=74,mspa[]={ //from easeoften()
int ii=chgms/multsp;
//int n=millis();
while(((m=millis())%ii)>5); //always catch 0? servo interrupt skipped this ==0
int i=mspa[m/ii];
int deg=(prev+0.5+degoffset)*multdeg;
int eo_degrpm(int deg, int rpm100) {
//no floats used in easeoften()
const int chgms=74,rpm=2000,degmov=90; //from ease.xls
//return(easeoften(deg,rpm100)); //calcs floats every iteration
int easeoften(int adjdist, int adjspeed){
//do not change adjspeed,dist once you begin
//call every << return() micros about r/2
//line interval 74ms 20RPM see ease.xls
const int chgms=74,mspa[]={
int easi=millis()/(chgms-adjspeed+adjdist); //might be late, plus adjspeed is shorter cuz faster
long i=abs(mspa[easi]);
if(!i)return(0); //done
long j=abs(mspa[easi+1]);  //next speed wrong 0 during last line
j-=long(adjspeed)*j/chgms;  //not important used for return only
boolean bcw=(mspa[easi]>0);
if(bcw)stepnum++; else stepnum--;
if(bcw)movecnt++; else movecnt--;
motorSpeed=1; //1?
//no time to print
while(micros()<ems){  //blocking do something else too? 
//if(movecnt%55==0){  //5 deg
if(j<i)i=j; //j or i smaller guess worst case, i is usually correct, so wrong 1/2 of the time
return(i); //could be too short to wait for next step, j not adj4speed above?, check micros()>ems+i-100 in loop
void st07(){
if(stepnum== 8)stepnum=0;
case 0:
  dw(mp4, HIGH);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, LOW);
case 1:
  dw(mp4, HIGH);
  dw(mp3, HIGH);
  dw(mp2, LOW);
  dw(mp1, LOW);
case 2:
  dw(mp4, LOW);
  dw(mp3, HIGH);
  dw(mp2, LOW);
  dw(mp1, LOW);
case 3:
  dw(mp4, LOW);
  dw(mp3, HIGH);
  dw(mp2, HIGH);
  dw(mp1, LOW);
case 4:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, HIGH);
  dw(mp1, LOW);
case 5:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, HIGH);
  dw(mp1, HIGH);
case 6:
  dw(mp4, LOW);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, HIGH);
case 7:
  dw(mp4, HIGH);
  dw(mp3, LOW);
  dw(mp2, LOW);
  dw(mp1, HIGH);



Happy to see you are alive sbright33..I was worried.


It would help a lot if you format the code before posting it!.


Go Up