Hi There!
I am doing experiment on belt driven linear actuator, with NEMA17 motor and uStepper S driver with magnet for encoder. So, will post my code here and two major tricks i would like to solve.
First is, when i call function to change speed or angle via serial, motor either "jumps" some steps, specialy if it is near end position........so everytime i send something via serial, program stops for a moment and than continue.......is there any trick in code i could solve this? Also, i was think to add external analog input which would serve as reference for speed (velocity) and other for moving angle.
Another thing is, but probably due to inertia of motor rotor and belt gearing, is that the higher speed, the more motor is missing end position, if i wrote that is going to 600, it alway miss 600, it starts returning at around 700 or so.......+/- 20-40 would not be a problem, but +/- 200 at max speed it is. So since this is pure mechanical/inertia problem, is there any trick in uStepper maybe to try improving it?
I was think to try with bigger motor, like NEMA23 so it will have enought power maybe to fight agains inertia of system during start and stop.
thanks!!!!!
#include <uStepperS.h>
int kut = 600;
int brzina = 1000;
uStepperS stepper;
void setup(void)
{
stepper.encoder.setHome();
Serial.begin(9600);
stepper.setMaxAcceleration(28000);
stepper.setup(PID,200);
stepper.runContinous(CW);
}
void loop(void)
{
stepper.setMaxVelocity(brzina); //Max velocity of 500 fullsteps/s
if (Serial.available() > 0) {
brzina = Serial.parseInt();
}
if ((stepper.encoder.getAngleMoved())<=-kut)
{
stepper.runContinous(CW);
}
else if ((stepper.encoder.getAngleMoved())>=kut)
{
stepper.runContinous(CCW);
}
Serial.println(stepper.encoder.getAngleMoved()); //print out the current angle of the motor shaft.
}