Skip to content

Commit

Permalink
Fixed issue 45 by providing Option to turn off position query
Browse files Browse the repository at this point in the history
  • Loading branch information
zapmaker committed Apr 28, 2014
1 parent 01f8b72 commit 9a81840
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 75 deletions.
10 changes: 10 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Enhancements
https://github.com/LETARTARE/Grbl_with_Arduino/tree/master/Grbl84Mega2560
which is the A axis grbl variant.
- LETARTARE: Added UVW axes
- #45: Added ability to completely or partially turn off querying position from grbl to
help improve responsiveness. Partial means to turn it off during jog or manual control
which will result in light-greyed LCD numbers. A button to query the position has been
added, which will provided up-to-date position at the time the button is pushed.
Look in Options | Display tab for new button options. You can also set the rate
at which the query takes place from 0.5-10 seconds, if it is enabled. Also, the
current position dot on the Visualizer turns from red to green when the position
is not accurately known to match the color of the path.
NOTE: The default will turn off getting position during manual/jog which means the
LCDs will go into their light grey state. If you don't like this, change in Options.
Bug fix
- Fixed fourth axis adjust buttons and coordinate display greyed out when they shouldn't
be (under specific operating circumstances).
Expand Down
3 changes: 2 additions & 1 deletion controlparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ControlParams::ControlParams()
useAggressivePreload(false), filterFileCommands(false),
reducePrecision(false), grblLineBufferLen(DEFAULT_GRBL_LINE_BUFFER_LEN),
useFourAxis(false), charSendDelayMs(DEFAULT_CHAR_SEND_DELAY_MS),
fourthAxisType(FOURTH_AXIS_A)
fourthAxisType(FOURTH_AXIS_A), usePositionRequest(true),
alwaysRequestPosition(false), postionRequestTimeMilliSec(DEFAULT_POS_REQ_FREQ_MSEC)
{
}
3 changes: 3 additions & 0 deletions controlparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class ControlParams
bool useFourAxis;
int charSendDelayMs;
char fourthAxisType;
bool usePositionRequest;
bool alwaysRequestPosition;
int postionRequestTimeMilliSec;
};

#endif // CONTROLPARAMS_H
5 changes: 5 additions & 0 deletions definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
#define FOURTH_AXIS_B 'B'
#define FOURTH_AXIS_C 'C'

#define PREQ_ALWAYS "always"
#define PREQ_NOT_WHEN_MANUAL "notWhenManual"

#define DEFAULT_POS_REQ_FREQ_SEC 1.0
#define DEFAULT_POS_REQ_FREQ_MSEC 1000

extern AtomicIntBool g_enableDebugLog;

Expand Down
149 changes: 96 additions & 53 deletions gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ GCode::GCode()
incorrectMeasurementUnits(false), incorrectLcdDisplayUnits(false),
maxZ(0), motionOccurred(false),
sliderZCount(0),
positionValid(false),
numaxis(DEFAULT_AXIS_COUNT)
{
// use base class's timer - use it to capture random text from the controller
startTimer(1000);
// for position polling
pollPosTimer.start();
}

