case 92: //BONUCE - Short Strokes digitalWrite(Enable_Pin, LOW); // Extend the shaft dirX = 0 // read the encoder and if it is not >= target then increase the step on the motor. if((stepper1.readEnc() <= 50) && (dirX == 0)){ //move the motor forward stepper1.moveTo((50 * 3.19)+1); }else{ dirX = 1; } // reverse the direction of shaft if(dirX == 1){ // Retract the shaft dirX = 1 // read the encoder and if it is not <= 1 then increase the step on the motor. if(stepper1.readEnc() >= 5){ //move the motor backward
stepper1.moveTo(5); //bring it just past the zero point to be sure }else{ dirX = 0; } } break;--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You could check if the speed is non-zero to see if the motor is running. distanceToGo() is reliable though - but remember that if you are moving at a low speed, you will not necessarily take a step every cycle, so it's correct that the distanceToGo() would not change after each cycle.I'll mention that run() itself returns a true or false, where true indicates a step was taken, and false indicates no step was taken this time, so you could look at that, and only bother checking the encoder if run() suggested a step was taken.Last thing, I came across this while writing https://github.com/euphy/AccelStepperEncoder, and that there's a physical lag between the motor being signalled to step, the motor actually moving, and the motion being transferred to the encoder (and the actual thing you're moving, moving!). In my case, I have quite a sloppy drive chain, so I have a lot of stretch and wiggle between the drive and the encoder. But the process of taking the step, and then not seeing any change on the encoder reminded me that while the software moves in discrete, instantaneous jumps, the physical nature of the beast is more complex!sn
case 93: //BONUCE - Random Moves digitalWrite(Enable_Pin, LOW); // turn on the drivedif((stepper1.readEnc() >= 50) && (stepper1.distanceToGo() == 0)){ dirX = 1; Serial.println("Shaft IN");}if((stepper1.readEnc() <= 5) && (stepper1.distanceToGo() == 0)){ dirX = 0; Serial.println("Shaft OUT");} if((stepper1.readEnc() < 50) && (dirX == 0)){ //move shaft out stepper1.moveTo((50* 3.19)+1); //bring it just past the zero point to be sure } else {// dirX = 1; } if((stepper1.readEnc() > 5) && (dirX == 1)){ //move shaft in stepper1.moveTo(5); //bring it just past the zero point to be sure } else {// dirX = 0; }
Hi,
run() returns true when the stepper has not yet reached its destination, even if the stepper was not stepped. runSpeed() returns true if the stepper was stepped.
//BONUCE - Random Moves digitalWrite(Enable_Pin, LOW); // turn on the drivedif((stepper1.readEnc() >= 50) && (stepper1.run() == 0)){ dirX = 1;// Serial.println(stepper1.run());}if((stepper1.readEnc() <= 5) && (stepper1.run() == 0)){ dirX = 0;// Serial.println(stepper1.run());} case 93: //BONUCE - Random Moves digitalWrite(Enable_Pin, LOW); // turn on the driver
if((stepper1.readEnc() >= thisrndmove) && (dirX == 0)){ dirX = 1; lastrndmove = random(5, 50); //store the last random move.// Serial.print("Shaft Out ");// Serial.println(stepper1.readEnc());}if((stepper1.readEnc() <= lastrndmove) && (dirX == 1)){ dirX = 0; thisrndmove = random(20, 100); //store the last random move.// Serial.println("Shaft In ");// Serial.println(stepper1.readEnc());} if((stepper1.readEnc() < thisrndmove) && (dirX == 0)){ //move shaft out stepper1.moveTo((thisrndmove * 3.19)+1); //bring it just past the zero point to be sure } if((stepper1.readEnc() > lastrndmove) && (dirX == 1)){ //move shaft in stepper1.moveTo((lastrndmove * 3.19)+1); //bring it just past the zero point to be sure }
break;Thanks,
So is isRunning() still required?