Fix emergency stop
parent
0de48bf66a
commit
db98b6daab
|
@ -14,6 +14,12 @@ PinControl *PinControl::getInstance()
|
|||
|
||||
PinControl::PinControl()
|
||||
{
|
||||
for (int pinNr = 1; pinNr <= 52; pinNr++)
|
||||
{
|
||||
pinWritten[0][pinNr] = false;
|
||||
pinWritten[1][pinNr] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int PinControl::setMode(int pinNr, int mode)
|
||||
|
@ -49,11 +55,23 @@ void PinControl::resetPinsUsed()
|
|||
{
|
||||
if (pinWritten[0][pinNr])
|
||||
{
|
||||
Serial.print("R99");
|
||||
Serial.print(" resetting digital pin");
|
||||
Serial.print(pinNr);
|
||||
Serial.print("\r\n");
|
||||
|
||||
digitalWrite(pinNr, false);
|
||||
pinWritten[0][pinNr] = false;
|
||||
}
|
||||
if (pinWritten[1][pinNr])
|
||||
{
|
||||
Serial.print("R99");
|
||||
Serial.print(" resetting analog pin");
|
||||
Serial.print(pinNr);
|
||||
Serial.print("\r\n");
|
||||
|
||||
analogWrite(pinNr, 0);
|
||||
pinWritten[1][pinNr] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ private:
|
|||
PinControl(PinControl const &);
|
||||
void operator=(PinControl const &);
|
||||
|
||||
bool pinWritten[1][56];
|
||||
bool pinWritten[2][56];
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -528,7 +528,12 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
incomingByte = Serial.read();
|
||||
if (incomingByte == 69 || incomingByte == 101)
|
||||
{
|
||||
Serial.print("R99 emergency stop\r\n");
|
||||
serialBuffer += "R99 emergency stop\r\n";
|
||||
|
||||
Serial.print(COMM_REPORT_EMERGENCY_STOP);
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
|
||||
//Serial.print("R99 emergency stop\r\n");
|
||||
|
||||
emergencyStop = true;
|
||||
|
||||
|
@ -546,7 +551,8 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
|
||||
if (error == 1)
|
||||
{
|
||||
Serial.print("R99 error\r\n");
|
||||
serialBuffer += "R99 error\r\n";
|
||||
//Serial.print("R99 error\r\n");
|
||||
|
||||
axisActive[0] = false;
|
||||
axisActive[1] = false;
|
||||
|
@ -554,48 +560,7 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
}
|
||||
|
||||
// Send the serial buffer one character per cycle to keep motor timing more accuracte
|
||||
if (serialBuffer.length() > 0)
|
||||
{
|
||||
|
||||
//Serial.print("[buf");
|
||||
//Serial.print(serialBufferLength);
|
||||
//Serial.print("]");
|
||||
|
||||
//Serial.print("[send");
|
||||
//Serial.print(serialBufferSending);
|
||||
//Serial.print("]");
|
||||
|
||||
if (serialBufferSending < serialBuffer.length())
|
||||
{
|
||||
//Serial.print("-");
|
||||
switch(serialBuffer.charAt(serialBufferSending))
|
||||
{
|
||||
case 13:
|
||||
Serial.print("\r\n");
|
||||
break;
|
||||
case 10:
|
||||
break;
|
||||
default:
|
||||
Serial.print(serialBuffer.charAt(serialBufferSending));
|
||||
break;
|
||||
}
|
||||
|
||||
//Serial.print("<");
|
||||
//Serial.print(serialBufferSending);
|
||||
//Serial.print(">");
|
||||
|
||||
serialBufferSending++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.print("reset");
|
||||
// Reset length of buffer when done
|
||||
serialBuffer = "";
|
||||
serialBufferSending = 0;
|
||||
|
||||
//Serial.println("YY");
|
||||
}
|
||||
}
|
||||
serialBufferSendNext();
|
||||
|
||||
// Periodically send message still active
|
||||
currentMillis++;
|
||||
|
@ -640,6 +605,7 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
}
|
||||
}
|
||||
|
||||
serialBufferEmpty();
|
||||
Serial.print("R99 stopped\r\n");
|
||||
|
||||
// Stop motors
|
||||
|
@ -690,6 +656,46 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
return error;
|
||||
}
|
||||
|
||||
void StepperControl::serialBufferEmpty()
|
||||
{
|
||||
while (serialBuffer.length() > 0)
|
||||
{
|
||||
serialBufferSendNext();
|
||||
}
|
||||
}
|
||||
|
||||
void StepperControl::serialBufferSendNext()
|
||||
{
|
||||
// Send the next char in the serialBuffer
|
||||
if (serialBuffer.length() > 0)
|
||||
{
|
||||
|
||||
if (serialBufferSending < serialBuffer.length())
|
||||
{
|
||||
//Serial.print("-");
|
||||
switch (serialBuffer.charAt(serialBufferSending))
|
||||
{
|
||||
case 13:
|
||||
Serial.print("\r\n");
|
||||
break;
|
||||
case 10:
|
||||
break;
|
||||
default:
|
||||
Serial.print(serialBuffer.charAt(serialBufferSending));
|
||||
break;
|
||||
}
|
||||
|
||||
serialBufferSending++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reset length of buffer when done
|
||||
serialBuffer = "";
|
||||
serialBufferSending = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calibration
|
||||
//
|
||||
|
|
|
@ -78,6 +78,9 @@ private:
|
|||
int serialMessageNr = 0;
|
||||
int serialMessageDelay = 0;
|
||||
|
||||
void serialBufferSendNext();
|
||||
void serialBufferEmpty();
|
||||
|
||||
void checkAxisVsEncoder(StepperControlAxis *axis, StepperControlEncoder *encoder, float *missedSteps, long *lastPosition, long *encoderLastPosition, int *encoderUseForPos, float *encoderStepDecay, bool *encoderEnabled);
|
||||
void checkAxisSubStatus(StepperControlAxis *axis, int *axisSubStatus);
|
||||
|
||||
|
|
Loading…
Reference in New Issue