ur-sock 0.3.3 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8dde2b66e0d8f0ab96fdbe057344b2b7472b65e08811d643ec4d55fa784b55f
4
- data.tar.gz: 9fb11b94f2b0de59f0708e8d785b06a86116080259969e85b9e56dd25eb953cb
3
+ metadata.gz: b0ba8bae1a6d1d252e4c6c31cf0f2836cb98cfd41c9f3c3f908f34af85023c92
4
+ data.tar.gz: f39725dbf3b8fc8f4400a79a7be07992cbcd1807eef3ed6be751b03ca806ca1c
5
5
  SHA512:
6
- metadata.gz: 2ea13d1e1859e308f8d5c8e802987d666ad0fa84ccaf92419234d90ced941ff0fe220ba30d210b507c892d6839dd37f24100dad5131b0109fd2b6018528b2712
7
- data.tar.gz: 926a8c316f11eb496add47ee6de9dd72dfd33cdc1b3b5ff3550592369cdebaea864417440ee7226c8d879e7235d22767ae9253e73e7608281c725f0e5d1baa77
6
+ metadata.gz: 3b92164f0b9042ef02deb4dae4ca87d4f1cc49ec4400c3f46063aa4a78ea5831b2d4fea19266ad1c38532f6cea94ff35ababda446634acfed559b15a9adccf02
7
+ data.tar.gz: c8f691fb6cd1b20571606bd25ab4dc7572b6a9d9ff2193d8cf2fd098f4b0415afa27ff81e359cbfc510bdc255027a3b7c3dd89edcca4415a8673b8686416d4df
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Universal robot interface implementation in ruby. This library provides functions using different interfaces of the universal robot. Primary this was designed for the new e-series.
4
4
 
5
+ ## Requirements
6
+
7
+ This software requires URControl version newer than 5.1.
8
+ Latest supported URControl vresion: 5.5
9
+
5
10
  ## Getting Started
6
11
 
7
12
  This library uses 3 interfaces of the universal robot:
@@ -79,7 +84,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6
79
84
  * **Florian Pauker**
80
85
  * **Jürgen Mangler**
81
86
 
