-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCodeGenerator.pde
More file actions
81 lines (81 loc) · 2.53 KB
/
GCodeGenerator.pde
File metadata and controls
81 lines (81 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class GCodeGenerator {
ArrayList<String> gcode;
Machine printer;
Settings settings;
Processor processor;
GCodeGenerator(Machine t_machine, Settings t_settings, Processor t_processor) {
printer = t_machine;
settings = t_settings;
processor = t_processor;
}
GCodeGenerator generate() {
gcode = new ArrayList<String>();
startPlot();
comment("looping through shapes in processor");
for (RShape shape : processor.shapes) {
for (RShape child : shape.children) {
comment("move to first point of shape");
moveTo(child.getPoint(0));
lowerTool();
RPoint[] points = child.getPoints();
comment("looping through points in shape");
for (int i=0; i<points.length; i++) {
RPoint p1 = points[i];
writeTo(p1);
}
}
}
endPlot();
return this;
}
void write(String command) {
gcode.add(command);
}
void comment(String comment)
{
gcode.add("; "+comment);
}
void moveTo(RPoint p) {
comment("travelling to position");
raiseTool();
write("G00 " + "X" + p.x + " Y" + p.y + " F" + settings.travel_speed);
}
void writeTo(RPoint p2) {
write("G1 " + "X" + p2.x + " Y" + p2.y);
}
void writeTo(RPoint p2, float f) {
comment("writing to position with specified feedrate");
write("G1 " + "X" + p2.x + " Y" + p2.y);
}
void raiseTool() {
comment("raising tool");
write("G00" + " Z" + 0 + " F" + settings.retraction_speed);
}
void lowerTool() {
comment("lowering tool");
write("G00" + " Z" + settings.retraction_amount + " F" + settings.retraction_speed);
}
void setSpeed(float speed) {
comment("overriding feedrate");
write("G1 F" + speed);
}
void startPlot() {
comment("starting plot");
write("G28 X0 Y0"+" ; home xy"); //Home X and Y axes
write("G90"+" ; set absolute movement mode"); //Absolute mode
//write("G00 X" + printer.x_center_table + " Y" + printer.y_center_table + " F8000" + " ; move to center of work area"); //Go to the center
}
void endPlot() {
comment("ending plot");
raiseTool(); //Retract filament to avoid filament drop on last layer
write("G28 X0 Y0"); //Home X and Y axes
}
void export() {
//Create a unique name for the exported file
String name_save = "/output/figure_"+day()+""+hour()+""+minute()+"_"+second()+".gcode";
//Convert from ArrayList to array (required by saveString function)
String[] arr_gcode = gcode.toArray(new String[gcode.size()]);
// Export GCODE
saveStrings(name_save, arr_gcode);
}
}