support for G00 command

Signed-off-by: Stepan Usatyuk <usaatyuk@ustk.me>
This commit is contained in:
2019-05-10 16:13:34 +03:00
parent 33e0c82364
commit c4d76632a0
3 changed files with 55 additions and 33 deletions

View File

@@ -5,6 +5,7 @@
enum command { enum command {
unk, unk,
G00,
G01, G01,
M99, M99,
}; };

View File

@@ -23,8 +23,6 @@ float* parseGCode(String gcode) {
strncpy(args, &commandString[4], 45); strncpy(args, &commandString[4], 45);
if (strcmp(command, "G01") == 0 || strcmp(command, "G00") == 0) { if (strcmp(command, "G01") == 0 || strcmp(command, "G00") == 0) {
bytecode[0] = G01;
char split_args[3][40]; char split_args[3][40];
memset(split_args, 0, sizeof(split_args)); memset(split_args, 0, sizeof(split_args));
char* arg; char* arg;
@@ -60,8 +58,14 @@ float* parseGCode(String gcode) {
bytecode[Z] = floatValue; bytecode[Z] = floatValue;
} }
} }
if (strcmp(command, "G00") == 0) {
return bytecode; bytecode[0] = G00;
return bytecode;
}
if (strcmp(command, "G01") == 0) {
bytecode[0] = G01;
return bytecode;
}
} }
if (strcmp(command, "M99") == 0) { if (strcmp(command, "M99") == 0) {

View File

@@ -1,5 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <Ticker.h>
#include "EggConstants.h" #include "EggConstants.h"
#include "GCodeParser.h" #include "GCodeParser.h"
#include "Globals.h" #include "Globals.h"
@@ -9,22 +11,31 @@
int RPM = DEF_RPM; int RPM = DEF_RPM;
bool needAdjust = false;
Ticker adjustTicker;
void execCommand(float *command) { void execCommand(float *command) {
if (command[0] == G01) { if (command[0] == G01 || command[0] == G00) {
if (command[X] != -1 && command[Y] != -1) { if (command[0] == G01) {
float distX = servoStepper.getDistMm(command[X]); needAdjust = true;
float distY = eggStepper.getDistMm(command[Y]); if (command[X] != -1 && command[Y] != -1) {
int stepsX = servoStepper.mmToSteps(distX); float distX = servoStepper.getDistMm(command[X]);
int stepsY = eggStepper.mmToSteps(distY); float distY = eggStepper.getDistMm(command[Y]);
if (stepsX != 0 && stepsY != 0) { int stepsX = servoStepper.mmToSteps(distX);
if (stepsX > stepsY) { int stepsY = eggStepper.mmToSteps(distY);
float rpm = (float)RPM * (float)stepsY / (float)stepsX; if (stepsX != 0 && stepsY != 0) {
eggStepperTimer.setRPM(rpm); if (stepsX > stepsY) {
} else if (stepsY > stepsX) { float rpm = (float)RPM * (float)stepsY / (float)stepsX;
float rpm = (float)RPM * (float)stepsX / (float)stepsY; eggStepperTimer.setRPM(rpm);
servoStepperTimer.setRPM(rpm); } else if (stepsY > stepsX) {
float rpm = (float)RPM * (float)stepsX / (float)stepsY;
servoStepperTimer.setRPM(rpm);
}
} }
} }
} else {
needAdjust = false;
} }
if (command[X] != -1) { if (command[X] != -1) {
@@ -57,13 +68,33 @@ void execCommand(float *command) {
} }
} }
void adjustRPM() {
if (needAdjust) {
cli();
int stepsX = servoStepper.getRemainingSteps();
int stepsY = eggStepper.getRemainingSteps();
if (stepsX > stepsY) {
float rpm = (float)RPM * (float)stepsY / (float)stepsX;
eggStepperTimer.setRPM(rpm);
} else if (stepsY > stepsX) {
float rpm = (float)RPM * (float)stepsX / (float)stepsY;
servoStepperTimer.setRPM(rpm);
} else {
eggStepperTimer.setRPM(RPM);
servoStepperTimer.setRPM(RPM);
}
sei();
}
}
void setup() { void setup() {
WiFi.mode(WIFI_OFF);
Serial.begin(115200); Serial.begin(115200);
eggStepperTimer.setStepper(&eggStepper); eggStepperTimer.setStepper(&eggStepper);
servoStepperTimer.setStepper(&servoStepper); servoStepperTimer.setStepper(&servoStepper);
pen.init(); pen.init();
servoStepper.setPos(70); servoStepper.setPos(70);
WiFi.mode(WIFI_OFF); adjustTicker.attach_ms(50, adjustRPM);
} }
void loop() { void loop() {
@@ -76,20 +107,6 @@ void loop() {
execCommand(parseGCode(inString)); execCommand(parseGCode(inString));
while (!eggStepper.finished() || !servoStepper.finished()) { while (!eggStepper.finished() || !servoStepper.finished()) {
delay(50); delay(50);
cli();
int stepsX = servoStepper.getRemainingSteps();
int stepsY = eggStepper.getRemainingSteps();
if (stepsX > stepsY) {
float rpm = (float)RPM * (float)stepsY / (float)stepsX;
eggStepperTimer.setRPM(rpm);
} else if (stepsY > stepsX) {
float rpm = (float)RPM * (float)stepsX / (float)stepsY;
servoStepperTimer.setRPM(rpm);
} else {
eggStepperTimer.setRPM(RPM);
servoStepperTimer.setRPM(RPM);
}
sei();
} }
eggStepperTimer.setRPM(RPM); eggStepperTimer.setRPM(RPM);
servoStepperTimer.setRPM(RPM); servoStepperTimer.setRPM(RPM);
@@ -97,4 +114,4 @@ void loop() {
inString = ""; inString = "";
} }
} }
} }