Hi,
I'have got some troubles with my programme.
All my connexion are good, everything have been test before.
Two NEMA 17 stepper motors are driven by a Shield cnc shield and two a4988.
Both engines must, at each call of the "deplace" function, move a certain number of steps (argument of the function "deplace") multiplied by the "coef" int.
They must move for the same duration for each call, the speed of the one who makes the smallest number of steps therefore adapts to the speed of the one who makes the bigger number in order to arrive at there target position at the same time.
That works when x>y or when x=y.
But it doesn't work when y>x.
Does someone could explain me wath is wrong with my program ?
//Deux moteurs pas à pas NEMA 17 sont piloté par un cnc Shield et deux a4988.
//Les deux moteurs doivent, à chaque appel de la fonction "deplace", de déplacer d'un certain nombre de pas (argument de la fonction déplace) multiplié par le coef.
//Ils doivent se déplacer durant la même durée pour chaque appel, la vitesse de celui qui fait le plus petit nombre de pas s'adapte donc à la vitesse de celui qui fait le plus grand nombre.
#include <AccelStepper.h>
AccelStepper Xaxis(1, 2, 5); // pin 2 = step, pin 5 = direction
AccelStepper Yaxis(1, 3, 6); // pin 3 = step, pin 6 = direction
int coef=200; // coef multiplicateur utile pour le programme final
void setup() {
delay(1000); // Moment s'attente pour observer les moteurs
Xaxis.setMaxSpeed(1000);
Yaxis.setMaxSpeed(1000);
deplace(3,6);
deplace(9,3);
deplace(4,1);
deplace(-8,5);
deplace(3,6);
deplace(3,-3);
deplace(1,2);
deplace(3,6);
}
void loop() {
}
void deplace(int x,int y) {
Xaxis.move(x*coef);
Yaxis.move(y*coef);
if(x>y){
Xaxis.setSpeed(1000);
Yaxis.setSpeed(1000/x*y);
while(Xaxis.distanceToGo()!=0){
Xaxis. runSpeedToPosition();
Xaxis.move(Xaxis.distanceToGo());
Yaxis. runSpeedToPosition();
Yaxis.move(Yaxis.distanceToGo());
}
}
else if (x=y){
Xaxis.setSpeed(1000);
Yaxis.setSpeed(1000);
while(Xaxis.distanceToGo()!=0){
Xaxis. runSpeedToPosition();
Xaxis.move(Xaxis.distanceToGo());
Yaxis. runSpeedToPosition();
Yaxis.move(Yaxis.distanceToGo());
}
}
else {
Xaxis.setSpeed(1000/y*x);
Yaxis.setSpeed(1000);
while(Yaxis.distanceToGo()!=0){
Yaxis. runSpeedToPosition();
Yaxis.move(Yaxis.distanceToGo());
Xaxis. runSpeedToPosition();
Xaxis.move(Xaxis.distanceToGo());
}
}
delay(1000);
}
Arnaudz:
They must move for the same duration for each call, the speed of the one who makes the smallest number of steps therefore adapts to the speed of the one who makes the bigger number in order to arrive at there target position at the same time.
The AccelStepper library is specifically NOT suitable for that. Either use the MultiStepper version of the library (which does not use acceleration) or write your own code.
Robin2 I found help in using multistepper. But I thought have to use accelstepper Library in order to use multistepper. I'll take a look on it.
PaulS, if you really nead to know, my motors are black
I think that setSpeed() take a float argument so I'm not sure the program is going to make a difference between 1000 and 1000.0 But if you really need to know integer division doesn't biting me in the posterior
Thank you for the time you took to help me, this problem is solve !
I think that setSpeed() take a float argument so I'm not sure the program is going to make a difference between 1000 and 1000.0 But if you really need to know integer division doesn't biting me in the posterior
Suppose that you decide that you need to step a bit farther.
deplace(40,60);
Yaxis.setSpeed(1000/x*y);
What is 1000/(40*60)? If you said anything other than 0, you'd be wrong.
By the way, what happens if you want to move in only one axis?