Motor Shield V2 AccelStepper issue: stop() eliminates accele

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
ajnorster
 
Posts: 5
Joined: Sun May 15, 2011 3:43 pm

Motor Shield V2 AccelStepper issue: stop() eliminates accele

Post by ajnorster »

I am using the Arduino Uno and the V2 Motorshield with the Accelstepper library to implement control of two stepper motors with a joystick. To get some finer control I would like to accelerate slowly each time the person starts to press the joystick forward. The first time I execute a move with the joystick the acceleration works normally, however every time thereafter the motor simply turns back on. I was wondering if anyone has a better understanding of this library and could explain how to better use stop().

Code: Select all



//LIBRARIES -----------------------------------------------------------

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

//DEVICES -----------------------------------------------------------

Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);

//FUNCTIONS -----------------------------------------------------------

void forwardstep1() {  
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {  
  myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {  
  myStepper2->onestep(BACKWARD, DOUBLE);
}

AccelStepper stepper1(forwardstep1, backwardstep1);     // wrappers
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()
{  

  AFMStop.begin(); // Start the top shield
   
  stepper1.setMaxSpeed(100.0);
  stepper1.setAcceleration(200.0);
  stepper1.moveTo(500);
    
  stepper2.setMaxSpeed(200.0);
  stepper2.setAcceleration(300.0);
  stepper2.moveTo(500);


}

//MAIN LOOP -----------------------------------------------------------

void loop()
{
  int xAxis = analogRead(A0);
  int yAxis = analogRead(A2);
  
 
  if (xAxis >=600){ // Full speed up to 300
    stepper1.move(200);
    stepper1.run();
  }
  else if (xAxis < 600) {
    stepper1.stop();
  }

 
}
Thanks!

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 AccelStepper issue: stop() eliminates ac

Post by adafruit_support_bill »

I'm not that familiar with the internals of that library. According to the documentation, stop should respect the acceleration parameters:
http://www.airspayce.com/mikem/arduino/ ... a76c00aced
Sets a new target position that causes the stepper to stop as quickly as possible, using to the current speed and acceleration parameters.

ajnorster
 
Posts: 5
Joined: Sun May 15, 2011 3:43 pm

Re: Motor Shield V2 AccelStepper issue: stop() eliminates ac

Post by ajnorster »

That's why I was confused too. The motor doesn't decelerate but just stops dead and starts back up again. I can't find anyone else talking about this issue, so maybe it's just me.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”