Version 1.4

This commit is contained in:
cocktailyogi
2015-03-29 11:38:26 +02:00
parent d8cc9bdccd
commit f4b7367399
4 changed files with 52 additions and 98 deletions

View File

@@ -24,7 +24,7 @@ Thanks to my wife and my daughter for their patience. :-)
#include <Servo.h>
#include "SerialCommand.h" //nice lib from Stefan Rado, https://github.com/kroimon/Arduino-SerialCommand
#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.3"
#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.4"
//Rotational Stepper
#define step1 11
#define dir1 10
@@ -37,6 +37,7 @@ Thanks to my wife and my daughter for their patience. :-)
#define penMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch
//Servo
#define servoPin 3
#define PrgButton 2 //optional Pushbutton between Pin and Ground to use certain functions with Eggbot-Inkscape extension
//make Objects
AccelStepper rotMotor(1, step1, dir1);
@@ -48,19 +49,17 @@ Thanks to my wife and my daughter for their patience. :-)
int penMin=0;
int penMax=0;
int penUpPos=5; //can be overwritten from EBB-Command SC
int penDownPos=30; //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 servoRateDown=0;//from EBB-Protocol not implemented on machine-side
uint8_t rotStepMode=16; //1/16 by default, can be changed by EBB protocol, used as correction factor
uint8_t penStepMode=16; //1/16 by default, can be changed by EBB protocol, used as correction factor
long rotStepError=0;
long penStepError=0;
int penState=penUpPos;
uint32_t nodeCount=0;
unsigned int layer=0;
int prgButtonState=0;
uint8_t rotStepCorrection = rotStepMode/rotMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
uint8_t penStepCorrection = penStepMode/penMicrostep ; //devide EBB-Coordinates by this factor to get EGGduino-Steps
boolean prgButtonState=0;
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
float rotSpeed=0;
float penSpeed=0; // these are local variables for Function SteppermotorMove-Command, but for performance-reasons it will be initialized here
@@ -72,4 +71,6 @@ void setup() {
void loop() {
SCmd.readSerial();
if( 0 == digitalRead(PrgButton))
prgButtonState == 1;
}

View File

@@ -15,7 +15,7 @@ void makeComInterface(){
SCmd.addCommand("SL",setLayer);
SCmd.addCommand("QL",queryLayer);
SCmd.addCommand("QP",queryPen);
SCmd.addCommand("QB",queryButton); //preparation for "PRG" Button, actually gives fake answer,
SCmd.addCommand("QB",queryButton); //"PRG" Button,
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
}
@@ -31,6 +31,7 @@ void queryPen() {
void queryButton() {
Serial.print(String(prgButtonState) +"\r\n");
prgButtonState = 0;
sendAck();
}
@@ -110,33 +111,40 @@ void stepperMove(){
//Turn on Motors, if they are off....
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
//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...
long rotSteps = ( (long)rotStepsEBB * 16 / rotStepCorrection) + (long)rotStepError; //correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
long penSteps = ( (long)penStepsEBB * 16 / penStepCorrection) + (long)penStepError;
int rotStepsToGo = (int) (rotSteps/16); //Calc Steps to go, which are possible on our machine
int penStepsToGo = (int) (penSteps/16);
rotStepError = (long)rotSteps - ((long) rotStepsToGo * (long)16); // calc Position-Error, if there is one
penStepError = (long)penSteps - ((long) penStepsToGo * (long)16);
long temp_rotSpeed = ((long)rotStepsToGo * (long)1000 / (long)duration ); // calc Speed in Integer Math
long temp_penSpeed = ((long)penStepsToGo * (long)1000 / (long)duration ) ;
if (temp_rotSpeed <0 ) //remove sign, there is no negative Speed....
temp_rotSpeed= -temp_rotSpeed;
if (temp_penSpeed <0 ) //remove sign, there is no negative Speed....
temp_penSpeed= -temp_penSpeed;
float rotSpeed= (float) temp_rotSpeed; // type cast
float penSpeed= (float) temp_penSpeed;
rotMotor.move(rotStepsToGo); // finally, let us set the target position...
rotMotor.setSpeed(rotSpeed); // and the Speed!
penMotor.move(penStepsToGo);
penMotor.setSpeed( penSpeed );
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
if( (1 == rotStepCorrection) && (1 == penStepCorrection) ){ // if coordinatessystems are identical
//set Coordinates and Speed
rotMotor.move(rotStepsEBB);
rotMotor.setSpeed( abs( (float)rotStepsEBB * (float)1000 / (float)duration ) );
penMotor.move(penStepsEBB);
penMotor.setSpeed( abs( (float)penStepsEBB * (float)1000 / (float)duration ) );
}
else {
//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...
long rotSteps = ( (long)rotStepsEBB * 16 / rotStepCorrection) + (long)rotStepError; //correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
long penSteps = ( (long)penStepsEBB * 16 / penStepCorrection) + (long)penStepError;
int rotStepsToGo = (int) (rotSteps/16); //Calc Steps to go, which are possible on our machine
int penStepsToGo = (int) (penSteps/16);
rotStepError = (long)rotSteps - ((long) rotStepsToGo * (long)16); // calc Position-Error, if there is one
penStepError = (long)penSteps - ((long) penStepsToGo * (long)16);
long temp_rotSpeed = ((long)rotStepsToGo * (long)1000 / (long)duration ); // calc Speed in Integer Math
long temp_penSpeed = ((long)penStepsToGo * (long)1000 / (long)duration ) ;
float rotSpeed= (float) abs(temp_rotSpeed); // type cast
float penSpeed= (float) abs(temp_penSpeed);
//set Coordinates and Speed
rotMotor.move(rotStepsToGo); // finally, let us set the target position...
rotMotor.setSpeed(rotSpeed); // and the Speed!
penMotor.move(penStepsToGo);
penMotor.setSpeed( penSpeed );
}
//Start Move
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
rotMotor.runSpeedToPosition();
}
}
//################### Move-Code End ############################################################
sendAck(); //Mission completed
}
sendAck(); //report Mission completed
}
}
else
sendError();
@@ -229,41 +237,7 @@ void enableMotors(){
digitalWrite(enablePenMotor, HIGH) ;
sendAck();
break;
case 1: rotStepMode=16;
penStepMode=16;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 2: rotStepMode=8;
penStepMode=8;
rotStepCorrection = rotStepMode/rotMicrostep;
penStepCorrection = penStepMode/penMicrostep;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 3: rotStepMode=4;
penStepMode=4;
rotStepCorrection = rotStepMode/rotMicrostep;
penStepCorrection = penStepMode/penMicrostep;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 4: rotStepMode=2;
penStepMode=2;
rotStepCorrection = rotStepMode/rotMicrostep;
penStepCorrection = penStepMode/penMicrostep;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 5: rotStepMode=1;
penStepMode=1;
rotStepCorrection = rotStepMode/rotMicrostep;
penStepCorrection = penStepMode/penMicrostep;
digitalWrite(enableRotMotor, LOW) ;
case 1: digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
@@ -278,43 +252,16 @@ void enableMotors(){
digitalWrite(enablePenMotor, HIGH) ;
sendAck();
break;
case 1: rotStepMode=16;
penStepMode=16;
digitalWrite(enableRotMotor, LOW) ;
case 1: digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 2: rotStepMode=8;
penStepMode=8;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 3: rotStepMode=4;
penStepMode=4;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 4: rotStepMode=2;
penStepMode=2;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
case 5: rotStepMode=1;
penStepMode=1;
digitalWrite(enableRotMotor, LOW) ;
digitalWrite(enablePenMotor, LOW) ;
sendAck();
break;
default:
sendError();
}
}
}
void stepperModeConfigure(){
int cmd;

View File

@@ -3,7 +3,7 @@ Eggduino
Arduino Firmware for Eggbot / Spherebot with Inkscape-Integration
Version 1.3
Version 1.4s
tested with Inkscape Portable 0.91, Eggbot Extension and patched eggbot.py
Regards: Eggduino-Firmware by Joachim Cerny, 2015
@@ -34,7 +34,7 @@ http://wiki.evilmadscientist.com/Installing_software
- Go to your Inkscape-Installationfolder and navigate to subfolder .\App\Inkscape\share\extensions
- open File "eggbot.py" in texteditor and search for line:
"Try any devices which seem to have EBB boards attached"
- uncomment that block like this:
- comment that block with "#" like this:
# Try any devices which seem to have EBB boards attached
# for strComPort in eggbot_scan.findEiBotBoards():
# serialPort = self.testSerialPort( strComPort )

View File

@@ -1,3 +1,9 @@
29.03.2015 v1.4
added prototype for PRG-Button support. somebody has to test it. Connect pushbutton between Pin2 und GND.
disabled ccordinate transform for 16-microstepping, because Inkscape sends in 16-microstepping, as well.
removed commands for changing rotStepmodes
fixed some minor bugs
26.03.2015 v1.3
updated Accelstepper-Lib
set Microstepping Factor 16 by default.