Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support zAxisAuto settings from GroundControl (B12 Y) #328

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions cnc_ctrl_v1/CNC_Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,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;

Expand Down Expand Up @@ -411,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 = "";
Expand Down Expand Up @@ -954,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;
Expand Down Expand Up @@ -1014,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();
Expand All @@ -1024,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
*/
Expand Down Expand Up @@ -1167,6 +1169,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){
Expand Down Expand Up @@ -1217,13 +1222,8 @@ 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 = true;
*/
boolean useServo = !zAxisAuto;
boolean activeHigh = true;
int delayAfterChange = 1000; // milliseconds
int servoIdle = 90; // degrees
Expand All @@ -1234,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
Expand All @@ -1246,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
Expand All @@ -1268,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);
Expand Down