Added max length parameters, reporting encoder status, rewritten encoder read
parent
63f0072858
commit
5ef61ccd13
|
@ -21,7 +21,8 @@ const char COMM_REPORT_CMD_BUSY[4] = {'R', '0', '4', '\0'};
|
|||
const char COMM_REPORT_CMD_STATUS[4] = {'R', '0', '5', '\0'};
|
||||
const char COMM_REPORT_CALIB_STATUS[4] = {'R', '0', '6', '\0'};
|
||||
|
||||
const char COMM_REPORT_ENCODER[4] = { 'R', '2', '1', '\0' };
|
||||
const char COMM_REPORT_ENCODER_SCALED[4] = { 'R', '2', '1', '\0' };
|
||||
const char COMM_REPORT_ENCODER_RAW[4] = { 'R', '2', '2', '\0' };
|
||||
|
||||
const char COMM_REPORT_EMERGENCY_STOP[4] = { 'R', '8', '7', '\0' };
|
||||
const char COMM_REPORT_NO_CONFIG[4] = {'R', '8', '8', '\0'};
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
*/
|
||||
|
||||
#ifndef DEBUG_H_
|
||||
#define debugMessages true
|
||||
#define debugMessages false
|
||||
#define debugInterrupt false
|
||||
#endif /* DEBUG_H_ */
|
||||
|
|
|
@ -14,22 +14,24 @@ StepperControl *StepperControl::getInstance()
|
|||
|
||||
void StepperControl::reportEncoders()
|
||||
{
|
||||
Serial.print(COMM_REPORT_ENCODER);
|
||||
Serial.print(" XS");
|
||||
Serial.print(COMM_REPORT_ENCODER_SCALED);
|
||||
Serial.print(" X");
|
||||
Serial.print(encoderX.currentPosition());
|
||||
Serial.print(" XR");
|
||||
Serial.print(encoderX.currentPosition());
|
||||
|
||||
Serial.print(" YS");
|
||||
Serial.print(" Y");
|
||||
Serial.print(encoderY.currentPosition());
|
||||
Serial.print(" YR");
|
||||
Serial.print(encoderY.currentPosition());
|
||||
|
||||
Serial.print(" ZS");
|
||||
Serial.print(encoderZ.currentPosition());
|
||||
Serial.print(" ZR");
|
||||
Serial.print(" Z");
|
||||
Serial.print(encoderZ.currentPosition());
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
|
||||
Serial.print(COMM_REPORT_ENCODER_RAW);
|
||||
Serial.print(" X");
|
||||
Serial.print(encoderX.currentPositionRaw());
|
||||
Serial.print(" Y");
|
||||
Serial.print(encoderY.currentPositionRaw());
|
||||
Serial.print(" Z");
|
||||
Serial.print(encoderZ.currentPositionRaw());
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
|
||||
}
|
||||
|
||||
void StepperControl::reportStatus(StepperControlAxis *axis, int axisStatus)
|
||||
|
@ -307,16 +309,15 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
axisActive[1] = true;
|
||||
axisActive[2] = true;
|
||||
|
||||
/**/
|
||||
if (xHome || yHome || zHome)
|
||||
{
|
||||
if (!xHome) { axisX.deactivateAxis(); }
|
||||
if (!yHome) { axisY.deactivateAxis(); }
|
||||
if (!zHome) { axisZ.deactivateAxis(); }
|
||||
if (!xHome) { axisX.deactivateAxis(); }
|
||||
if (!yHome) { axisY.deactivateAxis(); }
|
||||
if (!zHome) { axisZ.deactivateAxis(); }
|
||||
|
||||
axisActive[0] = xHome;
|
||||
axisActive[1] = yHome;
|
||||
axisActive[2] = zHome;
|
||||
axisActive[0] = xHome;
|
||||
axisActive[1] = yHome;
|
||||
axisActive[2] = zHome;
|
||||
}
|
||||
|
||||
axisX.checkMovement();
|
||||
|
@ -363,7 +364,6 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
if (debugInterrupt)
|
||||
{
|
||||
delayMicroseconds(100);
|
||||
|
||||
handleMovementInterrupt();
|
||||
}
|
||||
else
|
||||
|
@ -505,11 +505,12 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
// Periodically send message still active
|
||||
currentMillis++;
|
||||
|
||||
if (currentMillis % 750 == 0)
|
||||
if (currentMillis % 300 == 0)
|
||||
{
|
||||
Serial.print(COMM_REPORT_CMD_BUSY);
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
reportPosition();
|
||||
reportEncoders();
|
||||
|
||||
if (debugMessages /*&& debugInterrupt*/)
|
||||
{
|
||||
|
@ -553,6 +554,7 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
|||
storeEndStops();
|
||||
reportEndStops();
|
||||
reportPosition();
|
||||
reportEncoders();
|
||||
|
||||
// Report axis idle
|
||||
|
||||
|
@ -700,7 +702,7 @@ int StepperControl::calibrateAxis(int axis)
|
|||
while (!movementDone && error == 0)
|
||||
{
|
||||
|
||||
//checkAxisVsEncoder(&axisX, &encoderX, &motorConsMissedSteps[0], &motorLastPosition[0], &motorConsMissedStepsDecay[0], &motorConsEncoderEnabled[0]);
|
||||
checkAxisVsEncoder(calibAxis, calibEncoder, &motorConsMissedSteps[axis], &motorLastPosition[axis], &motorConsEncoderLastPosition[axis], &motorConsEncoderUseForPos[axis], &motorConsMissedStepsDecay[axis], &motorConsEncoderEnabled[axis]);
|
||||
|
||||
// Check if there is an emergency stop command
|
||||
if (Serial.available() > 0)
|
||||
|
@ -719,6 +721,7 @@ int StepperControl::calibrateAxis(int axis)
|
|||
{
|
||||
|
||||
calibAxis->setStepAxis();
|
||||
|
||||
|
||||
delayMicroseconds(100000 / speedMin[axis] / 2);
|
||||
|
||||
|
@ -823,6 +826,8 @@ int StepperControl::calibrateAxis(int axis)
|
|||
while (!movementDone && error == 0)
|
||||
{
|
||||
|
||||
checkAxisVsEncoder(calibAxis, calibEncoder, &motorConsMissedSteps[axis], &motorLastPosition[axis], &motorConsEncoderLastPosition[axis], &motorConsEncoderUseForPos[axis], &motorConsMissedStepsDecay[axis], &motorConsEncoderEnabled[axis]);
|
||||
|
||||
// Check if there is an emergency stop command
|
||||
if (Serial.available() > 0)
|
||||
{
|
||||
|
@ -935,15 +940,11 @@ int debugPrintCount = 0;
|
|||
// Check encoder to verify the motor is at the right position
|
||||
void StepperControl::checkAxisVsEncoder(StepperControlAxis *axis, StepperControlEncoder *encoder, float *missedSteps, long *lastPosition, long *encoderLastPosition, int *encoderUseForPos, float *encoderStepDecay, bool *encoderEnabled)
|
||||
{
|
||||
|
||||
// If a step is done
|
||||
//if (*encoderEnabled && axis->isStepDone()
|
||||
if (*encoderEnabled)
|
||||
{
|
||||
|
||||
bool stepMissed = false;
|
||||
|
||||
if (debugInterrupt && debugMessages)
|
||||
if (debugMessages)
|
||||
{
|
||||
//debugPrintCount++;
|
||||
//if (debugPrintCount % 50 == 0)
|
||||
|
|
|
@ -74,9 +74,7 @@ void StepperControlEncoder::setPosition(long newPosition)
|
|||
|
||||
long StepperControlEncoder::currentPosition()
|
||||
{
|
||||
|
||||
// Apply scaling to the output of the encoder, except when scaling is zero or lower
|
||||
//return position;
|
||||
if (scalingFactor == 100 || scalingFactor <= 0)
|
||||
{
|
||||
return position * encoderInvert;
|
||||
|
|
|
@ -160,7 +160,7 @@ void setup()
|
|||
StepperControl::getInstance()->loadSettings();
|
||||
|
||||
// Dump all values to the serial interface
|
||||
ParameterList::getInstance()->readAllValues();
|
||||
//ParameterList::getInstance()->readAllValues();
|
||||
|
||||
// Get the settings for the pin guard
|
||||
PinGuard::getInstance()->loadConfig();
|
||||
|
@ -178,20 +178,23 @@ void setup()
|
|||
|
||||
if (ParameterList::getInstance()->getValue(MOVEMENT_HOME_AT_BOOT_X) == 1)
|
||||
{
|
||||
Serial.print("R99 HOME X ON STARTUP\r\n");
|
||||
StepperControl::getInstance()->moveToCoords(0, 0, 0, 0, 0, 0, true, false, false);
|
||||
}
|
||||
|
||||
if (ParameterList::getInstance()->getValue(MOVEMENT_HOME_AT_BOOT_Y) == 1)
|
||||
{
|
||||
Serial.print("R99 HOME Y ON STARTUP\r\n");
|
||||
StepperControl::getInstance()->moveToCoords(0, 0, 0, 0, 0, 0, false, true, false);
|
||||
}
|
||||
|
||||
if (ParameterList::getInstance()->getValue(MOVEMENT_HOME_AT_BOOT_Z) == 1)
|
||||
{
|
||||
Serial.print("R99 HOME Z ON STARTUP\r\n");
|
||||
StepperControl::getInstance()->moveToCoords(0, 0, 0, 0, 0, 0, false, false, true);
|
||||
}
|
||||
|
||||
Serial.print("R99 ARDUINO STARTUP \r\n");
|
||||
Serial.print("R99 ARDUINO STARTUP COMPLETE\r\n");
|
||||
}
|
||||
|
||||
// The loop function is called in an endless loop
|
||||
|
@ -340,6 +343,8 @@ void loop()
|
|||
CurrentState::getInstance()->storeEndStops();
|
||||
CurrentState::getInstance()->printEndStops();
|
||||
|
||||
StepperControl::getInstance()->reportEncoders();
|
||||
|
||||
if (debugMessages)
|
||||
{
|
||||
Serial.print(COMM_REPORT_COMMENT);
|
||||
|
|
|
@ -173,7 +173,7 @@
|
|||
</ImportGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties vm.programmer_name="avrisp" arduino.upload.port="COM3" />
|
||||
<UserProperties vm.programmer_name="avrisp" arduino.upload.port="COM5" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
Loading…
Reference in New Issue