Skip to content

Commit

Permalink
[g2core] Address an issue that spindle will restart after stopping pr…
Browse files Browse the repository at this point in the history
…ogram execution (#428) (#451)

[g2core] Address an issue that spindle will restart after stopping program execution (#428)
  • Loading branch information
cheton committed Apr 15, 2019
1 parent 2d4352d commit e45ef3e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
28 changes: 15 additions & 13 deletions src/server/controllers/Grbl/GrblController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Workflow, {
WORKFLOW_STATE_PAUSED,
WORKFLOW_STATE_RUNNING
} from '../../lib/Workflow';
import delay from '../../lib/delay';
import ensurePositiveNumber from '../../lib/ensure-positive-number';
import evaluateAssignmentExpression from '../../lib/evaluate-assignment-expression';
import logger from '../../lib/logger';
Expand Down Expand Up @@ -1054,28 +1055,31 @@ class GrblController {
},
'stop': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
this.command('gcode:stop');
this.command('gcode:stop', ...args);
},
// @param {object} options The options object.
// @param {boolean} [options.force] Whether to force stop a G-code program. Defaults to false.
'gcode:stop': () => {
const { force = false } = { ...args[0] };

'gcode:stop': async () => {
this.event.trigger('gcode:stop');

this.workflow.stop();

const [options] = args;
const { force = false } = { ...options };
if (force) {
const activeState = _.get(this.state, 'status.activeState', '');
let activeState;

activeState = _.get(this.state, 'status.activeState', '');
if (activeState === GRBL_ACTIVE_STATE_RUN) {
this.write('!'); // hold
}
setTimeout(() => {
const activeState = _.get(this.state, 'status.activeState', '');
if (activeState === GRBL_ACTIVE_STATE_HOLD) {
this.write('\x18'); // ctrl-x
}
}, 500); // delay 500ms

await delay(500); // delay 500ms

activeState = _.get(this.state, 'status.activeState', '');
if (activeState === GRBL_ACTIVE_STATE_HOLD) {
this.write('\x18'); // ^x
}
}
},
'pause': () => {
Expand All @@ -1086,7 +1090,6 @@ class GrblController {
this.event.trigger('gcode:pause');

this.workflow.pause();

this.write('!');
},
'resume': () => {
Expand All @@ -1097,7 +1100,6 @@ class GrblController {
this.event.trigger('gcode:resume');

this.write('~');

this.workflow.resume();
},
'feeder:feed': () => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/controllers/Marlin/MarlinController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ class MarlinController {
},
'stop': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
this.command('gcode:stop');
this.command('gcode:stop', ...args);
},
// @param {object} options The options object.
// @param {boolean} [options.force] Whether to force stop a G-code program. Defaults to false.
Expand Down
2 changes: 1 addition & 1 deletion src/server/controllers/Smoothie/SmoothieController.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ class SmoothieController {
},
'stop': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
this.command('gcode:stop');
this.command('gcode:stop', ...args);
},
// @param {object} options The options object.
// @param {boolean} [options.force] Whether to force stop a G-code program. Defaults to false.
Expand Down
40 changes: 26 additions & 14 deletions src/server/controllers/TinyG/TinyGController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Workflow, {
} from '../../lib/Workflow';
import delay from '../../lib/delay';
import ensurePositiveNumber from '../../lib/ensure-positive-number';
import { ensureNumber } from '../../lib/ensure-type';
import evaluateAssignmentExpression from '../../lib/evaluate-assignment-expression';
import logger from '../../lib/logger';
import translateExpression from '../../lib/translate-expression';
Expand Down Expand Up @@ -1092,7 +1093,7 @@ class TinyGController {
},
'stop': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
this.command('gcode:stop');
this.command('gcode:stop', ...args);
},
// @param {object} options The options object.
// @param {boolean} [options.force] Whether to force stop a G-code program. Defaults to false.
Expand All @@ -1101,12 +1102,29 @@ class TinyGController {

this.workflow.stop();

this.writeln('!%'); // feedhold and queue flush
const [options] = args;
const { force = false } = { ...options };
if (force) {
const firmwareBuild = ensureNumber(_.get(this.settings, 'fb'));

if (firmwareBuild >= 101) {
// https://github.com/synthetos/g2/releases/tag/101.02
// * Added explicit Job Kill ^d - has the effect of an M30 (program end)
this.writeln('\x04'); // kill job (^d)
} else if (firmwareBuild >= 100) {
this.writeln('\x04'); // kill job (^d)
this.writeln('M30'); // end of program
} else {
// https://github.com/synthetos/g2/wiki/Feedhold,-Resume,-and-Other-Simple-Commands#jogging-using-feedhold-and-queue-flush
// Send a ! to stop movement immediately.
// Send a % to flush remaining moves from planner buffer.
this.writeln('!'); // feedhold
this.writeln('%'); // queue flush
this.writeln('M30'); // end of program
}
}

setTimeout(() => {
this.writeln('{clear:null}');
this.writeln('{"qr":""}'); // queue report
}, 250); // delay 250ms
this.writeln('{"qr":""}'); // queue report
},
'pause': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
Expand All @@ -1116,9 +1134,7 @@ class TinyGController {
this.event.trigger('gcode:pause');

this.workflow.pause();

this.writeln('!'); // feedhold

this.writeln('{"qr":""}'); // queue report
},
'resume': () => {
Expand All @@ -1129,9 +1145,7 @@ class TinyGController {
this.event.trigger('gcode:resume');

this.writeln('~'); // cycle start

this.workflow.resume();

this.writeln('{"qr":""}'); // queue report
},
'feeder:feed': () => {
Expand Down Expand Up @@ -1176,14 +1190,12 @@ class TinyGController {
// Not supported
},
'unlock': () => {
this.writeln('{clear:null}');
this.writeln('{clear:null}'); // alarm clear
},
'reset': () => {
this.workflow.stop();

this.feeder.reset();

this.write('\x18'); // ^x
this.write('\x18'); // reset board (^x)
},
// Feed Overrides
// @param {number} value A percentage value between 5 and 200. A value of zero will reset to 100%.
Expand Down

0 comments on commit e45ef3e

Please sign in to comment.