icaro 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icaro.rb +39 -6
- metadata +1 -1
data/lib/icaro.rb
CHANGED
@@ -5,12 +5,6 @@ require 'serialport'
|
|
5
5
|
class Icaro
|
6
6
|
|
7
7
|
#added aliases to use the same names as the apicaro on python api
|
8
|
-
alias :activar :start
|
9
|
-
alias :cerrar :close
|
10
|
-
alias :leer_analogico :read_analog
|
11
|
-
alias :leer_digital :read_digital
|
12
|
-
alias :activar_servo :servo
|
13
|
-
alias :sonido :sound
|
14
8
|
|
15
9
|
#look for the device ttyACM
|
16
10
|
#initialize the device and check if Icaro board is conected and set
|
@@ -35,6 +29,8 @@ alias :sonido :sound
|
|
35
29
|
STDERR.puts ex.message
|
36
30
|
rescue Errno::EBUSY => ex
|
37
31
|
STDERR.puts ex.message
|
32
|
+
rescue Errno::EIO => ex
|
33
|
+
STDERR.puts ex.message
|
38
34
|
rescue IOError => ex
|
39
35
|
STDERR.puts ex.message
|
40
36
|
end
|
@@ -43,9 +39,19 @@ alias :sonido :sound
|
|
43
39
|
puts "Please connect Icaro"
|
44
40
|
end
|
45
41
|
end
|
42
|
+
|
46
43
|
def close
|
44
|
+
begin
|
47
45
|
@sp.close
|
46
|
+
return true
|
47
|
+
rescue Errno::EIO => ex
|
48
|
+
STDERR.puts ex.message
|
49
|
+
rescue IOError => ex
|
50
|
+
return ex
|
51
|
+
end
|
48
52
|
end
|
53
|
+
|
54
|
+
alias cerrar close
|
49
55
|
# set Icaro board to ready status
|
50
56
|
# icaro=Icaro.new
|
51
57
|
# icaro.start('1')
|
@@ -54,10 +60,15 @@ alias :sonido :sound
|
|
54
60
|
@sp.write('s')
|
55
61
|
@sp.write(value)
|
56
62
|
return true
|
63
|
+
rescue Errno::EIO => ex
|
64
|
+
STDERR.puts ex.message
|
57
65
|
rescue IOError => ex
|
58
66
|
return ex
|
59
67
|
end
|
60
68
|
end
|
69
|
+
|
70
|
+
alias activar start
|
71
|
+
|
61
72
|
#Motor move robot DC motors
|
62
73
|
# 1 forward
|
63
74
|
# 2 back
|
@@ -73,6 +84,8 @@ alias :sonido :sound
|
|
73
84
|
@sp.write('l')
|
74
85
|
@sp.write(value)
|
75
86
|
return true
|
87
|
+
rescue Errno::EIO => ex
|
88
|
+
STDERR.puts ex.message
|
76
89
|
rescue IOError => ex
|
77
90
|
return ex
|
78
91
|
end
|
@@ -80,6 +93,7 @@ alias :sonido :sound
|
|
80
93
|
return false
|
81
94
|
end
|
82
95
|
end
|
96
|
+
|
83
97
|
#read analog input sensors
|
84
98
|
#there are 8 analog input ports
|
85
99
|
# icaro.read_analog('3')
|
@@ -89,6 +103,8 @@ alias :sonido :sound
|
|
89
103
|
@sp.write('e')
|
90
104
|
@sp.write(value)
|
91
105
|
return @sp.read
|
106
|
+
rescue Errno::EIO => ex
|
107
|
+
STDERR.puts ex.message
|
92
108
|
rescue IOError => ex
|
93
109
|
return ex
|
94
110
|
end
|
@@ -96,6 +112,9 @@ alias :sonido :sound
|
|
96
112
|
return false
|
97
113
|
end
|
98
114
|
end
|
115
|
+
|
116
|
+
alias leer_analogico read_analog
|
117
|
+
|
99
118
|
#read digital input sensor
|
100
119
|
#there are 4 digital input sensors ports
|
101
120
|
# d=icaro.read_digital('3')
|
@@ -105,6 +124,8 @@ alias :sonido :sound
|
|
105
124
|
@sp.write('d')
|
106
125
|
@sp.write(value)
|
107
126
|
return @sp.read==1 ? 1:0
|
127
|
+
rescue Errno::EIO => ex
|
128
|
+
STDERR.puts ex.message
|
108
129
|
rescue IOError => ex
|
109
130
|
return ex
|
110
131
|
end
|
@@ -112,6 +133,9 @@ alias :sonido :sound
|
|
112
133
|
return false
|
113
134
|
end
|
114
135
|
end
|
136
|
+
|
137
|
+
alias leer_digital read_digital
|
138
|
+
|
115
139
|
#move servo motors
|
116
140
|
#Icaro board has 5 servo engines ports
|
117
141
|
#value is one of 255 characters and move the engine to that position
|
@@ -123,6 +147,8 @@ alias :sonido :sound
|
|
123
147
|
@sp.write(servo)
|
124
148
|
@sp.write(value)
|
125
149
|
return true
|
150
|
+
rescue Errno::EIO => ex
|
151
|
+
STDERR.puts ex.message
|
126
152
|
rescue IOError => ex
|
127
153
|
return ex
|
128
154
|
end
|
@@ -130,6 +156,9 @@ alias :sonido :sound
|
|
130
156
|
return false
|
131
157
|
end
|
132
158
|
end
|
159
|
+
|
160
|
+
alias activar_servo servo
|
161
|
+
|
133
162
|
#sound produce a sound on the port
|
134
163
|
# icaro.sound('2','2')
|
135
164
|
def sound(audio,value)
|
@@ -141,10 +170,14 @@ alias :sonido :sound
|
|
141
170
|
@sp.write('s')
|
142
171
|
@sp.write('0')
|
143
172
|
return true
|
173
|
+
rescue Errno::EIO => ex
|
174
|
+
STDERR.puts ex.message
|
144
175
|
rescue IOError => ex
|
145
176
|
return ex
|
146
177
|
end
|
147
178
|
|
148
179
|
end
|
180
|
+
|
181
|
+
alias sonido sound
|
149
182
|
end
|
150
183
|
|