robotic-arm 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/robotic-arm.rb +42 -9
- metadata +1 -1
data/lib/robotic-arm.rb
CHANGED
@@ -51,15 +51,21 @@ class RoboticArm
|
|
51
51
|
end
|
52
52
|
|
53
53
|
class ComponentMoving < Component
|
54
|
-
|
54
|
+
|
55
55
|
def initialize(robot_arm)
|
56
56
|
super(robot_arm)
|
57
57
|
@switch, @val = 0, OFF
|
58
|
+
@moving = false
|
58
59
|
end
|
59
60
|
|
60
|
-
def stop()
|
61
|
+
def stop()
|
62
|
+
if moving? then
|
63
|
+
@active = false
|
64
|
+
activate(@switch, -(@prev_val))
|
65
|
+
end
|
66
|
+
end
|
61
67
|
|
62
|
-
|
68
|
+
def moving?() @active ? @moving : false end
|
63
69
|
|
64
70
|
protected
|
65
71
|
|
@@ -72,8 +78,17 @@ class RoboticArm
|
|
72
78
|
|
73
79
|
class ComponentUpDown < ComponentMoving
|
74
80
|
|
75
|
-
def up
|
76
|
-
|
81
|
+
def up(seconds=0)
|
82
|
+
return if @active and @moving == :up
|
83
|
+
activate(@switch, @upval, seconds)
|
84
|
+
@moving = :up
|
85
|
+
end
|
86
|
+
|
87
|
+
def down(seconds=0)
|
88
|
+
return if @active and @moving == :down
|
89
|
+
activate(@switch, @downval, seconds)
|
90
|
+
@moving = :down
|
91
|
+
end
|
77
92
|
end
|
78
93
|
|
79
94
|
class Shoulder < ComponentUpDown
|
@@ -107,14 +122,32 @@ class RoboticArm
|
|
107
122
|
@switch = 1
|
108
123
|
end
|
109
124
|
|
110
|
-
def left
|
111
|
-
|
125
|
+
def left(seconds=0)
|
126
|
+
return if @active and @moving == :left
|
127
|
+
activate(@switch, @val=0x02, seconds)
|
128
|
+
@moving = :left
|
129
|
+
end
|
130
|
+
|
131
|
+
def right(seconds=0)
|
132
|
+
return if @active and @moving == :right
|
133
|
+
activate(@switch, @val=0x01, seconds)
|
134
|
+
@moving = :right
|
135
|
+
end
|
112
136
|
end
|
113
137
|
|
114
138
|
class Gripper < ComponentMoving
|
115
139
|
|
116
|
-
def open (seconds=0)
|
117
|
-
|
140
|
+
def open (seconds=0)
|
141
|
+
return if @active and @moving == :open
|
142
|
+
activate(@switch, @val=0x02, seconds)
|
143
|
+
@moving = :open
|
144
|
+
end
|
145
|
+
|
146
|
+
def close(seconds=0)
|
147
|
+
return if @active and @moving == :close
|
148
|
+
activate(@switch, @val=0x01, seconds)
|
149
|
+
@moving = :close
|
150
|
+
end
|
118
151
|
end
|
119
152
|
|
120
153
|
|