void GCode::openPort(QString commPortStr, QString baudRate)
Expand Down Expand Up @@ -195,46 +198,59 @@ void GCode::sendGcode(QString line)
// keep polling our position and state until we are done running
void GCode::pollPosWaitForIdle(bool checkMeasurementUnits)
{
bool immediateQuit = false;
for (int i = 0; i < 10000; i++)
if (controlParams.usePositionRequest
&& (controlParams.alwaysRequestPosition || checkMeasurementUnits))
{
bool ret = sendGcodeLocal(REQUEST_CURRENT_POS);
if (!ret)
bool immediateQuit = false;
for (int i = 0; i < 10000; i++)
{
immediateQuit = true;
break;
}

if (doubleDollarFormat)
{
if (lastState.compare("Run") != 0)
break;
}
else
{
if (machineCoordLastIdlePos == machineCoord
&& workCoordLastIdlePos == workCoord)
GCode::PosReqStatus ret = positionUpdate();
if (ret == POS_REQ_RESULT_ERROR || ret == POS_REQ_RESULT_UNAVAILABLE)
{
immediateQuit = true;
break;
}
else if (ret == POS_REQ_RESULT_TIMER_SKIP)
{
SLEEP(250);
continue;
}

if (doubleDollarFormat)
{
if (lastState.compare("Run") != 0)
break;
}
else
{
if (machineCoordLastIdlePos == machineCoord
&& workCoordLastIdlePos == workCoord)
{
break;
}

machineCoordLastIdlePos = machineCoord;
workCoordLastIdlePos = workCoord;
}

machineCoordLastIdlePos = machineCoord;
workCoordLastIdlePos = workCoord;
if (shutdownState.get())
return;
}

if (shutdownState.get())
if (immediateQuit)
return;
}

if (immediateQuit)
return;

if (checkMeasurementUnits)
if (checkMeasurementUnits)
{
if (doubleDollarFormat)
checkAndSetCorrectMeasurementUnits();
else
setOldFormatMeasurementUnitControl();
}
}
else
{
if (doubleDollarFormat)
checkAndSetCorrectMeasurementUnits();
else
setOldFormatMeasurementUnitControl();
setLivenessState(false);
}
}

Expand Down Expand Up @@ -340,9 +356,10 @@ bool GCode::sendGcodeInternal(QString line, QString& result, bool recordResponse
bool sentReqForSettings = false;
bool sentReqForParserState = false;

if (!line.compare(REQUEST_CURRENT_POS))
if (checkForGetPosStr(line))
{
sentReqForLocation = true;
setLivenessState(true);
}
else if (!line.compare(REQUEST_PARSER_STATE_V08c))
{
Expand Down Expand Up @@ -939,7 +956,7 @@ void GCode::parseCoordinates(const QString& received, bool aggressive)
maxZ = workCoord.z;

emit updateCoordinates(machineCoord, workCoord);
emit setLivePoint(workCoord.x, workCoord.y, controlParams.useMm);
emit setLivePoint(workCoord.x, workCoord.y, controlParams.useMm, positionValid);
emit setLastState(state);

lastState = state;
Expand Down Expand Up @@ -1049,9 +1066,6 @@ void GCode::sendFile(QString path)

parseCoordTimer.restart();

QTime pollPosTimer;
pollPosTimer.start();

int currLine = 0;
bool xyRateSet = false;

Expand Down Expand Up @@ -1129,19 +1143,7 @@ void GCode::sendFile(QString path)
float percentComplete = (currLine * 100.0) / totalLineCount;
setProgress((int)percentComplete);

if (!aggressive)
{
sendGcodeLocal(REQUEST_CURRENT_POS);
}
else
{
int ms = pollPosTimer.elapsed();
if (ms >= 1000)
{
pollPosTimer.restart();
sendGcodeLocal(REQUEST_CURRENT_POS, false, -1, aggressive);
}
}
positionUpdate();
currLine++;
} while ((code.atEnd() == false) && (!abortState.get()));
file.close();
Expand Down Expand Up @@ -1170,7 +1172,7 @@ void GCode::sendFile(QString path)
}
}

sendGcodeLocal(REQUEST_CURRENT_POS);
positionUpdate();

emit resetTimer(false);

Expand Down Expand Up @@ -1705,7 +1707,9 @@ QStringList GCode::doZRateLimit(QString inputLine, QString& msg, bool& xyRateSet

void GCode::gotoXYZFourth(QString line)
{
pollPosWaitForIdle(false);
bool queryPos = checkForGetPosStr(line);
if (!queryPos)
pollPosWaitForIdle(false);

if (sendGcodeLocal(line))
{
Expand Down Expand Up @@ -1735,7 +1739,8 @@ void GCode::gotoXYZFourth(QString line)
//emit addList("No movement expected for command.");
}

pollPosWaitForIdle(false);
if (!queryPos)
pollPosWaitForIdle(false);
}
else
{
Expand Down Expand Up @@ -1852,7 +1857,7 @@ void GCode::checkAndSetCorrectMeasurementUnits()
setConfigureInchesMode(true);
}
incorrectMeasurementUnits = false;// hope this is ok to do here
sendGcodeLocal(REQUEST_CURRENT_POS);
positionUpdate(true);
}
else
{
Expand Down Expand Up @@ -1888,15 +1893,15 @@ void GCode::setConfigureMmMode(bool setGrblUnits)
sendGcodeLocal("$13=0");
if (setGrblUnits)
sendGcodeLocal("G21");
sendGcodeLocal(REQUEST_CURRENT_POS);
positionUpdate(true);
}

