robotic-arm 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. data/lib/robotic-arm.rb +42 -9
  2. 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() (@active = false; activate(@switch, -(@prev_val))) if moving? end
61
+ def stop()
62
+ if moving? then
63
+ @active = false
64
+ activate(@switch, -(@prev_val))
65
+ end
66
+ end
61
67
 
62
- alias moving? active?
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 (seconds=0) activate(@switch, @upval, seconds) end
76
- def down(seconds=0) activate(@switch, @downval, seconds) end
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 (seconds=0) activate(@switch, @val=0x02, seconds) end
111
- def right(seconds=0) activate(@switch, @val=0x01, seconds) end
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) activate(@switch, @val=0x02, seconds) end
117
- def close(seconds=0) activate(@switch, @val=0x01, seconds) end
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
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: robotic-arm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson