From 9dd1ba270219b09f16207b6c99291bd4bc965bf3 Mon Sep 17 00:00:00 2001 From: Josh Martin Date: Fri, 17 Nov 2017 19:12:36 -0800 Subject: [PATCH 1/2] Support zAxisAuto settings from GroundControl (B12 Y) --- cnc_ctrl_v1/CNC_Functions.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cnc_ctrl_v1/CNC_Functions.h b/cnc_ctrl_v1/CNC_Functions.h index 10a1f3e4..79f6f257 100644 --- a/cnc_ctrl_v1/CNC_Functions.h +++ b/cnc_ctrl_v1/CNC_Functions.h @@ -31,6 +31,7 @@ libraries*/ Servo myservo; // create servo object to control a servo bool zAxisAttached = false; +bool zAxisAuto = false; #define FORWARD 1 #define BACKWARD -1 @@ -1167,6 +1168,9 @@ void updateMotorSettings(const String& readString){ float KpV = extractGcodeValue(readString, 'V', -1); float KiV = extractGcodeValue(readString, 'W', -1); float KdV = extractGcodeValue(readString, 'X', -1); + if (extractGcodeValue(readString, 'Y', -1) != -1) { + zAxisAuto = extractGcodeValue(readString, 'Y', -1); + } //Write the PID values to the axis if new ones have been received if (KpPos != -1){ @@ -1223,7 +1227,7 @@ void setSpindlePower(boolean powerState) { // but hard-code these for now int controlPin = AUX1; - boolean useServo = true; + boolean useServo = !zAxisAuto; boolean activeHigh = true; int delayAfterChange = 1000; // milliseconds int servoIdle = 90; // degrees From 9bb100890865262cbd5da92b47360e7b606e321f Mon Sep 17 00:00:00 2001 From: Josh Martin Date: Fri, 17 Nov 2017 23:39:05 -0800 Subject: [PATCH 2/2] Update mappings for AUX1 clean up Pin defines --- cnc_ctrl_v1/CNC_Functions.h | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/cnc_ctrl_v1/CNC_Functions.h b/cnc_ctrl_v1/CNC_Functions.h index 79f6f257..6d9efa11 100644 --- a/cnc_ctrl_v1/CNC_Functions.h +++ b/cnc_ctrl_v1/CNC_Functions.h @@ -76,7 +76,8 @@ int ENC; #define AUX2 16 #define AUX3 15 #define AUX4 14 -#define Probe AUX4 // use this input for zeroing zAxis with G38.2 gcode +#define SpindlePowerControlPin AUX1 // output for controlling spindle power +#define ProbePin AUX4 // use this input for zeroing zAxis with G38.2 gcode int pcbVersion = -1; @@ -412,7 +413,7 @@ void maslowDelay(unsigned long waitTimeMs) { bool checkForProbeTouch(const int& probePin) { /* - Check to see if AUX4 has gone LOW + Check to see if ProbePin has gone LOW */ if (digitalRead(probePin) == LOW) { readyCommandString = ""; @@ -955,8 +956,8 @@ void G38(const String& readString) { //set Probe to input with pullup - pinMode(Probe, INPUT_PULLUP); - digitalWrite(Probe, HIGH); + pinMode(ProbePin, INPUT_PULLUP); + digitalWrite(ProbePin, HIGH); if (zgoto != currentZPos / _inchesToMMConversion) { // now move z to the Z destination; @@ -1015,7 +1016,7 @@ void G38(const String& readString) { } //check for Probe touchdown - if (checkForProbeTouch(Probe)) { + if (checkForProbeTouch(ProbePin)) { zAxis.set(0); zAxis.endMove(0); zAxis.attach(); @@ -1025,7 +1026,7 @@ void G38(const String& readString) { } /* - If wen get here, the probe failed to touch down + If we get here, the probe failed to touch down - print error - STOP execution */ @@ -1221,12 +1222,7 @@ bool isSafeCommand(const String& readString){ void setSpindlePower(boolean powerState) { /* * Turn spindle on or off depending on powerState - */ - - // Need to add settings to choose the method and pin number here - // but hard-code these for now - - int controlPin = AUX1; + */ boolean useServo = !zAxisAuto; boolean activeHigh = true; int delayAfterChange = 1000; // milliseconds @@ -1238,7 +1234,7 @@ void setSpindlePower(boolean powerState) { // Now for the main code #if defined (verboseDebug) && verboseDebug > 1 Serial.print(F("Spindle control uses pin ")); - Serial.print(controlPin); + Serial.print(SpindlePowerControlPin); #endif if (useServo) { // use a servo to control a standard wall switch #if defined (verboseDebug) && verboseDebug > 1 @@ -1250,7 +1246,7 @@ void setSpindlePower(boolean powerState) { Serial.print(servoOff); Serial.println(F(")")); #endif - myservo.attach(controlPin); // start servo control + myservo.attach(SpindlePowerControlPin); // start servo control myservo.write(servoIdle); // move servo to idle position maslowDelay(servoDelay); // wait for move to complete if (powerState) { // turn on spindle @@ -1272,16 +1268,16 @@ void setSpindlePower(boolean powerState) { if (activeHigh) Serial.println(F("high")); else Serial.println(F("low")); #endif - pinMode(controlPin, OUTPUT); + pinMode(SpindlePowerControlPin, OUTPUT); if (powerState) { // turn on spindle Serial.println(F("Turning Spindle On")); - if (activeHigh) digitalWrite(controlPin, HIGH); - else digitalWrite(controlPin, LOW); + if (activeHigh) digitalWrite(SpindlePowerControlPin, HIGH); + else digitalWrite(SpindlePowerControlPin, LOW); } else { // turn off spindle Serial.println(F("Turning Spindle Off")); - if (activeHigh) digitalWrite(controlPin, LOW); - else digitalWrite(controlPin, HIGH); + if (activeHigh) digitalWrite(SpindlePowerControlPin, LOW); + else digitalWrite(SpindlePowerControlPin, HIGH); } } maslowDelay(delayAfterChange);