82
- See also the list of [contributors](https://intra.acdp.at/gogs/fpauker/ua4ur/contributors) who participated in this project.
87
+ See also the list of [contributors](https://github.com/fpauker/ua4ur/contributors) who participated in this project.
83
88
 
84
89
  ## License
85
90
 
@@ -6,6 +6,8 @@ require 'uri'
6
6
  module UR
7
7
 
8
8
  class Dash
9
+ class Reconnect < Exception; end
10
+
9
11
  module ConnectionState
10
12
  DISCONNECTED = 'DISCONNECTED'
11
13
  CONNECTED = 'CONNECTED'
@@ -79,15 +81,14 @@ module UR
79
81
  def load_program (programname)
80
82
  @logger.debug "loadprogram"
81
83
  send = "load " + programname + ".urp\n"
82
- puts send
83
- @sock.write (send)
84
+ @sock.write send
84
85
  line = @sock.gets.strip
85
- if line.match(/^./) == 'L'
86
+ if line.match(/^L/)
86
87
  @logger.debug line
87
88
  true
88
89
  else
89
90
  @logger.error line
90
- nil
91
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
91
92
  end
92
93
  end
93
94
 
@@ -99,7 +100,7 @@ module UR
99
100
  true
100
101
  else
101
102
  @logger.error line
102
- nil
103
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
103
104
  end
104
105
  end
105
106
 
@@ -111,7 +112,7 @@ module UR
111
112
  true
112
113
  else
113
114
  @logger.error line
114
- nil
115
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
115
116
  end
116
117
  end
117
118
 
@@ -123,7 +124,7 @@ module UR
123
124
  true
124
125
  else
125
126
  @logger.error line
126
- nil
127
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
127
128
  end
128
129
  end
129
130
 
@@ -135,7 +136,7 @@ module UR
135
136
  true
136
137
  else
137
138
  @logger.error line
138
- nil
139
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
139
140
  end
140
141
  end
141
142
 
@@ -147,7 +148,7 @@ module UR
147
148
  true
148
149
  else
149
150
  @logger.error line
150
- nil
151
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
151
152
  end
152
153
  end
153
154
 
@@ -159,14 +160,19 @@ module UR
159
160
  end
160
161
 
161
162
  def get_loaded_program
162
- @sock.write ("get loaded program\n")
163
- line = @sock.gets.strip
163
+ begin
164
+ @sock.write ("get loaded program\n")
165
+ line = @sock.gets.strip
166
+ rescue
167
+ raise UR::Dash::Reconnect.new('Loaded program can not be got. Dashboard server down or not in Remote Mode')
168
+ end
169
+ @logger.debug line
164
170
  if line.match(/^Loaded program:\s(.+)/)
165
- @logger.debug line
166
- path = $1.strip
167
- else
168
- @logger.error line
171
+ $1.strip
172
+ elsif line.match(/^No program loaded/)
169
173
  nil
174
+ else
175
+ raise UR::Dash::Reconnect.new('Loaded program can not be got. Dashboard server down or not in Remote Mode')
170
176
  end
171
177
  end
172
178
 
@@ -187,6 +193,7 @@ module UR
187
193
  @logger.debug line
188
194
  else
189
195
  @logger.error line
196
+ raise UR::Dash::Reconnect.new('Dashboard server down or not in Remote Mode')
190
197
  end
191
198
  end
192
199
 
@@ -198,7 +205,7 @@ module UR
198
205
  true
199
206
  else
200
207
  @logger.error line
201
- nil
208
+ raise UR::Dash::Reconnect.new('Cant determine if program is saved. Dashboard server down or not in Remote Mode')
202
209
  end
203
210
  end
204
211
 
@@ -223,6 +230,7 @@ module UR
223
230
  @logger.debug line
224
231
  else
225
232
  @logger.error line
233
+ raise UR::Dash::Reconnect.new('Cant set operation mode manual. Dashboard server down or not in Remote Mode')
226
234
  end
227
235
  end
228
236
 
@@ -233,6 +241,7 @@ module UR
233
241
  @logger.debug line
234
242
  else
235
243
  @logger.error line
244
+ raise UR::Dash::Reconnect.new('Cant set operation mode automatic. Dashboard server down or not in Remote Mode')
236
245
  end
237
246
  end
238
247
 
@@ -244,6 +253,7 @@ module UR
244
253
  true
245
254
  else
246
255
  @logger.error line
256
+ raise UR::Dash::Reconnect.new('Cant clear operation mode. Dashboard server down or not in Remote Mode')
247
257
  end
248
258
  end
249
259
 
@@ -255,7 +265,7 @@ module UR
255
265
  true
256
266
  else
257
267
  @logger.error line
258
- nil
268
+ raise UR::Dash::Reconnect.new('Cant power on. Dashboard server down or not in Remote Mode')
259
269
  end
260
270
  end
261
271
 
@@ -267,7 +277,7 @@ module UR
267
277
  true
268
278
  else
269
279
  @logger.error line
270
- nil
280
+ raise UR::Dash::Reconnect.new('Cant power off. Dashboard server down or not in Remote Mode')
271
281
  end
272
282
  end
273
283
 
@@ -279,7 +289,7 @@ module UR
279
289
  true
280
290
  else
281
291
  @logger.error line
282
- nil
292
+ raise UR::Dash::Reconnect.new('Cant release breaks. Dashboard server down or not in Remote Mode')
283
293
  end
284
294
  end
285
295
 
@@ -298,7 +308,7 @@ module UR
298
308
  true
299
309
  else
300
310
  @logger.error line
301
- nil
311
+ raise UR::Dash::Reconnect.new('Cant unlock protective stop. Dashboard server down or not in Remote Mode')
302
312
  end
303
313
  end
304
314
 
@@ -310,7 +320,7 @@ module UR
310
320
  true
311
321
  else
312
322
  @logger.error line
313
- nil
323
+ raise UR::Dash::Reconnect.new('Cant close safety popup. Dashboard server down or not in Remote Mode')
314
324
  end
315
325
  end
316
326
 
@@ -322,7 +332,7 @@ module UR
322
332
  true
323
333
  else
324
334
  @logger.error line
325
- nil
335
+ raise UR::Dash::Reconnect.new('Cant load installation. Dashboard server down or not in Remote Mode')
326
336
  end
327
337
  end
328
338
 
@@ -332,11 +342,76 @@ module UR
332
342
  if line.match(/^Brake/)
333
343
  @logger.debug line
334
344
  true
345
+ elsif line.match(/^could not understand/)
346
+ @logger.warn'Could not execute restart_safety: Please upgrade to current version'
347
+ nil
335
348
  else
336
349
  @logger.error line
350
+ raise UR::Dash::Reconnect.new('Cant restart safety. Dashboard server down or not in Remote Mode')
351
+ end
352
+ end
353
+
354
+ def get_operational_mode
355
+ @sock.write("get operational mode\n")
356
+ line = @sock.gets.strip
357
+ if line == "MANUAL" || line == "AUTOMATIC"
358
+ @logger.debug line
359
+ line
360
+ elsif line == "NONE"
361
+ @logger.warn'No password set, so no modes variable is available'
337
362
  nil
363
+ elsif line.match(/^could not understand/)
364
+ @logger.warn'Could not execute get_operational_mode: Please upgrade to current version'
365
+ nil
366
+ else
367
+ @logger.error line
368
+ raise UR::Dash::Reconnect.new('Cant get operational mode. Dashboard server down or not in Remote Mode')
369
+ end
370
+ end
371
+
372
+ def is_in_remote_control
373
+ @sock.write("is in remote control\n")
374
+ line = @sock.gets.strip
375
+ if line.match(/^could not understand/)
376
+ @logger.warn'Could not execute is_in_remote_control: Please upgrade to current version'
377
+ nil
378
+ elsif line == 'true' || line == 'false'
379
+ @logger.debug line
380
+ line
381
+ else
382
+ @logger.error line
383
+ raise UR::Dash::Reconnect.new('Cant determine if robot is in remote control mode. Dashboard server down maybe down')
384
+ end
385
+ end
386
+
387
+ def get_serial_number
388
+ @sock.write("get serial number\n")
389
+ line = @sock.gets.strip
390
+ if line.match(/^could not understand/)
391
+ @logger.warn'Could not execute get_serial_number: Please upgrade to current version'
392
+ nil
393
+ elsif line.match(/^\d+$/)
394
+ @logger.debug line
395
+ line
396
+ else
397
+ @logger.error line
398
+ raise UR::Dash::Reconnect.new('Cant get serial number. Dashboard server down maybe down or not in Remote Mode')
338
399
  end
339
400
  end
340
401
 
402
+ def get_robot_model
403
+ @sock.write("get robot model\n")
404
+ line = @sock.gets.strip
405
+ if line.match(/^could not understand/)
406
+ @logger.warn'Could not execute get_robot_model: Please upgrade to current version'
407
+ nil
408
+ elsif line.match(/^UR/)
409
+ @logger.debug line
410
+ line
411
+ else
412
+ @logger.error line
413
+ raise UR::Dash::Reconnect.new('Cant get robot model. Dashboard server down maybe down or not in Remote Mode')
414
+ end
415
+ end
341
416
  end
342
417
  end
data/lib/psi.rb CHANGED
@@ -6,6 +6,8 @@ require 'uri'
6
6
  module UR
7
7
 
8
8
  class Psi
9
+ class Reconnect < Exception; end
10
+
9
11
  module ConnectionState
10
12
  DISCONNECTED = 0
11
13
  CONNECTED = 1
@@ -41,18 +43,35 @@ module UR
41
43
  @sock.close
42
44
  @sock = nil
43
45
  @conn_state = ConnectionState::DISCONNECTED
44
- @logger.info "Connection closed " + @hostname + ":" + @port.to_s
46
+ @logger.info 'Connection closed ' + @hostname + ':' + @port.to_s
45
47
  end
46
48
  end
47
49
 
48
- def transfer(filename)
49
- File.open(filename) do |file|
50
- while not file.eof?
51
- @sock.write(file.read(1024))
50
+ def execute_ur_script_file(filename)
51
+ @logger.info 'Executing UR Script File: ' + filename
52
+ begin
53
+ File.open(filename) do |file|
54
+ while not file.eof?
55
+ @sock.write(file.readline)
56
+ line = @sock.gets.strip
57
+ @logger.debug line
58
+ end
52
59
  end
60
+ rescue => e
61
+ raise UR::Psi::Reconnect.new('UR Script can not be got. PSI server down or not in Remote Mode')
53
62
  end
54
63
  end
55
64
 
65
+ def execute_ur_script(str)
66
+ @logger.info 'Executing UR Script ...'
67
+ begin
68
+ @sock.write(str)
69
+ line = @sock.gets.strip
70
+ @logger.debug line
71
+ rescue => e
72
+ raise UR::Psi::Reconnect.new('UR Script can not be got. PSI server down or not in Remote Mode')
73
+ end
74
+ end
56
75
  end
57
76
 
58
77
  end
@@ -101,7 +101,7 @@ module UR
101
101
  def connect #{{{
102
102
  return if @sock
103
103
 
104
- @buf = '' # buffer data in binary format
104
+ @buf = ''.b # buffer data in binary format
105
105
  begin
106
106
  @sock = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
107
107
  @sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1
@@ -159,18 +159,18 @@ module UR
159
159
  @logger.error 'Cannot send when RTDE synchroinization is inactive'
160
160
  return
161
161
  end
162
- if not @input_config.key?(input_data.recipe_id)
162
+ if not @input_config.include? input_data.recipe_id
163
163
  @logger.error 'Input configuration id not found: ' + @input_data.recipe_id
164
164
  return
165
165
  end
166
166
  config = @input_config[input_data.recipe_id]
167
167
  send_all Command::RTDE_DATA_PACKAGE, config.pack(input_data)
168
168
  end #}}}
169
- def send_and_receive(cmd, payload = '') #{{{
169
+ def send_and_receive(cmd, payload = ''.b) #{{{
170
170
  @logger.debug 'Start send_and_receive'
171
171
  send_all(cmd, payload) ? recv(cmd) : nil
172
172
  end #}}}
173
- def send_all(command, payload = '') #{{{
173
+ def send_all(command, payload = ''.b) #{{{
174
174
  fmt = 'S>C'
175
175
  size = ([0,0].pack fmt).length + payload.length
176
176
  buf = [size, command].pack(fmt) + payload
@@ -261,16 +261,16 @@ module UR
261
261
  return true
262
262
  end #}}}
263
263
 
264
- def receive #{{{
264
+ def receive(binary=false) #{{{
265
265
  @logger.debug 'Start receive'
266
266
  if !@output_config
267
267
  @logger.error 'Output configuration not initialized'
268
268
  nil
269
269
  end
270
270
  return nil if @conn_state != ConnectionState::STARTED
271
- recv Command::RTDE_DATA_PACKAGE
271
+ recv Command::RTDE_DATA_PACKAGE, binary
272
272
  end #}}}
273
- def recv(command) #{{{
273
+ def recv(command, binary=false) #{{{
274
274
  @logger.debug 'Start recv' + @buf.to_s
275
275
  while connected?
276
276
  readable, _, xlist = IO.select([@sock], [], [@sock])
@@ -311,7 +311,7 @@ module UR
311
311
  end
312
312
  if packet_header.command == command
313
313
  @logger.debug 'returning becuase of packet_header.command == command'
314
- return data
314
+ return binary ? packet[1..-1] : data
315
315
  else
316
316
  @logger.info 'skipping package(2)'
317
317
  end
@@ -64,6 +64,8 @@ module UR
64
64
  data[offset...offset+size].map(&:to_i)
65
65
  elsif data_type == 'INT32' or data_type == 'UINT8'
66
66
  data[offset].to_i
67
+ elsif data_type == 'BOOL'
68
+ data[offset].to_i > 0 ? true : false
67
69
  else
68
70
  raise TypeError.new('unpack_field: unknown data type: ' + data_type)
69
71
  end
@@ -131,7 +133,6 @@ module UR
131
133
  rmd.id = buf.unpack('C')[0]
132
134
  rmd.types = buf[1..-1].split(',')
133
135
  rmd.fmt = 'C'
134
- #p rmd.types
135
136
  rmd.types.each do |i|
136
137
  if i == 'INT32'
137
138
  rmd.fmt += 'i>'
@@ -151,10 +152,12 @@ module UR
151
152
  rmd.fmt += 'Q>'
152
153
  elsif i == 'UINT8'
153
154
  rmd.fmt += 'C'
155
+ elsif i == 'BOOL'
156
+ rmd.fmt += '?'
154
157
  elsif i == 'IN_USE'
155
- raise TypeError 'An input parameter is already in use.'
158
+ #raise TypeError 'An input parameter is already in use.'
156
159
  else
157
- raise TypeError 'Unknown data type: ' + i
160
+ #raise TypeError 'Unknown data type: ' + i
158
161
  end
159
162
  end
160
163
  rmd
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ur-sock"
3
- s.version = "0.3.3"
3
+ s.version = "1.0.3"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "Preliminary release of Universal Robot (UR) Socket Communication."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ur-sock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Pauker
@@ -9,28 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-04 00:00:00.000000000 Z
12
+ date: 2020-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml-smart
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
18
  - - ">="
22
19
  - !ruby/object:Gem::Version
23
20
  version: 0.3.6
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '0'
31
28
  - - ">="
32
29
  - !ruby/object:Gem::Version
33
30
  version: 0.3.6
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
34
  description: see https://github.com/fpauker/ur-sock
35
35
  email: florian.pauker@gmail.com
36
36
  executables: []
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.0.3
70
+ rubygems_version: 3.1.2
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Preliminary release of Universal Robot (UR) Socket Communication.