Skip to content

Commit

Permalink
v3.5.1 grbl queue handling fixes and char send delay now an option se…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
zapmaker committed Feb 9, 2014
1 parent 3119699 commit 90a24f4
Show file tree
Hide file tree
Showing 18 changed files with 650 additions and 289 deletions.
4 changes: 2 additions & 2 deletions GrblController.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Grbl Controller"
#define MyAppVersion "3.5"
#define MyAppVersion "3.5.1"
#define MyAppPublisher "Zapmaker"
#define MyAppURL "http://zapmaker.org"
#define MyAppExeName "GrblController.exe"
Expand All @@ -25,7 +25,7 @@ AllowNoIcons=yes
LicenseFile=C:\dev\github\GrblHoming\winlicense.txt
InfoBeforeFile=C:\dev\github\GrblHoming\wininfobefore.txt
InfoAfterFile=C:\dev\github\GrblHoming\wininfoafter.txt
OutputBaseFilename=GrblController35Setup
OutputBaseFilename=GrblController351Setup
Compression=lzma
SolidCompression=yes

Expand Down
23 changes: 23 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ build from source.
Details on how to do this can be found here:
http://zapmaker.org/

V3.5.1
Enhancements
- Made subtle modifications to the command preload when sending a file so that the
command queue on grbl is as full as possible. Previously we were depleting the
queue and then filling it again. This has possible negative performance implications,
although testing shows them to be negligible, probably because we immediately send
a command after the last ok is received.
- The status list view now supports only a maximum of 200 items when active. This was
done for the slower processors like the raspberry pi to prevent excessive CPU usage
when many commands lines exist in a file. When the user grabs the scrollbar, all
items are restored back into the view.
- A new progress bar has been added showing the current items in the grbl queue during
a file send. If the number of items for some reason drops to 0 the label text will
flash red. For this 0 count to occur is a very rare event.
- Added the ability to set the delay between sending of characters to grbl. The theory
is that grbl can drop characters if the sending computer is very fast. There is still
some debate on whether this is happening, so I provided the ability to set this value
in the options from 0 to 20 ms. Note: The default of 0 ms delay is back, like in 3.4.6
and unlike in 3.5 which has a hardcoded 10 ms delay.
Bug fix
- Modified the status window redraw to always ensure items show on the bottom when the
redraw timer expires.

V3.5
Bug fix
- For very fast computers, they send characters with virtually no delay between which
Expand Down
2 changes: 1 addition & 1 deletion controlparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ ControlParams::ControlParams()
xyRateAmount(DEFAULT_XY_RATE),
useAggressivePreload(false), filterFileCommands(false),
reducePrecision(false), grblLineBufferLen(DEFAULT_GRBL_LINE_BUFFER_LEN),
useFourAxis(false)
useFourAxis(false), charSendDelayMs(DEFAULT_CHAR_SEND_DELAY_MS)
{
}
1 change: 1 addition & 0 deletions controlparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ControlParams
bool reducePrecision;
int grblLineBufferLen;
bool useFourAxis;
int charSendDelayMs;
};

#endif // CONTROLPARAMS_H
1 change: 1 addition & 0 deletions definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define DEFAULT_XY_RATE 2000.0

#define DEFAULT_GRBL_LINE_BUFFER_LEN 50
#define DEFAULT_CHAR_SEND_DELAY_MS 0

#define MM_IN_AN_INCH 25.4
#define PRE_HOME_Z_ADJ_MM 5.0
Expand Down
60 changes: 52 additions & 8 deletions gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void GCode::openPort(QString commPortStr, QString baudRate)

currComPort = commPortStr;

port.setCharSendDelayMs(controlParams.charSendDelayMs);

