Created Tue, 12 Nov 2013 11:15:01 +0000 by PZ2332
Tue, 12 Nov 2013 11:15:01 +0000
I've got this code in arduino I'm trying to load into chipkit, one of the libraries doesn't seem to be supported though, could anyone help me figure out an alternative?
the <SM.h> library is the one failing for me.
#include <AccelStepper.h>
#include <SM.h>
const int buttonPin = 14;
int buttonState = 0;
SM Controller(Parked);
AccelStepper stepper1(AccelStepper::FULL2WIRE, 2, 3);
void setup()
{
pinMode(buttonPin, INPUT);
stepper1.setMaxSpeed(10000.0);
stepper1.setAcceleration(14000.0);
stepper1.moveTo(64000);
}
void loop(){
buttonState = digitalRead(buttonPin);
EXEC(Controller);
stepper1.run();
}//loop()
State Parked(){//wait for sensor to be activated
if(analogRead(A2)>600){
stepper1.setCurrentPosition(0);
stepper1.stop(); }
if (buttonState == LOW)
{
Controller.Set(SlowH, SlowB);
}
else if (analogRead(A2)<600){
stepper1.moveTo(-70000);}
}//Parked()
State SlowH(){// start moving forward at slow speed
stepper1.moveTo(27000);
stepper1.setSpeed(2000);
}//SlowH()
State SlowB(){//check remainng distance while moving
if(stepper1.distanceToGo() == 0) Controller.Set(FastH, FastB);
}//SlowB()
State FastH(){
stepper1.moveTo(64000);
stepper1.setSpeed(4000);
}//FastH()
State FastB(){
if(stepper1.distanceToGo() == 0) Controller.Set(ReverseC);
}//FastB
State ReverseH(){
stepper1.moveTo(0);
}//ReverseH()
State ReverseB(){
if(stepper1.distanceToGo() == 0)
Controller.Set(ReverseC);
}//ReverseB()
State ReverseC(){
if (analogRead(A2)>600)
{
stepper1.setCurrentPosition(0);
Controller.Set(SlowH, SlowB);
}
else
{ stepper1.moveTo(-70000);
stepper1.setSpeed(-8000);
}
}
The specific error I'm recieving is : undefined reference to `timer0_millis'
Sat, 16 Nov 2013 15:41:18 +0000
What is the SM.h lib supposed to do or a link a description?
Jacob
Sat, 16 Nov 2013 15:50:18 +0000
What is the SM.h lib supposed to do or a link a description? Jacob
It looks like it may be some form of State Machine library.
Why not code it manually? After all, a state machine is really just a variable and a switch() construct. Check out [url]http://hacking.majenko.co.uk/finite-state-machine[/url]