From f4b736739924018127a2f0f000ec32a5ac46499d Mon Sep 17 00:00:00 2001 From: cocktailyogi Date: Sun, 29 Mar 2015 11:38:26 +0200 Subject: [PATCH] Version 1.4 --- EggDuino.ino | 15 +++--- Functions.ino | 125 +++++++++++++-------------------------------- README.md | 4 +- VersionHistory.txt | 6 +++ 4 files changed, 52 insertions(+), 98 deletions(-) diff --git a/EggDuino.ino b/EggDuino.ino index d02e81c..08b5630 100644 --- a/EggDuino.ino +++ b/EggDuino.ino @@ -24,7 +24,7 @@ Thanks to my wife and my daughter for their patience. :-) #include #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; } diff --git a/Functions.ino b/Functions.ino index 703fc77..d76c669 100644 --- a/Functions.ino +++ b/Functions.ino @@ -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; diff --git a/README.md b/README.md index 2d2a3bb..d63ac11 100644 --- a/README.md +++ b/README.md @@ -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 ) diff --git a/VersionHistory.txt b/VersionHistory.txt index 24b5893..7a4368a 100644 --- a/VersionHistory.txt +++ b/VersionHistory.txt @@ -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.