Go Down

Topic: Stepper motors turn less then value shown on serial monitor (Read 741 times)previous topic - next topic

jojoboli

Hi guys any help is welcome

I am trying to move two tables to make circle something like  g2 code in cnc programing
It seems to me all calculations is done correctly the numbers printed on serial monitor is right but stepper motors move 100 steps only.

here is the code
Code: [Select]
`#include <AccelStepper.h>#include <AFMotor.h>float axis_x = 50 ;float radius = 50 ;float axis_y = 0  ;float steps = 200 ;   //if pich of the screw is 5mm and stepper motor is 180 steps per revolution 36 steps is 1mm float point_e  ;float point_f = 0.5 * 200 ;int var ;// two stepper motors one on each portAF_Stepper motor1(200, 1);AF_Stepper motor2(200, 2);// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!// wrappers for the first motor!void forwardstep1() {    motor1.onestep(FORWARD, SINGLE);}void backwardstep1() {    motor1.onestep(BACKWARD, SINGLE);}// wrappers for the second motor!void forwardstep2() {    motor2.onestep(FORWARD, SINGLE);}void backwardstep2() {    motor2.onestep(BACKWARD, SINGLE);}// Motor shield has two motor ports, now we'll wrap them in an AccelStepper objectAccelStepper stepper1(forwardstep1, backwardstep1);AccelStepper stepper2(forwardstep2, backwardstep2);void setup(){    Serial.begin(9600);      stepper1.setMaxSpeed(100.0);    stepper1.setAcceleration(100.0);  //stepper1.moveTo(axis_y);        stepper2.setMaxSpeed(100.0);    stepper2.setAcceleration(400.0);    //stepper2.moveTo(point_e);   }void loop(){   while(var < 100 ){                                   // axis y moves 0.5 milimetere every loop 100 times    axis_y = axis_y + 0.5 ;      var++;     Serial.println (var) ;     delay(10);     Serial.println  (point_f , 2) ;                       //print out to serial monitor  axis y       delay(10);       float side_a = axis_x ;                            //side_a takes value from axis_x     axis_x = sqrt(sq(radius) - sq(axis_y)) ;          //calculate axis_x value              point_e =  (side_a - axis_x) * steps ;        //calculate point_e = difference from privius axis_x  and current axis_x      Serial.println  (point_e, 2) ;                //print out to serial monitor point_e  value multiplied by number of steps divided by pitch of the screw        delay(10);                    stepper1.moveTo(point_f);   //stepper1 motor should turn 100 steps every loop, but it doesn't motor turns half turn                 stepper2.moveTo(point_e);   //stepper2 motor should move point_e value, which is 0.5 steps and increase every loop up to 1410.67 steps             stepper1.run();         // but it doesn't,  motor turns half turn             stepper2.run();               }     }`

Grumpy_Mike

Normally this happens when you are trying to go too fast. Drop the speed by half and see if it still happens.

Go Up

Please enter a valid email to subscribe