AccellStepper help
total nooby here go easy on ego.
question 1) steppers start out acceleration specified every time called don't stall.
they way have , have acceleration rate first time called. after first call start out full speed every time. have tried moving following commands on place doesn't seem matter.
verticalstepper.setmaxspeed(3000); // set verticalstepper max speed
verticalstepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp
question 2) have taken following command out of code since didn't anything:
stepper.stop(); // stop fast possible: sets new target
it seems if meet condition , no longer call stepper.run() stops motor?
please enlighten me on correct usage or suggest else accelerate top speed every time called.
as can see i'm not programmer working me far.
thanks help.
ferny
question 1) steppers start out acceleration specified every time called don't stall.
they way have , have acceleration rate first time called. after first call start out full speed every time. have tried moving following commands on place doesn't seem matter.
verticalstepper.setmaxspeed(3000); // set verticalstepper max speed
verticalstepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp
question 2) have taken following command out of code since didn't anything:
stepper.stop(); // stop fast possible: sets new target
it seems if meet condition , no longer call stepper.run() stops motor?
please enlighten me on correct usage or suggest else accelerate top speed every time called.
as can see i'm not programmer working me far.
thanks help.
ferny
code: [select]
//april 2014 big dipper state machine ferny
// state machine lcd outputs case when changed
#include <accelstepper.h>
#include <liquidcrystal.h>
#include <lcdkeypad.h>
#include <wire.h>
//setup lcd pins enb, r/w gnd, rs, d4, d5, d6, d7
liquidcrystal lcd(50, 52, 42, 44, 46, 48);//pins used control lcd 8bit
accelstepper verticalstepper(1, 40, 36);
accelstepper rotarystepper(1, 41, 37);
const int homevertical = 0; //set case # name
const int downpos = 1; //set case # name
const int homerotary = 2; //set case # name
const int rotate = 3; //set case # name
const int defaultcase = 4; //set case # name
const int rotarysensorpin = 22; // sensor input pin #
const int uppersensorpin = 24; // sensor input pin #
const int startpin = 26;// lowersensorpin = 28; // sensor input pin #
int led = 13; // number of led pin
// current state we're in @ given time. want start in
// "off", set variable soff when declare it.
int currentstate = defaultcase;
// need have somewhere go when leave soff, let's pick
int nextstate = defaultcase;
// our on/off switch
//int onoffpin = 2;
int startpressed = 0;
int upsensorstate = 0;
int rotarysensorstate = 0;
void setup()
{
pinmode(startpin, input); //define sensor pin direction lowersensorpin
pinmode(uppersensorpin, input); //define sensor pin direction
pinmode(rotarysensorpin, input); //define sensor pin direction
pinmode(led, output); //define led pin direction
//verticalstepper.setmaxspeed(3000); // set stepper top speed
//verticalstepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp up
rotarystepper.setmaxspeed(3000); // set stepper top speed
rotarystepper.setacceleration(10.0); // set stepper accelleration lower # + slower ramp up
lcd.begin(16, 2);//setup lcd panel 16 character 2 line lcd shield
lcd.clear(); //clear lcd panel
lcd.setcursor(0,0); //set position 0 line 0
lcd.print("ferny case "); //set 1st line lcd max 16 characters or spaces
lcd.setcursor(0,1); //set position 0 line 1
lcd.print("example "); //set 2nd line lcd max 16 characters or spaces
delay(2000); //wait see message before clearing lcd panel
lcd.clear(); //clear lcd panel
//delay(2000);
// if didn't set initial state when created variable,
// we'd here. initial state "off" or "start" in most
// state machines, if have active/on states, pick an
// appropriate starting state.
// currentstate = soff;
}
void loop()
{
switch(currentstate)
{
case defaultcase:
{
startpressed = digitalread(startpin);
lcd.setcursor(0,0); //position 0 line 0
lcd.print("defaultcase"); //1st line lcd max 16 characters or spaces
//wait switched input start cases
delay(100);
if (startpressed == high) {
digitalwrite(led, high); //turn led on:
currentstate = defaultcase;
nextstate = homevertical; //change state
}
else {
digitalwrite(led, low ); // turn led off:
currentstate = nextstate;
nextstate = defaultcase; //change state
lcd.clear();
}
break;
case homevertical:
{
verticalstepper.setmaxspeed(3000); // set verticalstepper max speed
verticalstepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp up
upsensorstate = 0; //define upsensorstate variable
//lcd.clear();
lcd.clear(); //clear lcdpanel
lcd.setcursor(0,0); //position 0 top line 0
lcd.print("homevertical"); //print 1st line lcd max 16 characters
{
while (digitalread(uppersensorpin) == low) { //move motor while uppersensorpin not blocked stop when is
verticalstepper.move(1000); //move enough steps hit uppersensor
verticalstepper.run();
//{
// verticalstepper.stop(); // stop fast possible: sets new target
//}
verticalstepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp up
//delay(1000);
currentstate = nextstate;
nextstate = homerotary;
}
}
}
break;
case downpos:
{
lcd.setcursor(0,0); //position 0 line 0
lcd.print("downpos"); //1st line lcd max 16 characters or spaces
delay(1000);
lcd.clear();
currentstate = nextstate;
nextstate = rotate;
}
break;
case homerotary:
{
lcd.clear();
lcd.setcursor(0,0); //position 0 line 0
lcd.print("homerotary"); //1st line lcd max 16 characters or spaces
rotarystepper.setmaxspeed(3000); // set stepper top speed
rotarystepper.setacceleration(50.0); // set stepper accelleration lower # + slower ramp up
rotarysensorstate = 0;
{
while (digitalread(rotarysensorpin) == low) {//move rotory stepper until sees rotaryhome sensor stop
rotarystepper.move(1000); // move rotarystepper enough steps see rotarysensorsensor
rotarystepper.run();
currentstate = nextstate;
nextstate = rotate;
}
}
}
break;
case rotate:
{
lcd.setcursor(0,0); //position 0 line 0
lcd.print("rotate"); //1st line lcd max 16 characters or spaces
delay(1000);
lcd.clear();
currentstate = nextstate;
nextstate = defaultcase;
}
break;
}
}
}
if you
can be
bothered
to use
tools +
auto
format
to make
that code
readable,
i can then
be bothered
to read it.
can be
bothered
to use
tools +
auto
format
to make
that code
readable,
i can then
be bothered
to read it.
Arduino Forum > Using Arduino > Programming Questions > AccellStepper help
arduino
Comments
Post a Comment