Unable to get desired speed with AccelStepper lib.

Hello!
we are going to design a robotics arms in which we are using steppers motors for control position and speed.
We have to move the arms at a speed of 1/4 revolution in less than one seconds say in our example 0.7 sec. so the desired speed in steps/secs come out to be 74steps/sec in our calculation.we declare the speed and other requirement in the arduino sketch upon running the stepper motor move with a very slow speed.
we are using Nema17 and tb6560 stepper motor drive.below is our arduino code.
we are messing some thing in the code i thinked so if any have any idea or suggestion please help us.
Any help would be appreciated.Thanks

#include "AccelStepper.h"

#define ENABLE_PIN 3
//unsigned int rSpeed = (rpm / 60) * microStep * 200;
AccelStepper stepper(1,4,5); //driver mode,step pin,dir pin 
void setup()
{ 
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  pinMode(ENABLE_PIN, OUTPUT);           // set pin to input
  digitalWrite(ENABLE_PIN,LOW); // turn on pullup resistors
  stepper.setSpeed(74);
  stepper.setMaxSpeed(200);
 // stepper.setAcceleration(620);
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available()>0){
    String data=Serial.readString();
    Serial.println(data);
      if(data.equals("45")){
      stepper.moveTo(50); 
      }
     else if(data.equals("90")){
      stepper.moveTo(100);
     }
  }
  if(stepper.distanceToGo()==0){
    stepper.setCurrentPosition(0);
  }
 stepper.runSpeed();
}

stepper.setSpeed(rpms) where 'rpms' means the speed at which the motor should turn in rotations per minute. So change it to 4440, it should work fine then :slight_smile:

EDIT: My bad, the AccelStepper is using steps per second as a speed. Sorry for misleading you!

For the AccelStepper library speed is expressed in steps per second.

...R
Stepper Motor Basics
Simple Stepper Code

pati130013:
stepper.setSpeed(rpms) where 'rpms' means the speed at which the motor should turn in rotations per minute. So change it to 4440, it should work fine then :slight_smile:

AccelStepper uses steps per second, not RPM.

mtg:
we are using Nema17 and tb6560 stepper motor drive

When you run your test, is there something attached to the stepper motor, or is there an arm attached?

If there is an arm attached to the stepper, use acceleration ( ie set maxspeed to 74 and use stepper.Run() instead of stepper.runSpeed() ). You may not be able to move properly without acceleration. Your calculations of maxspeed will be determined by your maxaccel setting
also:

Have you double checked the settings of switch 3 and 4? are they set for whole step mode
Have you double checked the wiring of the motor?

Finally, is the NEMA 17 motor just the motor itself, or does it also have a gearbox attached.

pati130013:
stepper.setSpeed(rpms) where 'rpms' means the speed at which the motor should turn in rotations per minute. So change it to 4440, it should work fine then :slight_smile:

Still the same speed.no changes

Post a link to the datasheet for your stepper motor.

Give details of the stepper motor power supply (volts and amps).

Post the latest version of your program.

Tell us in as much detail as possible what happens when you run the program.

...R

For very small movements, like the examples you’re using, the acceleration will have to be high
remember, that with an acceleration of 106steps/sec(square), you will take 1 second to go from a speed of 0 steps per second, to 106 steps per second.

The way that accelstep works, it will accelerate then decelerate (using the acceleration rate you supplied) to get to the desired position.

If you want to get to position 50 (1/4 revolution) in 0.7 seconds calculate the acceleration rate to get to position 25 in 0.35 seconds (d = Att ==> A = d/t/t ==> A = 25/0.35/0.35 ==> A = 204)

So, using an acceleration rate of 204 will get you closer to what you want.
Setting MaxSpeed to 74 will mean that Accelstepper will try to limit the speed to close Maxspeed, again using the acceleration rate supplied

Arrg.. Sorry, I gave you the wrong formula to use :confused:

d = (A * t * t)/2

so, A = d / t / t * 2

so in the example you used, 50steps in 0.5 sec becomes 25 steps in 0.25 sec
so A = 25/0.25/0.25*2 = 800 steps/sec/sec