-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_Fine_control.R
355 lines (346 loc) · 12.4 KB
/
server_Fine_control.R
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
## server_ink_test.R
output$ink_test_control_1 = renderUI({
tagList(
column(3,
h4("General"),
textInput("test_ink_cmd","Command","G1 X10"),
actionButton("test_ink_cmd_button","Launch GCODE"),
actionButton("test_ink_G28_X0","Home X"),
actionButton("test_ink_G28_Y0","Home Y"),
actionButton("test_ink_G28_Z0","Home Z"),
actionButton("test_ink_M84","Disable Motors"),
# uiOutput("temp_1"),
actionButton("test_ink_LED","LED gcode in pin 63 (for testing only)"),
actionButton("test_ink_LED_stop","Stop_LED (for testing only)")
),
column(3,
h4("Inkjet"),
numericInput("test_ink_n","Number of fire (repetition)",10),
numericInput("test_ink_n_bis","Number of fire bis (I)",2),
numericInput("test_ink_L","Pulse length",5),
checkboxGroupInput("test_ink_S","Nozzles to fire",choices = seq(12),inline = T,selected = seq(12)),
# numericInput("test_ink_S","S",4095),
actionButton("test_ink_action",label = "Fire selected nozzles"),
actionButton("test_ink_nozzle_test",label = "Nozzle testing process")
),
column(3,
h4("Layer printing"),
actionButton("test_ink_extrude_1mm","Extrude 1 mm"),
actionButton("test_ink_extrude_5mm","Extrude 5 mm"),
actionButton("test_ink_retract_5mm","Retract 5 mm"),
numericInput("test_ink_bed_temp","Bed temperature (Prusa only)",105),
actionButton("test_ink_bed_set","Set bed temperature")
),
column(3,
p("For testing only"),
plotOutput("test_ink_plot",click="test_ink_plot_click")
),
column(3,
h4("Gcode upload"),
fileInput("test_ink_gcode_file","Upload a GCODE file"),
actionButton("test_ink_gcode_file_action","Launch the GCODE file")
),
column(3,
h4("Documentation"),
actionButton("test_ink_visu_position","Go in position"),
actionButton("test_ink_red","Red light"),
actionButton("test_ink_green","Green light"),
actionButton("test_ink_blue","Blue light"),
actionButton("test_ink_white","White light"),
actionButton("test_ink_254","254 nm light"),
actionButton("test_ink_light_off","Turn light off")#,
# actionButton("test_ink_ring_on","ring on"),
# actionButton("test_ink_ring_off","ring off")
)
)
})
observeEvent(input$test_ink_visu_position,{
if(connect$board){
main$send_gcode("gcode/Visu_position.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_red,{
if(connect$board){
main$send_gcode("gcode/Red.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_green,{
if(connect$board){
main$send_gcode("gcode/Green.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_blue,{
if(connect$board){
main$send_gcode("gcode/Blue.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_white,{
if(connect$board){
main$send_gcode("gcode/White.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_254,{
if(connect$board){
main$send_gcode("gcode/254 nm.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_light_off,{
if(connect$board){
main$send_gcode("gcode/light_off.gcode")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_gcode_file_action,{
if(connect$board){
main$send_gcode(input$test_ink_gcode_file$datapath)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
test_TempInvalidate <- reactiveTimer(2000)
output$temp_1 = renderUI({
validate(
need(connect$board,"Please connect the board")
)
# test_TempInvalidate()
# full = python.call("get_temp")
# full = gsub(pattern = "ok T:0.0 /0.0 B:",x = full,replacement = "Bed temp: ")
# full = gsub(pattern = "@:0 B@:0",x = full,replacement = "°C")
tagList(
# h6(full),
h6("M104 S90; set temp to 90 degree celsius")
)
})
observeEvent(input$test_ink_nozzle_test,{
if(connect$board){
gcode = c("G91",paste0("M700 P0 I",input$test_ink_n_bis," L",input$test_ink_L," S",4095))
for(i in seq(12)){
S=rep(0,12);S[i] = 1;S = BinToDec(S)
for(j in seq(10)){gcode = c(gcode,paste0("G1 X",0.25),"M400",paste0("M700 P0 I",input$test_ink_n_bis," L",input$test_ink_L," S",S))}
}
gcode = c(gcode,paste0("G1 X",2),"M400",paste0("M700 P0 I",input$test_ink_n_bis," L",input$test_ink_L," S",4095))
gcode = c(gcode,"G90","M84")
test_ink_file = paste0("gcode/","test_ink",".gcode")
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(gcode, fileConn)
close(fileConn)
# send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_action,{
if(connect$board){
# create the gcode
# test_ink_file = paste0("gcode/",format(Sys.time(),"%Y%m%d_%H:%M:%S"),"test_ink",".gcode")
test_ink_file = paste0("gcode/","test_ink",".gcode")
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(test_ink_gcode(), fileConn)
close(fileConn)
# put it in the log
write(paste0(format(Sys.time(),"%Y%m%d_%H:%M:%S"),";","test_ink;",test_ink_file,";",Log,";",connect$Visa,";",input$Plate),file="log/log.txt",append = T)
# send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
test_ink_gcode <- reactive({
# paste0("M700 P0 I",input$test_ink_n_bis," S",input$test_ink_S)
# rep(paste0("M700 P0 S",input$test_ink_S),input$test_ink_n)
S=rep(0,12)
for(i in seq(12)){if(i %in% as.numeric(input$test_ink_S)){S[i] = 1}};S = BinToDec(S)
rep(paste0("M700 P0 I",input$test_ink_n_bis," L",input$test_ink_L," S",S),input$test_ink_n)
})
observeEvent(input$test_ink_cmd_button,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(input$test_ink_cmd, fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
output$test_ink_plot = renderPlot({
x = c(0,130)
y = c(80,0)
plot(x,y,type="n",xlim=x,ylim=y,main="Origin in Upper left corner",xaxs="i",yaxs="i",
xlab="X",ylab="Y")
abline(h=seq(from=0,to=200,by = 10),v=seq(from=0,to=200,by = 10))
})
observeEvent(input$test_ink_plot_click,{
if(connect$board){
if(!is.null(input$test_ink_plot_click)){
truc = paste0("G1 X",round(input$test_ink_plot_click$x,4)," Y",round(input$test_ink_plot_click$y,4))
print(truc)
# create the gcode
test_ink_file = "gcode/test_ink_plot.gcode"
fileConn<-file(test_ink_file)
writeLines(truc, fileConn)
close(fileConn)
# send the gcode
main$send_gcode(test_ink_file)
}
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_LED,{
if(connect$board){
main$send_gcode("gcode/LED.gcode")
# py_run_file("send_gcode.py")
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_LED_stop,{
main$cancelprint() ## py
# main$cancelprint()
})
# observeEvent(input$test_ink_LED_stop,{
# validate(need(!input$Serial_windows,"not on windows"))
# if(!is.null(rv$id$pid)){
# tools::pskill(rv$id$pid)
# rv$id <- list()
# }
# })
# observeEvent(input$test_ink_ring_on,{
# # if(connect$board){
# # main$send_gcode("gcode/LED.gcode")
# main$colorWipe(255L,0)
# # }else{
# # shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
# # }
# })
# observeEvent(input$test_ink_ring_off,{
# # if(connect$board){
# # main$send_gcode("gcode/LED.gcode")
# main$colorWipe(0L,0)
# # }else{
# # shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
# # }
# })
observeEvent(input$test_ink_G28_X0,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines("G28 X0", fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_G28_Y0,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines("G28 Y0", fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_G28_Z0,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines("G28 Z0", fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_M84,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines("M84", fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_extrude_1mm,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(c("G92 E0","G1 E1"), fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_extrude_5mm,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(c("G92 E0","G1 E5"), fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_retract_5mm,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(c("G92 E0","G1 E-5"), fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})
observeEvent(input$test_ink_bed_set,{
if(connect$board){
# create the gcode
test_ink_file = "gcode/test_ink_cmd.gcode"
Log = test_ink_file
fileConn<-file(test_ink_file)
writeLines(paste0("M140 S",input$test_ink_bed_temp), fileConn)
close(fileConn) # send the gcode
main$send_gcode(test_ink_file)
}else{
shinyalert(title = "Error",text = "Board not connected",type="error",closeOnClickOutside = T, showCancelButton = F)
}
})