Class: UR::Dash
- Inherits:
-
Object
show all
- Defined in:
- lib/dashboard.rb
Defined Under Namespace
Modules: ConnectionState, ProgramState, SafetyMode
Classes: Reconnect
Instance Method Summary
collapse
Constructor Details
#initialize(host, logger = Logger.new(STDOUT,level: :INFO)) ⇒ Dash
Returns a new instance of Dash.
48
49
50
51
52
53
54
55
56
|
# File 'lib/dashboard.rb', line 48
def initialize(host, logger=Logger.new(STDOUT,level: :INFO))
host = '//' + host if host !~ /\/\//
uri = URI::parse(host)
@logger = logger
@hostname = uri.host
@port = uri.port.nil? ? 29999 : uri.port
@conn_state = ConnectionState::DISCONNECTED
@sock = nil
end
|
Instance Method Details
#add_to_log(message) ⇒ Object
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/dashboard.rb', line 189
def add_to_log(message)
@sock.write ("addToLog " + message.to_s + "\n")
line = @sock.gets.strip
if line.match(/^Added log message/)
@logger.debug line
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#break_release ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/dashboard.rb', line 284
def break_release
@sock.write("brake release\n")
line = @sock.gets.strip
if line.match(/^Brake/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant release breaks. Dashboard server down or not in Remote Mode')
end
end
|
#clear_operation_mode ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/dashboard.rb', line 248
def clear_operation_mode
@sock.write("clear operational mode\n")
line = @sock.gets.strip
if line.match(/^operational/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant clear operation mode. Dashboard server down or not in Remote Mode')
end
end
|
184
185
186
187
|
# File 'lib/dashboard.rb', line 184
def
@sock.write ("close popup\n")
@logger.debug @sock.gets.strip
end
|
315
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/dashboard.rb', line 315
def
@sock.write("close safety popup\n")
line = @sock.gets.strip
if line.match(/^closing/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant close safety popup. Dashboard server down or not in Remote Mode')
end
end
|
#connect ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/dashboard.rb', line 58
def connect
return if @sock
@sock = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
@sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1
@sock = TCPSocket.new(@hostname, @port)
@conn_state = ConnectionState::CONNECTED
@logger.info @sock.gets.strip
self
end
|
#disconnect ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/dashboard.rb', line 72
def disconnect
if @sock
@sock.close
@sock = nil
@conn_state = ConnectionState::DISCONNECTED
@logger.info "Connection closed " + @hostname + ":" + @port.to_s
end
end
|
#get_loaded_program ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/dashboard.rb', line 162
def get_loaded_program
begin
@sock.write ("get loaded program\n")
line = @sock.gets.strip
rescue
raise UR::Dash::Reconnect.new('Loaded program can not be got. Dashboard server down or not in Remote Mode')
end
@logger.debug line
if line.match(/^Loaded program:\s(.+)/)
$1.strip
elsif line.match(/^No program loaded/)
nil
else
raise UR::Dash::Reconnect.new('Loaded program can not be got. Dashboard server down or not in Remote Mode')
end
end
|
#get_operational_mode ⇒ Object
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
# File 'lib/dashboard.rb', line 354
def get_operational_mode
@sock.write("get operational mode\n")
line = @sock.gets.strip
if line == "MANUAL" || line == "AUTOMATIC"
@logger.debug line
line
elsif line == "NONE"
@logger.warn'No password set, so no modes variable is available'
nil
elsif line.match(/^could not understand/)
@logger.warn'Could not execute get_operational_mode: Please upgrade to current version'
nil
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant get operational mode. Dashboard server down or not in Remote Mode')
end
end
|
#get_polyscope_version ⇒ Object
219
220
221
222
223
224
|
# File 'lib/dashboard.rb', line 219
def get_polyscope_version
@sock.write("PolyscopeVersion\n")
line = @sock.gets.strip
@logger.debug line
line
end
|
#get_program_state ⇒ Object
212
213
214
215
216
217
|
# File 'lib/dashboard.rb', line 212
def get_program_state
@sock.write("programState\n")
line = @sock.gets.strip
@logger.debug line
line
end
|
#get_robot_model ⇒ Object
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
# File 'lib/dashboard.rb', line 402
def get_robot_model
@sock.write("get robot model\n")
line = @sock.gets.strip
if line.match(/^could not understand/)
@logger.warn'Could not execute get_robot_model: Please upgrade to current version'
nil
elsif line.match(/^UR/)
@logger.debug line
line
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant get robot model. Dashboard server down maybe down or not in Remote Mode')
end
end
|
#get_robotmode ⇒ Object
155
156
157
158
159
160
|
# File 'lib/dashboard.rb', line 155
def get_robotmode
@sock.write("robotmode\n")
line = @sock.gets.strip
@logger.debug line
result = $1.strip if line.match(/^Robotmode:\s(.+)/)
end
|
#get_safety_mode ⇒ Object
296
297
298
299
300
301
|
# File 'lib/dashboard.rb', line 296
def get_safety_mode
@sock.write("safetymode\n")
line = @sock.gets.strip
@logger.debug line
result = $1.strip if line.match(/^Safetymode:\s(.+)/)
end
|
#get_serial_number ⇒ Object
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/dashboard.rb', line 387
def get_serial_number
@sock.write("get serial number\n")
line = @sock.gets.strip
if line.match(/^could not understand/)
@logger.warn'Could not execute get_serial_number: Please upgrade to current version'
nil
elsif line.match(/^\d+$/)
@logger.debug line
line
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant get serial number. Dashboard server down maybe down or not in Remote Mode')
end
end
|
#is_in_remote_control ⇒ Object
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/dashboard.rb', line 372
def is_in_remote_control
@sock.write("is in remote control\n")
line = @sock.gets.strip
if line.match(/^could not understand/)
@logger.warn'Could not execute is_in_remote_control: Please upgrade to current version'
nil
elsif line == 'true' || line == 'false'
@logger.debug line
line
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant determine if robot is in remote control mode. Dashboard server down maybe down')
end
end
|
#is_program_saved? ⇒ Boolean
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/dashboard.rb', line 200
def is_program_saved?
@sock.write("isProgramSaved\n")
line = @sock.gets.strip
if line == "True"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant determine if program is saved. Dashboard server down or not in Remote Mode')
end
end
|
#load_installation ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/dashboard.rb', line 327
def load_installation
@sock.write("load installation\n")
line = @sock.gets.strip
if line.match(/^Loading/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant load installation. Dashboard server down or not in Remote Mode')
end
end
|
#load_program(programname) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/dashboard.rb', line 81
def load_program (programname)
@logger.debug "loadprogram"
send = "load " + programname + ".urp\n"
@sock.write send
line = @sock.gets.strip
if line.match(/^L/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
179
180
181
182
|
# File 'lib/dashboard.rb', line 179
def (message)
@sock.write ("popup " + message.to_s + "\n")
@logger.debug @sock.gets.strip
end
|
#pause_program ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/dashboard.rb', line 119
def pause_program
@sock.write("pause\n")
line = @sock.gets.strip
if line == "Pausing program"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#power_off ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/dashboard.rb', line 272
def power_off
@sock.write("power off\n")
line = @sock.gets.strip
if line.match(/^Powering/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant power off. Dashboard server down or not in Remote Mode')
end
end
|
#power_on ⇒ Object
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/dashboard.rb', line 260
def power_on
@sock.write("power on\n")
line = @sock.gets.strip
if line.match(/^Powering/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant power on. Dashboard server down or not in Remote Mode')
end
end
|
#restart_safety ⇒ Object
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/dashboard.rb', line 339
def restart_safety
@sock.write("restart safety\n")
line = @sock.gets.strip
if line.match(/^Brake/)
@logger.debug line
true
elsif line.match(/^could not understand/)
@logger.warn'Could not execute restart_safety: Please upgrade to current version'
nil
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant restart safety. Dashboard server down or not in Remote Mode')
end
end
|
#running? ⇒ Boolean
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/dashboard.rb', line 143
def running?
@sock.write("running\n")
line = @sock.gets.strip
if line == "Program running: True"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#set_operation_mode_auto ⇒ Object
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/dashboard.rb', line 237
def set_operation_mode_auto
@sock.write("set operational mode automatic\n")
line = @sock.gets.strip
if line.match(/^S/)
@logger.debug line
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant set operation mode automatic. Dashboard server down or not in Remote Mode')
end
end
|
#set_operation_mode_manual ⇒ Object
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/dashboard.rb', line 226
def set_operation_mode_manual
@sock.write("set operational mode manual\n")
line = @sock.gets.strip
if line.match(/^S/)
@logger.debug line
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant set operation mode manual. Dashboard server down or not in Remote Mode')
end
end
|
#shutdown ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/dashboard.rb', line 131
def shutdown
@sock.write("shutdown\n")
line = @sock.gets.strip
if line == "Shutting down"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#start_program ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/dashboard.rb', line 95
def start_program
@sock.write("play\n")
line = @sock.gets.strip
if line == "Starting program"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#stop_program ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/dashboard.rb', line 107
def stop_program
@sock.write("stop\n")
line = @sock.gets.strip
if line == "Stopped"
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
end
end
|
#unlock_protective_stop ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
|
# File 'lib/dashboard.rb', line 303
def unlock_protective_stop
@sock.write("unlock protective stop\n")
line = @sock.gets.strip
if line.match(/^Protective/)
@logger.debug line
true
else
@logger.error line
raise UR::Dash::Reconnect.new('Cant unlock protective stop. Dashboard server down or not in Remote Mode')
end
end
|