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,9 +58,15 @@ float* parseGCode(String gcode) {
bytecode[Z] = floatValue; bytecode[Z] = floatValue;
} }
} }
if (strcmp(command, "G00") == 0) {
bytecode[0] = G00;
return bytecode; return bytecode;
} }
if (strcmp(command, "G01") == 0) {
bytecode[0] = G01;
return bytecode;
}
}
if (strcmp(command, "M99") == 0) { if (strcmp(command, "M99") == 0) {
bytecode[0] = M99; bytecode[0] = M99;

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,8 +11,14 @@
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 || command[0] == G00) {
if (command[0] == G01) { if (command[0] == G01) {
needAdjust = true;
if (command[X] != -1 && command[Y] != -1) { if (command[X] != -1 && command[Y] != -1) {
float distX = servoStepper.getDistMm(command[X]); float distX = servoStepper.getDistMm(command[X]);
float distY = eggStepper.getDistMm(command[Y]); float distY = eggStepper.getDistMm(command[Y]);
@@ -26,6 +34,9 @@ void execCommand(float *command) {
} }
} }
} }
} else {
needAdjust = false;
}
if (command[X] != -1) { if (command[X] != -1) {
servoStepper.moveTo(command[X]); servoStepper.moveTo(command[X]);
@@ -57,25 +68,8 @@ void execCommand(float *command) {
} }
} }
void setup() { void adjustRPM() {
Serial.begin(115200); if (needAdjust) {
eggStepperTimer.setStepper(&eggStepper);
servoStepperTimer.setStepper(&servoStepper);
pen.init();
servoStepper.setPos(70);
WiFi.mode(WIFI_OFF);
}
void loop() {
while (Serial.available() > 0) {
char inChar = Serial.read();
inString += inChar;
if (inChar == '\n') {
inString.trim();
execCommand(parseGCode(inString));
while (!eggStepper.finished() || !servoStepper.finished()) {
delay(50);
cli(); cli();
int stepsX = servoStepper.getRemainingSteps(); int stepsX = servoStepper.getRemainingSteps();
int stepsY = eggStepper.getRemainingSteps(); int stepsY = eggStepper.getRemainingSteps();
@@ -91,6 +85,29 @@ void loop() {
} }
sei(); sei();
} }
}
void setup() {
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
eggStepperTimer.setStepper(&eggStepper);
servoStepperTimer.setStepper(&servoStepper);
pen.init();
servoStepper.setPos(70);
adjustTicker.attach_ms(50, adjustRPM);
}
void loop() {
while (Serial.available() > 0) {
char inChar = Serial.read();
inString += inChar;
if (inChar == '\n') {
inString.trim();
execCommand(parseGCode(inString));
while (!eggStepper.finished() || !servoStepper.finished()) {
delay(50);
}
eggStepperTimer.setRPM(RPM); eggStepperTimer.setRPM(RPM);
servoStepperTimer.setRPM(RPM); servoStepperTimer.setRPM(RPM);
Serial.println("OK"); Serial.println("OK");