adding debug message definition

pull/70/head
Tim Evers 2017-04-20 12:34:39 +02:00
parent 500259b6ea
commit 22a8b9b11b
5 changed files with 111 additions and 89 deletions

11
src/Debug.h 100644
View File

@ -0,0 +1,11 @@
/*
* Debug.h
*
* Created on: 2017/04/20
* Author: Tim Evers
*/
#ifndef DEBUG_H_
#define debugMessages false
#define debugInterrupt false
#endif /* DEBUG_H_ */

View File

@ -1,4 +1,5 @@
#include "StepperControl.h"
#include "Debug.h"
static StepperControl *instance;
@ -17,7 +18,6 @@ void StepperControl::reportStatus(StepperControlAxis *axis, int axisStatus)
Serial.print(" ");
Serial.print(axis->label);
Serial.print(axisStatus);
//Serial.print("\r\n");
CurrentState::getInstance()->printQAndNewLine();
}
@ -27,7 +27,6 @@ void StepperControl::reportCalib(StepperControlAxis *axis, int calibStatus)
Serial.print(" ");
Serial.print(axis->label);
Serial.print(calibStatus);
//Serial.print("\r\n");
CurrentState::getInstance()->printQAndNewLine();
}
@ -298,20 +297,26 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
checkAxisSubStatus(&axisY, &axisSubStep[1]);
checkAxisSubStatus(&axisZ, &axisSubStep[2]);
delay(1);
//delayMicroseconds(100);
if (debugInterrupt)
{
delayMicroseconds(100);
//encoderX.currentPosition();
//encoderY.currentPosition();
//encoderZ.currentPosition();
encoderX.currentPosition();
encoderY.currentPosition();
encoderZ.currentPosition();
//axisX.checkTiming();
//axisY.checkTiming();
//axisZ.checkTiming();
axisX.checkTiming();
axisY.checkTiming();
axisZ.checkTiming();
//checkAxisVsEncoder(&axisX, &encoderX, &motorConsMissedSteps[0], &motorLastPosition[0], &motorConsMissedStepsDecay[0], &motorConsEncoderEnabled[0]);
//checkAxisVsEncoder(&axisY, &encoderY, &motorConsMissedSteps[1], &motorLastPosition[1], &motorConsMissedStepsDecay[1], &motorConsEncoderEnabled[1]);
//checkAxisVsEncoder(&axisZ, &encoderZ, &motorConsMissedSteps[2], &motorLastPosition[2], &motorConsMissedStepsDecay[2], &motorConsEncoderEnabled[2]);
checkAxisVsEncoder(&axisX, &encoderX, &motorConsMissedSteps[0], &motorLastPosition[0], &motorConsMissedStepsDecay[0], &motorConsEncoderEnabled[0]);
checkAxisVsEncoder(&axisY, &encoderY, &motorConsMissedSteps[1], &motorLastPosition[1], &motorConsMissedStepsDecay[1], &motorConsEncoderEnabled[1]);
checkAxisVsEncoder(&axisZ, &encoderZ, &motorConsMissedSteps[2], &motorLastPosition[2], &motorConsMissedStepsDecay[2], &motorConsEncoderEnabled[2]);
}
else
{
delay(1);
}
if (motorConsMissedSteps[0] > motorConsMissedStepsMax[0])
{
@ -447,7 +452,9 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
//Serial.print("\r\n");
CurrentState::getInstance()->printQAndNewLine();
reportPosition();
/*
if (debugMessages && debugInterrupt)
{
Serial.print("R99");
Serial.print(" encoder pos ");
Serial.print(encoderX.currentPosition());
@ -463,16 +470,7 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
Serial.print(" axis pos ");
Serial.print(axisX.currentPosition());
Serial.print("\r\n");
*/
//Serial.print("R99");
//Serial.print(" missed step nr ");
//Serial.print(motorConsMissedSteps[0]);
//Serial.print(" encoder pos ");
//Serial.print(encoderX.currentPosition());
//Serial.print(" axis pos ");
//Serial.print(axisX.currentPosition());
//Serial.print("\r\n");
}
}
}
@ -661,11 +659,6 @@ int StepperControl::calibrateAxis(int axis)
}
}
// Ignore the missed steps at startup time
//if (stepsCount < 20) {
// *missedSteps = 0;
//}
// Move until the end stop for home position is reached, either by end stop or motot skipping
if ((!calibAxis->endStopMin() && !calibAxis->endStopMax()) && !movementDone && (*missedSteps < *missedStepsMax))
{
@ -912,34 +905,36 @@ void StepperControl::checkAxisVsEncoder(StepperControlAxis *axis, StepperControl
bool stepMissed = false;
/*
debugPrintCount++;
if (debugPrintCount % 50 == 0)
{
Serial.print("R99");
Serial.print(" encoder pos ");
Serial.print(encoder->currentPosition());
Serial.print(" axis pos ");
Serial.print(axis->currentPosition());
Serial.print(" last pos ");
Serial.print(*lastPosition);
Serial.print(" move up ");
Serial.print(axis->movingUp());
Serial.print(" missed step cons ");
Serial.print(motorConsMissedSteps[0]);
Serial.print(" missed step ");
Serial.print(*missedSteps);
Serial.print(" encoder X pos ");
Serial.print(encoderX.currentPosition());
Serial.print(" axis X pos ");
Serial.print(axisX.currentPosition());
Serial.print(" decay ");
Serial.print(*encoderStepDecay);
Serial.print(" enabled ");
Serial.print(*encoderEnabled);
Serial.print("\r\n");
}
*/
if (debugInterrupt && debugMessages)
{
debugPrintCount++;
if (debugPrintCount % 50 == 0)
{
Serial.print("R99");
Serial.print(" encoder pos ");
Serial.print(encoder->currentPosition());
Serial.print(" axis pos ");
Serial.print(axis->currentPosition());
Serial.print(" last pos ");
Serial.print(*lastPosition);
Serial.print(" move up ");
Serial.print(axis->movingUp());
Serial.print(" missed step cons ");
Serial.print(motorConsMissedSteps[0]);
Serial.print(" missed step ");
Serial.print(*missedSteps);
Serial.print(" encoder X pos ");
Serial.print(encoderX.currentPosition());
Serial.print(" axis X pos ");
Serial.print(axisX.currentPosition());
Serial.print(" decay ");
Serial.print(*encoderStepDecay);
Serial.print(" enabled ");
Serial.print(*encoderEnabled);
Serial.print("\r\n");
}
}
// Decrease amount of missed steps if there are no missed step
if (*missedSteps > 0)

View File

@ -7,6 +7,7 @@
#include "PinGuard.h"
#include "TimerOne.h"
#include "MemoryFree.h"
#include "Debug.h"
static char commandEndChar = 0x0A;
static GCodeProcessor *gCodeProcessor = new GCodeProcessor();
@ -39,23 +40,26 @@ bool interruptBusy = false;
int interruptSecondTimer = 0;
void interrupt(void)
{
interruptSecondTimer++;
if (interruptBusy == false)
if (!debugInterrupt)
{
interruptSecondTimer++;
interruptBusy = true;
StepperControl::getInstance()->handleMovementInterrupt();
// Check the actions triggered once per second
if (interruptSecondTimer >= 1000000 / MOVEMENT_INTERRUPT_SPEED)
if (interruptBusy == false)
{
interruptSecondTimer = 0;
PinGuard::getInstance()->checkPins();
//blinkLed();
}
interruptBusy = false;
interruptBusy = true;
StepperControl::getInstance()->handleMovementInterrupt();
// Check the actions triggered once per second
if (interruptSecondTimer >= 1000000 / MOVEMENT_INTERRUPT_SPEED)
{
interruptSecondTimer = 0;
PinGuard::getInstance()->checkPins();
//blinkLed();
}
interruptBusy = false;
}
}
}
@ -127,6 +131,11 @@ void setup()
void loop()
{
if (debugInterrupt)
{
StepperControl::getInstance()->handleMovementInterrupt();
}
if (Serial.available())
{
@ -186,8 +195,6 @@ void loop()
}
}
//StepperControl::getInstance()->test();
// Check if parameters are changes, and if so load the new settings
if (lastParamChangeNr != ParameterList::getInstance()->paramChangeNumber())
@ -226,23 +233,28 @@ void loop()
CurrentState::getInstance()->storeEndStops();
CurrentState::getInstance()->printEndStops();
/*
Serial.print(COMM_REPORT_COMMENT);
Serial.print(" MEM ");
Serial.print(freeMemory());
CurrentState::getInstance()->printQAndNewLine();
Serial.print(COMM_REPORT_COMMENT);
Serial.print(" Cycle ");
Serial.print(cycleCounter);
CurrentState::getInstance()->printQAndNewLine();
StepperControl::getInstance()->test();
*/
if (debugMessages)
{
Serial.print(COMM_REPORT_COMMENT);
Serial.print(" MEM ");
Serial.print(freeMemory());
CurrentState::getInstance()->printQAndNewLine();
// if (ParameterList::getInstance()->getValue(PARAM_CONFIG_OK) != 1) {
// Serial.print(COMM_REPORT_NO_CONFIG);
// }
Serial.print(COMM_REPORT_COMMENT);
Serial.print(" Cycle ");
Serial.print(cycleCounter);
CurrentState::getInstance()->printQAndNewLine();
StepperControl::getInstance()->test();
}
// Tim 2017-04-20 Temporary disabling the warning of no valid configuration
// until fully supported on RPI
// if (ParameterList::getInstance()->getValue(PARAM_CONFIG_OK) != 1)
// {
// Serial.print(COMM_REPORT_NO_CONFIG);
// }
cycleCounter++;
lastAction = millis();

View File

@ -125,6 +125,7 @@
<ClInclude Include="Command.h" />
<ClInclude Include="Config.h" />
<ClInclude Include="CurrentState.h" />
<ClInclude Include="Debug.h" />
<ClInclude Include="F11Handler.h" />
<ClInclude Include="F12Handler.h" />
<ClInclude Include="F13Handler.h" />
@ -173,4 +174,4 @@
<UserProperties vm.programmer_name="avrisp" arduino.upload.port="COM3" />
</VisualStudio>
</ProjectExtensions>
</Project>
</Project>

View File

@ -260,5 +260,8 @@
<ClInclude Include="__vm\.src.vsarduino.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Debug.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>