robotic-arm 0.2.1 → 0.2.2
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.
- data/lib/robotic-arm.rb +81 -24
- metadata +2 -2
data/lib/robotic-arm.rb
CHANGED
@@ -35,39 +35,93 @@ module Session
|
|
35
35
|
@log.first[:time] = @log[1][:time]
|
36
36
|
t1 = @log.first[:time]
|
37
37
|
@log.first[:sleep] = 0
|
38
|
-
@log[1..-2].
|
38
|
+
@log[1..-2].each_with_index do |record,i|
|
39
39
|
t2 = record[:time]
|
40
|
-
|
40
|
+
@log[i][:sleep] = (t2 - t1).round(2)
|
41
41
|
t1 = t2
|
42
42
|
end
|
43
|
+
|
43
44
|
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
@rlog.pop
|
46
|
+
matched = []
|
47
|
+
@rlog = @log.map{|x| x.clone}
|
48
48
|
|
49
|
-
@rlog[0..-2].each_with_index do |record,i |
|
50
|
-
|
51
|
-
classname = record[:class]
|
49
|
+
@rlog.reverse[0..-2].each_with_index do |record,i |
|
52
50
|
|
53
|
-
|
54
|
-
j = @rlog[(i+1)..-1].map{|x| x[:class]}.index(classname)
|
55
|
-
|
56
|
-
next unless j
|
51
|
+
next if matched.include? i
|
57
52
|
|
58
|
-
|
59
|
-
record[:sleep] = swap_state @rlog[i+1+j][:sleep]
|
53
|
+
j = @rlog.reverse[(i+1)..-1].map{|x| x[:class]}.index(record[:class])
|
60
54
|
|
61
|
-
|
62
|
-
@rlog[i+1+j][:sleep] = tmp[:sleep]
|
55
|
+
if j then
|
63
56
|
|
57
|
+
tmp = record.clone
|
58
|
+
record[:method] = @rlog.reverse[i+j+1][:method]
|
59
|
+
record[:sleep] = @rlog.reverse[i+j+1][:sleep]
|
60
|
+
@rlog.reverse[i+j+1][:method] = tmp[:method]
|
61
|
+
@rlog.reverse[i+j+1][:sleep] = tmp[:sleep]
|
62
|
+
matched << i+j+1
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
@rlog.first[:sleep] = 0
|
68
|
+
=begin
|
69
|
+
# The following code includes factors for adjusting the duration of
|
70
|
+
robotic arm movements, as I had observed the distance travelled by
|
71
|
+
the arm n a downward motion != distance travelled in a upward motion
|
72
|
+
for a fixed duration.
|
73
|
+
A more accurate approach would be to add offset times for an actual
|
74
|
+
recorded session.
|
75
|
+
|
76
|
+
@rlog.each do |record|
|
77
|
+
|
78
|
+
if record[:sleep] then
|
79
|
+
|
80
|
+
record[:method] = swap_state record[:method]
|
81
|
+
|
82
|
+
if record[:method] == :stop then
|
83
|
+
#record[:sleep] = (record[:sleep] - 0.03).round(2)
|
84
|
+
elsif record[:class] == :shoulder and record[:method] == :up then
|
85
|
+
record[:sleep] = (record[:sleep] * 1.14).round(2)
|
86
|
+
elsif record[:class] == :elbow and record[:method] == :up then
|
87
|
+
record[:sleep] = (record[:sleep] * 1.14).round(2)
|
88
|
+
elsif record[:class] == :shoulder and record[:method] == :down then
|
89
|
+
record[:sleep] = (record[:sleep] / 1.14).round(2)
|
90
|
+
elsif record[:class] == :elbow and record[:method] == :down then
|
91
|
+
record[:sleep] = (record[:sleep] / 1.14).round(2)
|
92
|
+
|
93
|
+
elsif record[:class] == :gripper and record[:method] == :open then
|
94
|
+
record[:sleep] = (record[:sleep] / 1.14).round(2)
|
95
|
+
elsif record[:class] == :gripper and record[:method] == :close then
|
96
|
+
record[:sleep] = (record[:sleep] * 1.14).round(2)
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
64
101
|
end
|
102
|
+
|
103
|
+
@log.each do |record|
|
104
|
+
|
105
|
+
if record[:sleep] then
|
106
|
+
|
107
|
+
if record[:method] == :stop then
|
108
|
+
#record[:sleep] = (record[:sleep] - 0.03).round(2)
|
109
|
+
elsif record[:class] == :shoulder and record[:method] == :up then
|
110
|
+
record[:sleep] = (record[:sleep] * 1.24).round(2)
|
111
|
+
elsif record[:class] == :shoulder and record[:method] == :down then
|
112
|
+
record[:sleep] = (record[:sleep] / 1.05).round(2)
|
113
|
+
elsif record[:class] == :elbow and record[:method] == :down then
|
114
|
+
record[:sleep] = (record[:sleep] / 1.05).round(2)
|
115
|
+
end
|
65
116
|
|
117
|
+
end
|
118
|
+
end
|
119
|
+
=end
|
66
120
|
@log
|
67
121
|
end
|
68
122
|
|
69
123
|
def record(classname, methodname)
|
70
|
-
|
124
|
+
|
71
125
|
@log << {
|
72
126
|
time: Time.now,
|
73
127
|
class: classname.to_sym,
|
@@ -75,9 +129,9 @@ module Session
|
|
75
129
|
}
|
76
130
|
end
|
77
131
|
|
78
|
-
def recording?() @recording
|
79
|
-
def playback() play @log
|
80
|
-
def reverse_play() play @rlog
|
132
|
+
def recording?() @recording end
|
133
|
+
def playback() play @log end
|
134
|
+
def reverse_play() play @rlog.reverse end
|
81
135
|
|
82
136
|
private
|
83
137
|
|
@@ -85,14 +139,15 @@ module Session
|
|
85
139
|
|
86
140
|
log.each do |record|
|
87
141
|
|
88
|
-
sleep record[:sleep].to_f
|
89
142
|
component, action = *[:class, :method].map{|x| record[x]}
|
90
|
-
|
143
|
+
|
91
144
|
unless component.nil? then
|
92
145
|
@obj.method(component).call.method(action).call
|
93
146
|
else
|
94
147
|
@obj.method(action).call
|
95
148
|
end
|
149
|
+
|
150
|
+
sleep record[:sleep].to_f
|
96
151
|
end
|
97
152
|
end
|
98
153
|
|
@@ -294,8 +349,10 @@ class RoboticArm
|
|
294
349
|
end
|
295
350
|
|
296
351
|
def inspect() '#<RoboticArm:>' end
|
297
|
-
def left(seconds=0) @base.left
|
298
|
-
def right(seconds=0)
|
352
|
+
def left (seconds=0) @base.left seconds end
|
353
|
+
def right(seconds=0) @base.right seconds end
|
354
|
+
def up (seconds=0) @shoulder.up seconds end
|
355
|
+
def down (seconds=0) @shoulder.down seconds end
|
299
356
|
|
300
357
|
# register and invoke the robotic action
|
301
358
|
#
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: robotic-arm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-25 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: libusb
|