Skip to content

Commit 1f27e2a

Browse files
committed
Implement G28 (home)
1 parent bcf7682 commit 1f27e2a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/__tests__/interpreter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ test('.G20 sets the units to inches', () => {
180180
expect(job.state.units).toEqual('in');
181181
});
182182

183+
test('.g28 moves the state to the origin', () => {
184+
const command = new GCodeCommand('G28', 'g28', {});
185+
const interpreter = new Interpreter();
186+
const job = new Job();
187+
job.state.x = 3;
188+
job.state.y = 4;
189+
190+
interpreter.G28(command, job);
191+
192+
expect(job.state.x).toEqual(0);
193+
expect(job.state.y).toEqual(0);
194+
expect(job.state.z).toEqual(0);
195+
});
196+
183197
test('.t0 sets the tool to 0', () => {
184198
const command = new GCodeCommand('T0', 't0', {});
185199
const interpreter = new Interpreter();

src/gcode-parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export enum Code {
6262
G2 = 'G2',
6363
G3 = 'G3',
6464
G20 = 'G20',
65+
G28 = 'G28',
6566
T0 = 'T0',
6667
T1 = 'T1',
6768
T2 = 'T2',
@@ -98,6 +99,8 @@ export class GCodeCommand {
9899
return Code.G3;
99100
case 'g20':
100101
return Code.G20;
102+
case 'g28':
103+
return Code.G28;
101104
case 't0':
102105
return Code.T0;
103106
case 't1':

src/interpreter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ export class Interpreter {
134134
job.state.units = 'in';
135135
}
136136

137+
G28(command: GCodeCommand, job: Job): void {
138+
job.state.x = 0;
139+
job.state.y = 0;
140+
job.state.z = 0;
141+
}
142+
137143
T0(command: GCodeCommand, job: Job): void {
138144
job.state.tool = 0;
139145
}

0 commit comments

Comments
 (0)