Skip to content

Commit c4937bf

Browse files
committed
Implement G28 (home) (#219)
1 parent 7bb105b commit c4937bf

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/__tests__/interpreter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ test('.G21 sets the units to millimeters', () => {
207207
expect(job.state.units).toEqual('mm');
208208
});
209209

210+
test('.g28 moves the state to the origin', () => {
211+
const command = new GCodeCommand('G28', 'g28', {});
212+
const interpreter = new Interpreter();
213+
const job = new Job();
214+
job.state.x = 3;
215+
job.state.y = 4;
216+
217+
interpreter.G28(command, job);
218+
219+
expect(job.state.x).toEqual(0);
220+
expect(job.state.y).toEqual(0);
221+
expect(job.state.z).toEqual(0);
222+
});
223+
210224
test('.t0 sets the tool to 0', () => {
211225
const command = new GCodeCommand('T0', 't0', {});
212226
const interpreter = new Interpreter();

src/gcode-parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export enum Code {
6363
G3 = 'G3',
6464
G20 = 'G20',
6565
G21 = 'G21',
66+
G28 = 'G28',
6667
T0 = 'T0',
6768
T1 = 'T1',
6869
T2 = 'T2',
@@ -101,6 +102,8 @@ export class GCodeCommand {
101102
return Code.G20;
102103
case 'g21':
103104
return Code.G21;
105+
case 'g28':
106+
return Code.G28;
104107
case 't0':
105108
return Code.T0;
106109
case 't1':

src/interpreter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ export class Interpreter {
138138
job.state.units = 'mm';
139139
}
140140

141+
G28(command: GCodeCommand, job: Job): void {
142+
job.state.x = 0;
143+
job.state.y = 0;
144+
job.state.z = 0;
145+
}
146+
141147
T0(command: GCodeCommand, job: Job): void {
142148
job.state.tool = 0;
143149
}

0 commit comments

Comments
 (0)