Class: UR::Dash

Inherits:
Object
  • 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



188
189
190
191
192
193
194
195
196
197
# File 'lib/dashboard.rb', line 188

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_releaseObject



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/dashboard.rb', line 283

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_modeObject



247
248
249
250
251
252
253
254
255
256
257
# File 'lib/dashboard.rb', line 247

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

#close_popupmessageObject



183
184
185
186
# File 'lib/dashboard.rb', line 183

def close_popupmessage
  @sock.write ("close popup\n")
  @logger.debug @sock.gets.strip
end

#close_safety_popupObject



314
315
316
317
318
319
320
321
322
323
324
# File 'lib/dashboard.rb', line 314

def close_safety_popup
  @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

#connectObject



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

#connected?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/dashboard.rb', line 68

def connected?
  @conn_state != ConnectionState::DISCONNECTED
end

#disconnectObject



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_programObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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  
  if line.match(/^Loaded program:\s(.+)/)
    @logger.debug line
    path = $1.strip
  else
    @logger.error line
    raise UR::Dash::Reconnect.new('Loaded program can not be got. Dashboard server down or not in Remote Mode')
  end
end

#get_polyscope_versionObject



218
219
220
221
222
223
# File 'lib/dashboard.rb', line 218

def get_polyscope_version
  @sock.write("PolyscopeVersion\n")
  line = @sock.gets.strip
  @logger.debug line
  line
end

#get_program_stateObject



211
212
213
214
215
216
# File 'lib/dashboard.rb', line 211

def get_program_state
  @sock.write("programState\n")
  line = @sock.gets.strip
  @logger.debug line
  line
end

#get_robotmodeObject



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_modeObject



295
296
297
298
299
300
# File 'lib/dashboard.rb', line 295

def get_safety_mode
  @sock.write("safetymode\n")
  line = @sock.gets.strip
  @logger.debug line
  result = $1.strip if line.match(/^Safetymode:\s(.+)/)
end

#is_program_saved?Boolean

Returns:

  • (Boolean)


199
200
201
202
203
204
205
206
207
208
209
# File 'lib/dashboard.rb', line 199

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_installationObject



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/dashboard.rb', line 326

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

#open_popupmessage(message) ⇒ Object



178
179
180
181
# File 'lib/dashboard.rb', line 178

def open_popupmessage(message)
  @sock.write ("popup " + message.to_s + "\n")
  @logger.debug @sock.gets.strip
end

#pause_programObject



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_offObject



271
272
273
274
275
276
277
278
279
280
281
# File 'lib/dashboard.rb', line 271

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_onObject



259
260
261
262
263
264
265
266
267
268
269
# File 'lib/dashboard.rb', line 259

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_safetyObject



338
339
340
341
342
343
344
345
346
347
348
# File 'lib/dashboard.rb', line 338

def restart_safety
  @sock.write("restart safety\n")
  line = @sock.gets.strip
  if line.match(/^Brake/)
    @logger.debug line
    true
  else
    @logger.error line
    raise UR::Dash::Reconnect.new('Cant restart safety. Dashboard server down or not in Remote Mode')
  end
end

#running?Boolean

Returns:

  • (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_autoObject



236
237
238
239
240
241
242
243
244
245
# File 'lib/dashboard.rb', line 236

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_manualObject



225
226
227
228
229
230
231
232
233
234
# File 'lib/dashboard.rb', line 225

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. DDashboard server down or not in Remote Mode')
  end
end

#shutdownObject



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_programObject



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_programObject



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_stopObject



302
303
304
305
306
307
308
309
310
311
312
# File 'lib/dashboard.rb', line 302

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