if (port.OpenComport(commPortStr, baudRate))
{
emit portIsOpen(true);
Expand Down Expand Up @@ -395,7 +397,11 @@ bool GCode::sendGcodeInternal(QString line, QString& result, bool recordResponse
else
sendCount.append(CmdResponse(buf, line.length(), currLine));

waitForOk(result, waitSecActual, false, false, aggressive);
//diag("DG Buffer Add %d", sendCount.size());

emit setQueuedCommands(sendCount.size(), true);

waitForOk(result, waitSecActual, false, false, aggressive, false);

if (shutdownState.get())
return false;
Expand All @@ -412,7 +418,7 @@ bool GCode::sendGcodeInternal(QString line, QString& result, bool recordResponse
else
{
sentI++;
if (!waitForOk(result, waitSecActual, sentReqForLocation, sentReqForParserState, aggressive))
if (!waitForOk(result, waitSecActual, sentReqForLocation, sentReqForParserState, aggressive, false))
{
diag(qPrintable(tr("WAITFOROK FAILED\n")));
if (shutdownState.get())
Expand Down Expand Up @@ -464,11 +470,14 @@ bool GCode::sendGcodeInternal(QString line, QString& result, bool recordResponse
return true;
}

bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, bool sentReqForParserState, bool aggressive)
bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, bool sentReqForParserState, bool aggressive, bool finalize)
{
int okcount = 0;

if (aggressive)
{
if (!port.bytesAvailable())
//if (!port.bytesAvailable()) //more conservative code
if (!finalize || !port.bytesAvailable())
{
int total = 0;
bool haveWait = false;
Expand Down Expand Up @@ -509,8 +518,8 @@ bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, boo
count++;
SLEEP(100);
}
else
if (n < 0) {
else if (n < 0)
{
QString Mes(tr("Error reading data from COM port\n")) ;
err(qPrintable(Mes));

Expand Down Expand Up @@ -539,8 +548,13 @@ bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, boo
{
CmdResponse cmdResp = sendCount.takeFirst();
diag(qPrintable(tr("GOT[%d]:%s for %s\n")), cmdResp.line, tmpTrim.toLocal8Bit().constData(), cmdResp.cmd.toLocal8Bit().constData());

//diag("DG Buffer %d", sendCount.size());

emit setQueuedCommands(sendCount.size(), true);
}
rcvdI++;
okcount++;
}
else if (received.contains(RESPONSE_ERROR))
{
Expand All @@ -552,6 +566,10 @@ bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, boo
CmdResponse cmdResp = sendCount.takeFirst();
orig = cmdResp.cmd;
diag(qPrintable(tr("GOT[%d]:%s for %s\n")), cmdResp.line, tmpTrim.toLocal8Bit().constData(), orig.toLocal8Bit().constData());

//diag("DG Buffer %d", sendCount.size());

emit setQueuedCommands(sendCount.size(), true);
}
errorCount++;
QString result;
Expand All @@ -575,8 +593,21 @@ bool GCode::waitForOk(QString& result, int waitSec, bool sentReqForLocation, boo
//printf("Total out (b): %d (%d)\n", total, sendCount.size());
//printf("SENT:%d RCVD:%d\n", sentI, rcvdI);

if (port.bytesAvailable() || total >= (GRBL_RX_BUFFER_SIZE - 1))
if (total >= (GRBL_RX_BUFFER_SIZE - 1))
{
//diag("DG Loop again\n");
result.clear();
continue;
}
else if (port.bytesAvailable())
{
// comment out this block for more conservative approach
if (!finalize && okcount > 0)
{
//diag("DG Leave early\n");
return true;
}

result.clear();
continue;
}
Expand Down Expand Up @@ -979,6 +1010,7 @@ void GCode::sendFile(QString path)
//sendGcodeLocal("", true, SHORT_WAIT_SEC);

setProgress(0);
emit setQueuedCommands(0, false);
grblCmdErrors.clear();
grblFilteredCmds.clear();
errorCount = 0;
Expand All @@ -1001,7 +1033,15 @@ void GCode::sendFile(QString path)
// set here once so that it doesn't change in the middle of a file send
bool aggressive = controlParams.useAggressivePreload;
if (aggressive)
{
sendCount.clear();
//if (sendCount.size() == 0)
//{
// diag("DG Buffer 0 at start\n"));
//}

emit setQueuedCommands(sendCount.size(), true);
}

sentI = 0;
rcvdI = 0;
Expand Down Expand Up @@ -1112,7 +1152,7 @@ void GCode::sendFile(QString path)
while (sendCount.size() > 0 && limitCount)
{
QString result;
waitForOk(result, controlParams.waitTime, false, false, aggressive);
waitForOk(result, controlParams.waitTime, false, false, aggressive, true);
SLEEP(100);

if (shutdownState.get())
Expand Down Expand Up @@ -1189,6 +1229,8 @@ void GCode::sendFile(QString path)
{
emit stopSending();
}

emit setQueuedCommands(0, false);
}

void GCode::trimToEnd(QString& strline, QChar ch)
Expand Down Expand Up @@ -1767,6 +1809,8 @@ void GCode::setResponseWait(ControlParams controlParamsIn)

controlParams.useMm = oldMm;

port.setCharSendDelayMs(controlParams.charSendDelayMs);

if ((oldMm != controlParamsIn.useMm) && isPortOpen() && doubleDollarFormat)
{
if (controlParamsIn.useMm)
Expand Down
3 changes: 2 additions & 1 deletion gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class GCode : public QObject
void adjustedAxis();
void gcodeResult(int id, QString result);
void setProgress(int);
void setQueuedCommands(int, bool);
void resetTimer(bool timeIt);
void enableGrblDialogButton();
void updateCoordinates(Coord3D machineCoord, Coord3D workCoord);
Expand Down Expand Up @@ -117,7 +118,7 @@ public slots:

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 waitForOk(QString& result, int waitCount, bool sentReqForLocation, bool sentReqForParserState, bool aggressive, bool finalize);
bool waitForStartupBanner(QString& result, int waitSec, bool failOnNoFound);
bool sendGcodeInternal(QString line, QString& result, bool recordResponseOnFail, int waitSec, bool aggressive, int currLine = 0);
QString removeUnsupportedCommands(QString line);
Expand Down
Loading

0 comments on commit 90a24f4

Please sign in to comment.