Merge pull request #6 from bartebor/cocktailyogi
Some code cleanup, minor improvements and indentation fix
This commit is contained in:
140
EggDuino.ino
140
EggDuino.ino
@@ -1,10 +1,10 @@
|
|||||||
/* Eggduino-Firmware by Joachim Cerny, 2014
|
/* Eggduino-Firmware by Joachim Cerny, 2014
|
||||||
|
|
||||||
Thanks for the nice libs ACCELSTEPPER and SERIALCOMMAND, which made this project much easier.
|
Thanks for the nice libs ACCELSTEPPER and SERIALCOMMAND, which made this project much easier.
|
||||||
Thanks to the Eggbot-Team for such a funny and enjoable concept!
|
Thanks to the Eggbot-Team for such a funny and enjoable concept!
|
||||||
Thanks to my wife and my daughter for their patience. :-)
|
Thanks to my wife and my daughter for their patience. :-)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// implemented Eggbot-Protocol-Version v13
|
// implemented Eggbot-Protocol-Version v13
|
||||||
// EBB-Command-Reference, I sourced from: http://www.schmalzhaus.com/EBB/EBBCommands.html
|
// EBB-Command-Reference, I sourced from: http://www.schmalzhaus.com/EBB/EBBCommands.html
|
||||||
@@ -15,9 +15,9 @@ Thanks to my wife and my daughter for their patience. :-)
|
|||||||
// EBB-Coordinates are coming in for 16th-Microstepmode. The Coordinate-Transforms are done in weired integer-math. Be careful, when you diecide to modify settings.
|
// EBB-Coordinates are coming in for 16th-Microstepmode. The Coordinate-Transforms are done in weired integer-math. Be careful, when you diecide to modify settings.
|
||||||
|
|
||||||
/* TODOs:
|
/* TODOs:
|
||||||
1 collision control via penMin/penMax
|
1 collision control via penMin/penMax
|
||||||
2 implement homing sequence via microswitch or optical device
|
2 implement homing sequence via microswitch or optical device
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AccelStepper.h" // nice lib from http://www.airspayce.com/mikem/arduino/AccelStepper/
|
#include "AccelStepper.h" // nice lib from http://www.airspayce.com/mikem/arduino/AccelStepper/
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
@@ -27,87 +27,83 @@ Thanks to my wife and my daughter for their patience. :-)
|
|||||||
|
|
||||||
#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6"
|
#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6"
|
||||||
//Rotational Stepper:
|
//Rotational Stepper:
|
||||||
#define step1 11
|
#define step1 11
|
||||||
#define dir1 10
|
#define dir1 10
|
||||||
#define enableRotMotor 9
|
#define enableRotMotor 9
|
||||||
#define rotMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch
|
#define rotMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch
|
||||||
//Pen Stepper:
|
//Pen Stepper:
|
||||||
#define step2 8
|
#define step2 8
|
||||||
#define dir2 7
|
#define dir2 7
|
||||||
#define enablePenMotor 6
|
#define enablePenMotor 6
|
||||||
#define penMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch
|
#define penMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch
|
||||||
|
|
||||||
|
#define servoPin 3 //Servo
|
||||||
|
|
||||||
#define servoPin 3 //Servo
|
|
||||||
|
|
||||||
// EXTRAFEATURES - UNCOMMENT TO USE THEM -------------------------------------------------------------------
|
// EXTRAFEATURES - UNCOMMENT TO USE THEM -------------------------------------------------------------------
|
||||||
|
|
||||||
// #define prgButton 2 // PRG button
|
// #define prgButton 2 // PRG button
|
||||||
// #define penToggleButton 12 // pen up/down button
|
// #define penToggleButton 12 // pen up/down button
|
||||||
// #define motorsButton 4 // motors enable button
|
// #define motorsButton 4 // motors enable button
|
||||||
|
|
||||||
// #define CommandSMQB
|
|
||||||
//-----------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#define penUpPosEEAddress ((uint16_t *)0)
|
#define penUpPosEEAddress ((uint16_t *)0)
|
||||||
#define penDownPosEEAddress ((uint16_t *)2)
|
#define penDownPosEEAddress ((uint16_t *)2)
|
||||||
|
|
||||||
//make Objects
|
//make Objects
|
||||||
AccelStepper rotMotor(1, step1, dir1);
|
AccelStepper rotMotor(1, step1, dir1);
|
||||||
AccelStepper penMotor(1, step2, dir2);
|
AccelStepper penMotor(1, step2, dir2);
|
||||||
Servo penServo;
|
Servo penServo;
|
||||||
SerialCommand SCmd;
|
SerialCommand SCmd;
|
||||||
//create Buttons
|
//create Buttons
|
||||||
#ifdef prgButton
|
#ifdef prgButton
|
||||||
Button prgButtonToggle(prgButton, setprgButtonState);
|
Button prgButtonToggle(prgButton, setprgButtonState);
|
||||||
#endif
|
#endif
|
||||||
#ifdef penToggleButton
|
#ifdef penToggleButton
|
||||||
Button penToggle(penToggleButton, doTogglePen);
|
Button penToggle(penToggleButton, doTogglePen);
|
||||||
#endif
|
#endif
|
||||||
#ifdef motorsButton
|
#ifdef motorsButton
|
||||||
Button motorsToggle(motorsButton, toggleMotors);
|
Button motorsToggle(motorsButton, toggleMotors);
|
||||||
#endif
|
#endif
|
||||||
// Variables... be careful, by messing around here, everything has a reason and crossrelations...
|
// Variables... be careful, by messing around here, everything has a reason and crossrelations...
|
||||||
int penMin=0;
|
int penMin=0;
|
||||||
int penMax=0;
|
int penMax=0;
|
||||||
int penUpPos=5; //can be overwritten from EBB-Command SC
|
int penUpPos=5; //can be overwritten from EBB-Command SC
|
||||||
int penDownPos=20; //can be overwritten from EBB-Command SC
|
int penDownPos=20; //can be overwritten from EBB-Command SC
|
||||||
int servoRateUp=0; //from EBB-Protocol not implemented on machine-side
|
int servoRateUp=0; //from EBB-Protocol not implemented on machine-side
|
||||||
int servoRateDown=0;//from EBB-Protocol not implemented on machine-side
|
int servoRateDown=0; //from EBB-Protocol not implemented on machine-side
|
||||||
long rotStepError=0;
|
long rotStepError=0;
|
||||||
long penStepError=0;
|
long penStepError=0;
|
||||||
int penState=penUpPos;
|
int penState=penUpPos;
|
||||||
uint32_t nodeCount=0;
|
uint32_t nodeCount=0;
|
||||||
unsigned int layer=0;
|
unsigned int layer=0;
|
||||||
boolean prgButtonState=0;
|
boolean prgButtonState=0;
|
||||||
uint8_t rotStepCorrection = 16/rotMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
|
uint8_t rotStepCorrection = 16/rotMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
|
||||||
uint8_t penStepCorrection = 16/penMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
|
uint8_t penStepCorrection = 16/penMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
|
||||||
float rotSpeed=0;
|
float rotSpeed=0;
|
||||||
float penSpeed=0; // these are local variables for Function SteppermotorMove-Command, but for performance-reasons it will be initialized here
|
float penSpeed=0; // these are local variables for Function SteppermotorMove-Command, but for performance-reasons it will be initialized here
|
||||||
boolean motorsEnabled = 0;
|
boolean motorsEnabled = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
makeComInterface();
|
makeComInterface();
|
||||||
initHardware();
|
initHardware();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
moveOneStep();
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
SCmd.readSerial();
|
SCmd.readSerial();
|
||||||
|
|
||||||
#ifdef penToggleButton
|
#ifdef penToggleButton
|
||||||
penToggle.check();
|
penToggle.check();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef motorsButton
|
#ifdef motorsButton
|
||||||
motorsToggle.check();
|
motorsToggle.check();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef prgButton
|
#ifdef prgButton
|
||||||
prgButtonToggle.check();
|
prgButtonToggle.check();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
409
Functions.ino
409
Functions.ino
@@ -1,26 +1,23 @@
|
|||||||
|
|
||||||
void makeComInterface(){
|
void makeComInterface(){
|
||||||
SCmd.addCommand("v",sendVersion);
|
SCmd.addCommand("v",sendVersion);
|
||||||
SCmd.addCommand("EM",enableMotors);
|
SCmd.addCommand("EM",enableMotors);
|
||||||
SCmd.addCommand("SC",stepperModeConfigure);
|
SCmd.addCommand("SC",stepperModeConfigure);
|
||||||
SCmd.addCommand("SP",setPen);
|
SCmd.addCommand("SP",setPen);
|
||||||
SCmd.addCommand("SM",stepperMove);
|
SCmd.addCommand("SM",stepperMove);
|
||||||
#ifdef CommandSMQB
|
SCmd.addCommand("SE",ignore);
|
||||||
SCmd.addCommand("SMQB",stepperMoveQueryButton); // composite function enabling smooth movement
|
SCmd.addCommand("TP",togglePen);
|
||||||
#endif
|
SCmd.addCommand("PO",ignore); //Engraver command, not implemented, gives fake answer
|
||||||
SCmd.addCommand("SE",ignore);
|
SCmd.addCommand("NI",nodeCountIncrement);
|
||||||
SCmd.addCommand("TP",togglePen);
|
SCmd.addCommand("ND",nodeCountDecrement);
|
||||||
SCmd.addCommand("PO",ignore); //Engraver command, not implemented, gives fake answer
|
SCmd.addCommand("SN",setNodeCount);
|
||||||
SCmd.addCommand("NI",nodeCountIncrement);
|
SCmd.addCommand("QN",queryNodeCount);
|
||||||
SCmd.addCommand("ND",nodeCountDecrement);
|
SCmd.addCommand("SL",setLayer);
|
||||||
SCmd.addCommand("SN",setNodeCount);
|
SCmd.addCommand("QL",queryLayer);
|
||||||
SCmd.addCommand("QN",queryNodeCount);
|
SCmd.addCommand("QP",queryPen);
|
||||||
SCmd.addCommand("SL",setLayer);
|
SCmd.addCommand("QB",queryButton); //"PRG" Button,
|
||||||
SCmd.addCommand("QL",queryLayer);
|
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
|
||||||
SCmd.addCommand("QP",queryPen);
|
}
|
||||||
SCmd.addCommand("QB",queryButton); //"PRG" Button,
|
|
||||||
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
|
|
||||||
}
|
|
||||||
|
|
||||||
void queryPen() {
|
void queryPen() {
|
||||||
char state;
|
char state;
|
||||||
@@ -37,29 +34,29 @@ void queryButton() {
|
|||||||
sendAck();
|
sendAck();
|
||||||
prgButtonState = 0;
|
prgButtonState = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void queryLayer() {
|
void queryLayer() {
|
||||||
Serial.print(String(layer) +"\r\n");
|
Serial.print(String(layer) +"\r\n");
|
||||||
sendAck();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLayer() {
|
|
||||||
uint32_t value=0;
|
|
||||||
char *arg1;
|
|
||||||
arg1 = SCmd.next();
|
|
||||||
if (arg1 != NULL) {
|
|
||||||
value = atoi(arg1);
|
|
||||||
layer=value;
|
|
||||||
sendAck();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sendError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void queryNodeCount() {
|
|
||||||
Serial.print(String(nodeCount) +"\r\n");
|
|
||||||
sendAck();
|
sendAck();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLayer() {
|
||||||
|
uint32_t value=0;
|
||||||
|
char *arg1;
|
||||||
|
arg1 = SCmd.next();
|
||||||
|
if (arg1 != NULL) {
|
||||||
|
value = atoi(arg1);
|
||||||
|
layer=value;
|
||||||
|
sendAck();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sendError();
|
||||||
|
}
|
||||||
|
|
||||||
|
void queryNodeCount() {
|
||||||
|
Serial.print(String(nodeCount) +"\r\n");
|
||||||
|
sendAck();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNodeCount() {
|
void setNodeCount() {
|
||||||
@@ -86,212 +83,182 @@ void nodeCountDecrement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stepperMove() {
|
void stepperMove() {
|
||||||
uint16_t duration=0; //in ms
|
uint16_t duration=0; //in ms
|
||||||
int penStepsEBB=0; //Pen
|
int penStepsEBB=0; //Pen
|
||||||
int rotStepsEBB=0; //Rot
|
int rotStepsEBB=0; //Rot
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
moveToDestination();
|
||||||
sendError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendAck();
|
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
||||||
|
|
||||||
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
|
||||||
delay(duration);
|
|
||||||
//sendAck();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
doMove(duration, penStepsEBB, rotStepsEBB);
|
|
||||||
//sendAck();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CommandSMQB
|
|
||||||
void stepperMoveQueryButton() {
|
|
||||||
uint16_t duration=0; //in ms
|
|
||||||
int penStepsEBB=0; //Pen
|
|
||||||
int rotStepsEBB=0; //Rot
|
|
||||||
|
|
||||||
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
|
||||||
sendError();
|
sendError();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
|
||||||
delay(duration);
|
|
||||||
queryButton();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sending ACK before actual move to allow buffering
|
|
||||||
queryButton();
|
|
||||||
doMove(duration, penStepsEBB, rotStepsEBB);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
sendAck();
|
||||||
|
|
||||||
|
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
||||||
|
delay(duration);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareMove(duration, penStepsEBB, rotStepsEBB);
|
||||||
|
}
|
||||||
|
|
||||||
void setPen(){
|
void setPen(){
|
||||||
int cmd;
|
int cmd;
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
moveToDestination();
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
arg = SCmd.next();
|
||||||
arg = SCmd.next();
|
if (arg != NULL) {
|
||||||
if (arg != NULL) {
|
cmd = atoi(arg);
|
||||||
cmd = atoi(arg);
|
switch (cmd) {
|
||||||
switch (cmd) {
|
case 0:
|
||||||
case 0:
|
penServo.write(penUpPos);
|
||||||
penServo.write(penUpPos);
|
penState=penUpPos;
|
||||||
penState=penUpPos;
|
break;
|
||||||
break;
|
|
||||||
|
case 1:
|
||||||
case 1:
|
penServo.write(penDownPos);
|
||||||
penServo.write(penDownPos);
|
penState=penDownPos;
|
||||||
penState=penDownPos;
|
break;
|
||||||
break;
|
|
||||||
|
default:
|
||||||
default:
|
sendError();
|
||||||
sendError();
|
}
|
||||||
}
|
}
|
||||||
}
|
char *val;
|
||||||
char *val;
|
val = SCmd.next();
|
||||||
val = SCmd.next();
|
if (val != NULL) {
|
||||||
if (val != NULL) {
|
|
||||||
value = atoi(val);
|
value = atoi(val);
|
||||||
sendAck();
|
sendAck();
|
||||||
delay(value);
|
delay(value);
|
||||||
}
|
}
|
||||||
if (val==NULL && arg !=NULL) {
|
if (val==NULL && arg !=NULL) {
|
||||||
sendAck();
|
sendAck();
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
// Serial.println("delay");
|
// Serial.println("delay");
|
||||||
if (val==NULL && arg ==NULL)
|
if (val==NULL && arg ==NULL)
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
|
|
||||||
void togglePen(){
|
void togglePen(){
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
moveToDestination();
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
arg = SCmd.next();
|
||||||
arg = SCmd.next();
|
if (arg != NULL)
|
||||||
if (arg != NULL)
|
value = atoi(arg);
|
||||||
value = atoi(arg);
|
else
|
||||||
else
|
value = 500;
|
||||||
value = 500;
|
|
||||||
|
|
||||||
doTogglePen();
|
doTogglePen();
|
||||||
sendAck();
|
sendAck();
|
||||||
delay(value);
|
delay(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doTogglePen() {
|
void doTogglePen() {
|
||||||
if (penState==penUpPos) {
|
if (penState==penUpPos) {
|
||||||
penServo.write(penDownPos);
|
penServo.write(penDownPos);
|
||||||
penState=penDownPos;
|
penState=penDownPos;
|
||||||
} else {
|
} else {
|
||||||
penServo.write(penUpPos);
|
penServo.write(penUpPos);
|
||||||
penState=penUpPos;
|
penState=penUpPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enableMotors(){
|
void enableMotors(){
|
||||||
int cmd;
|
int cmd;
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
char *val;
|
char *val;
|
||||||
arg = SCmd.next();
|
arg = SCmd.next();
|
||||||
if (arg != NULL)
|
if (arg != NULL)
|
||||||
cmd = atoi(arg);
|
cmd = atoi(arg);
|
||||||
val = SCmd.next();
|
val = SCmd.next();
|
||||||
if (val != NULL)
|
if (val != NULL)
|
||||||
value = atoi(val);
|
value = atoi(val);
|
||||||
//values parsed
|
//values parsed
|
||||||
if ((arg != NULL) && (val == NULL)){
|
if ((arg != NULL) && (val == NULL)){
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 0: motorsOff();
|
case 0: motorsOff();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 1: motorsOn();
|
case 1: motorsOn();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//the following implementaion is a little bit cheated, because i did not know, how to implement different values for first and second argument.
|
//the following implementaion is a little bit cheated, because i did not know, how to implement different values for first and second argument.
|
||||||
if ((arg != NULL) && (val != NULL)){
|
if ((arg != NULL) && (val != NULL)){
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 0: motorsOff();
|
case 0: motorsOff();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 1: motorsOn();
|
case 1: motorsOn();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stepperModeConfigure(){
|
void stepperModeConfigure(){
|
||||||
int cmd;
|
int cmd;
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
arg = SCmd.next();
|
arg = SCmd.next();
|
||||||
if (arg != NULL)
|
if (arg != NULL)
|
||||||
cmd = atoi(arg);
|
cmd = atoi(arg);
|
||||||
char *val;
|
char *val;
|
||||||
val = SCmd.next();
|
val = SCmd.next();
|
||||||
if (val != NULL)
|
if (val != NULL)
|
||||||
value = atoi(val);
|
value = atoi(val);
|
||||||
if ((arg != NULL) && (val != NULL)){
|
if ((arg != NULL) && (val != NULL)){
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 4: penDownPos= (int) ((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
|
case 4: penDownPos= (int) ((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
|
||||||
storePenDownPosInEE();
|
storePenDownPosInEE();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 5: penUpPos= (int)((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
|
case 5: penUpPos= (int)((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
|
||||||
storePenUpPosInEE();
|
storePenUpPosInEE();
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 6: //rotMin=value; ignored
|
case 6: //rotMin=value; ignored
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 7: //rotMax=value; ignored
|
case 7: //rotMax=value; ignored
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 11: servoRateUp=value;
|
case 11: servoRateUp=value;
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
case 12: servoRateDown=value;
|
case 12: servoRateDown=value;
|
||||||
sendAck();
|
sendAck();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendVersion(){
|
void sendVersion(){
|
||||||
Serial.print(initSting);
|
Serial.print(initSting);
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void unrecognized(const char *command){
|
void unrecognized(const char *command){
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ignore(){
|
void ignore(){
|
||||||
sendAck();
|
sendAck();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,33 @@
|
|||||||
void initHardware(){
|
void initHardware(){
|
||||||
// enable eeprom wait in avr/eeprom.h functions
|
// enable eeprom wait in avr/eeprom.h functions
|
||||||
SPMCSR &= ~SELFPRGEN;
|
SPMCSR &= ~SELFPRGEN;
|
||||||
|
|
||||||
loadPenPosFromEE();
|
loadPenPosFromEE();
|
||||||
|
|
||||||
pinMode(enableRotMotor, OUTPUT);
|
pinMode(enableRotMotor, OUTPUT);
|
||||||
pinMode(enablePenMotor, OUTPUT);
|
pinMode(enablePenMotor, OUTPUT);
|
||||||
|
|
||||||
#ifdef prgButton
|
|
||||||
pinMode(prgButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef penToggleButton
|
|
||||||
pinMode(penToggleButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef motorsButton
|
|
||||||
pinMode(motorsButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rotMotor.setMaxSpeed(2000.0);
|
rotMotor.setMaxSpeed(2000.0);
|
||||||
rotMotor.setAcceleration(10000.0);
|
rotMotor.setAcceleration(10000.0);
|
||||||
penMotor.setMaxSpeed(2000.0);
|
penMotor.setMaxSpeed(2000.0);
|
||||||
penMotor.setAcceleration(10000.0);
|
penMotor.setAcceleration(10000.0);
|
||||||
motorsOff();
|
motorsOff();
|
||||||
penServo.attach(servoPin);
|
penServo.attach(servoPin);
|
||||||
penServo.write(penState);
|
penServo.write(penState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline loadPenPosFromEE() {
|
void inline loadPenPosFromEE() {
|
||||||
penUpPos = eeprom_read_word(penUpPosEEAddress);
|
penUpPos = eeprom_read_word(penUpPosEEAddress);
|
||||||
penDownPos = eeprom_read_word(penDownPosEEAddress);
|
penDownPos = eeprom_read_word(penDownPosEEAddress);
|
||||||
penState = penUpPos;
|
penState = penUpPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline storePenUpPosInEE() {
|
void inline storePenUpPosInEE() {
|
||||||
eeprom_update_word(penUpPosEEAddress, penUpPos);
|
eeprom_update_word(penUpPosEEAddress, penUpPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline storePenDownPosInEE() {
|
void inline storePenDownPosInEE() {
|
||||||
eeprom_update_word(penDownPosEEAddress, penDownPos);
|
eeprom_update_word(penDownPosEEAddress, penDownPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline sendAck(){
|
void inline sendAck(){
|
||||||
@@ -65,7 +53,7 @@ void motorsOn() {
|
|||||||
void toggleMotors() {
|
void toggleMotors() {
|
||||||
if (motorsEnabled) {
|
if (motorsEnabled) {
|
||||||
motorsOff();
|
motorsOff();
|
||||||
} else {
|
} else {
|
||||||
motorsOn();
|
motorsOn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,14 +73,14 @@ bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB) {
|
|||||||
}
|
}
|
||||||
if (arg3 != NULL) {
|
if (arg3 != NULL) {
|
||||||
*rotStepsEBB = atoi(arg3);
|
*rotStepsEBB = atoi(arg3);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
||||||
if (!motorsEnabled) {
|
if (!motorsEnabled) {
|
||||||
motorsOn();
|
motorsOn();
|
||||||
}
|
}
|
||||||
@@ -102,7 +90,7 @@ void doMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
|||||||
rotMotor.setSpeed( abs( (float)rotStepsEBB * (float)1000 / (float)duration ) );
|
rotMotor.setSpeed( abs( (float)rotStepsEBB * (float)1000 / (float)duration ) );
|
||||||
penMotor.move(penStepsEBB);
|
penMotor.move(penStepsEBB);
|
||||||
penMotor.setSpeed( abs( (float)penStepsEBB * (float)1000 / (float)duration ) );
|
penMotor.setSpeed( abs( (float)penStepsEBB * (float)1000 / (float)duration ) );
|
||||||
} else {
|
} else {
|
||||||
//incoming EBB-Steps will be multiplied by 16, then Integer-maths is done, result will be divided by 16
|
//incoming EBB-Steps will be multiplied by 16, then Integer-maths is done, result will be divided by 16
|
||||||
// This make thinks here really complicated, but floating point-math kills performance and memory, believe me... I tried...
|
// This make thinks here really complicated, but floating point-math kills performance and memory, believe me... I tried...
|
||||||
long rotSteps = ( (long)rotStepsEBB * 16 / rotStepCorrection) + (long)rotStepError; //correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
|
long rotSteps = ( (long)rotStepsEBB * 16 / rotStepCorrection) + (long)rotStepError; //correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
|
||||||
@@ -126,12 +114,20 @@ void doMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
|||||||
penMotor.move(penStepsToGo);
|
penMotor.move(penStepsToGo);
|
||||||
penMotor.setSpeed( penSpeed );
|
penMotor.setSpeed( penSpeed );
|
||||||
}
|
}
|
||||||
/*
|
}
|
||||||
|
|
||||||
|
void moveOneStep() {
|
||||||
|
if ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
||||||
|
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
||||||
|
rotMotor.runSpeedToPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveToDestination() {
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
||||||
rotMotor.runSpeedToPosition();
|
rotMotor.runSpeedToPosition();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setprgButtonState(){
|
void setprgButtonState(){
|
||||||
|
|||||||
@@ -44,7 +44,3 @@ http://wiki.evilmadscientist.com/Installing_software
|
|||||||
# return serialPort
|
# return serialPort
|
||||||
- In my version lines 1355-1360
|
- In my version lines 1355-1360
|
||||||
|
|
||||||
Todos and Feature-Wishlist:
|
|
||||||
|
|
||||||
- implement hardware-button , EGGBOT-Guys call it "PRG-Button"
|
|
||||||
|
|
||||||
|
|||||||
10
button.h
10
button.h
@@ -29,7 +29,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {} ;
|
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {
|
||||||
|
pinMode(pin, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
void check() {
|
void check() {
|
||||||
byte b = digitalRead(pin);
|
byte b = digitalRead(pin);
|
||||||
long t = millis();
|
long t = millis();
|
||||||
@@ -49,10 +52,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastState = b;
|
lastState = b;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}; //button
|
}; //button
|
||||||
|
|
||||||
#endif //__BUTTON_H__
|
#endif //__BUTTON_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user