void GCode::setConfigureInchesMode(bool setGrblUnits)
{
sendGcodeLocal("$13=1");
if (setGrblUnits)
sendGcodeLocal("G20");
sendGcodeLocal(REQUEST_CURRENT_POS);
positionUpdate(true);
}

void GCode::setUnitsTypeDisplay(bool millimeters)
Expand All @@ -1923,3 +1928,41 @@ int GCode:: getNumaxis()
{
return numaxis;
}

GCode::PosReqStatus GCode::positionUpdate(bool forceIfEnabled /* = false */)
{
if (controlParams.usePositionRequest)
{
if (forceIfEnabled)
{
return sendGcodeLocal(REQUEST_CURRENT_POS) ? POS_REQ_RESULT_OK : POS_REQ_RESULT_ERROR;
}
else
{
int ms = pollPosTimer.elapsed();
if (ms >= controlParams.postionRequestTimeMilliSec)
{
pollPosTimer.restart();
return sendGcodeLocal(REQUEST_CURRENT_POS) ? POS_REQ_RESULT_OK : POS_REQ_RESULT_ERROR;
}
else
{
return POS_REQ_RESULT_TIMER_SKIP;
}
}
}
return POS_REQ_RESULT_UNAVAILABLE;
}

bool GCode::checkForGetPosStr(QString& line)
{
return (!line.compare(REQUEST_CURRENT_POS)
|| (line.startsWith(REQUEST_CURRENT_POS) && line.endsWith('\r') && line.length() == 2));
}

void GCode::setLivenessState(bool valid)
{
positionValid = valid;
emit setVisualLivenessCurrPos(valid);
emit setLcdState(valid);
}
17 changes: 16 additions & 1 deletion gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ class GCode : public QObject
void setLastState(QString state);
void setUnitsWork(QString value);
void setUnitsMachine(QString value);
void setLivePoint(double x, double y, bool isMM);
void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
void setVisCurrLine(int currLine);
void setLcdState(bool valid);
void setVisualLivenessCurrPos(bool isLiveCP);

public slots:
void openPort(QString commPortStr, QString baudRate);
Expand All @@ -116,6 +118,14 @@ public slots:
protected:
void timerEvent(QTimerEvent *event);

private:
enum PosReqStatus
{
POS_REQ_RESULT_OK,
POS_REQ_RESULT_ERROR,
POS_REQ_RESULT_TIMER_SKIP,
POS_REQ_RESULT_UNAVAILABLE
};
private:
bool sendGcodeLocal(QString line, bool recordResponseOnFail = false, int waitSec = -1, bool aggressive = false, int currLine = 0);
bool waitForOk(QString& result, int waitCount, bool sentReqForLocation, bool sentReqForParserState, bool aggressive, bool finalize);
Expand All @@ -139,6 +149,9 @@ public slots:
void sendStatusList(QStringList& listToSend);
void clearToHome();
bool checkGrbl(const QString& result);
PosReqStatus positionUpdate(bool forceIfEnabled = false);
bool checkForGetPosStr(QString& line);
void setLivenessState(bool valid);

private:
RS232 port;
Expand All @@ -162,6 +175,8 @@ public slots:
int sliderZCount;
QStringList grblCmdErrors;
QStringList grblFilteredCmds;
QTime pollPosTimer;
bool positionValid;

int sentI;
int rcvdI;
Expand Down
Loading

0 comments on commit 9a81840

Please sign in to comment.