Go Down

Topic: multi stepper motor control question (Read 803 times) previous topic - next topic

kazimier

hello

I have been working for a bit of time on building a multi-stepper OSC controlled system. with some pretty good results, the code below gives me realtime control of multiple stepper motors using OSC ( i have been using Ableton Live for sequencing movement patters). However there is a limitation with the code I currently have, the OSC data coming in ranges from 0 - 1 this is in turn converted into 0-200 steps for the motors to move (the steppers I use have 1.8 degree incrementation). At the moment I can essentially control one rotation of the motor, I am keen to figure out a way where as the motor can be wound on multiple times, i.e. be able to turn it 5 rotations ... i guess this could be viewed as step 1000.. or if there was a way to send information in such a way that the motor can loop on itself. This way using audio sequencing software the motors would behave almost like musical loops, just continually looping for the duration of the track and at the same time completely indexable within the loop. I am not sure if I am doing a good job of explaining the problem.. but any help or advice is greatly appreciated.

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>
#include <AccelStepper.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 1, 100 };
int serverPort  = 10000;
int destPort=12000;


int flag=0;

OSCServer server;
OSCClient client;
AccelStepper stepper1(4,2,3,56,5);
AccelStepper stepper2(4,6,7,8,9);
AccelStepper stepper3(4,12,13,54,55);
AccelStepper stepper4(4,14,15,16,17);
AccelStepper stepper5(4,18,19,20,21);
AccelStepper stepper6(4,22,23,24,25);
AccelStepper stepper7(4,26,27,28,29);



long val1 = 0;
long val2 = 0;
long val3 = 0;
long val4 = 0;
long val5 = 0;
long val6 = 0;
long val7 = 0;



void setup(){
 
Serial.begin(9600);

Ethernet.begin(myMac ,myIp);
server.begin(serverPort);

//set callback function & oscaddress
server.addCallback("/1/fader1",&func1);
server.addCallback("/1/fader2",&func2);
  server.addCallback("/1/fader3",&func3);
   server.addCallback("/1/fader4",&func4);
    server.addCallback("/1/fader5",&func5);
     server.addCallback("/1/fader6",&func6);
      server.addCallback("/1/fader7",&func7);


stepper1.setMaxSpeed(300.0);
stepper1.setAcceleration(200.0);
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(200.0);
  stepper3.setMaxSpeed(300.0);
stepper3.setAcceleration(200.0);
  stepper4.setMaxSpeed(300.0);
stepper4.setAcceleration(200.0);
  stepper5.setMaxSpeed(300.0);
stepper5.setAcceleration(200.0);
  stepper6.setMaxSpeed(300.0);
stepper6.setAcceleration(200.0);
  stepper7.setMaxSpeed(300.0);
stepper7.setAcceleration(200.0);

}
 
void loop(){
 
  if(server.aviableCheck()>0){
//    Serial.println("alive! ");
  }
  stepper1.moveTo(val1);
  stepper1.run();
  stepper2.moveTo(val2);
  stepper2.run();
   stepper3.moveTo(val3);
  stepper3.run();
   stepper4.moveTo(val4);
  stepper4.run();
   stepper5.moveTo(val5);
  stepper5.run();
   stepper6.moveTo(val6);
  stepper6.run();
   stepper7.moveTo(val7);
  stepper7.run();
 
  pinMode(54, OUTPUT);
  pinMode(55, OUTPUT);
  pinMode(56, OUTPUT);
  pinMode(57, OUTPUT);
 
}


void func1(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val1 = (long)(value*200);
  Serial.println(val1);
}

void func2(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val2 = (long)(value*200);
  Serial.println(val2);
}

void func3(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val3 = (long)(value*200);
  Serial.println(val3);
}

void func4(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val4 = (long)(value*200);
  Serial.println(val4);
}

void func5(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val5 = (long)(value*200);
  Serial.println(val5);
}

void func6(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val6 = (long)(value*200);
  Serial.println(val6);
}

void func7(OSCMessage *_mes){
  float value = _mes->getArgFloat(0);
  val7 = (long)(value*200);
  Serial.println(val7);
}

PaulS

Quote
I am not sure if I am doing a good job of explaining the problem

No, I'm afraid you are not.

Quote
the OSC data coming in ranges from 0 - 1 this is in turn converted into 0-200 steps for the motors to move

So, how would you know that more than one rotation is required? That would require a value higher than 1.

Quote
or if there was a way to send information in such a way that the motor can loop on itself.

Not sure what this means. Of course a stepper motor can rotate more than 360 degrees. It is up to you to keep track of where it is, and to tell it how many steps to get to the new position that you want it at. It simply hears, from the motor controller, "step", "step", "step".

kazimier

hi paul - thanks for your reply and apologies for my clunky language.
trying to identify a way of telling the stepper that more than one rotation is required is exactly the problem. I had an idea of mapping  the osc data to a larger number of steps for example 10000 which would give me up to a maximum of 5 revolutions, but it just doesn't seem like the ideal solution. The OSC data is very precise, and can have as many decimal places as needed to increase accuracy, but being able to draw out interesting movement patterns in a sequencing software would become a lot more cumbersome. There is no way to have a value higher than 1 within OSC as far as I am aware..

with regards to being able to loop the motor - i guess what i was trying to say if there was a way to tell the motor that once it has gone past step 200 it is in effect back at step 0, and therefore able to begin the next rotational cycle without having to go backwards back to 0 which is what it currently has to do.

kf2qd

Yes - in your program that counts steps - when steps > 200 steps = 0. The only problem is that you might then just keep rotating because of other logic in your program. Either that or you reset your step count at the start of every rotations so you always move 1 turn.

What software are you currently using to control stepping? Does it have an INCREMENTAL mode instead of an ABSOLUTE mode?

Go Up