smalruby 0.1.4-x86-mingw32 → 0.1.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of smalruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/smalruby/hardware/smalrubot_s1.rb +14 -10
- data/lib/smalruby/hardware/smalrubot_v3.rb +50 -11
- data/lib/smalruby/version.rb +1 -1
- data/lib/smalruby.rb +6 -1
- data/samples/check_hardware_smalrubot_s1.rb +9 -8
- data/samples/check_hardware_smalrubot_v3.rb +89 -55
- data/smalruby.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46b5dad32964402e87c3c347e5ac470b37e9fc87
|
4
|
+
data.tar.gz: d57ef38735bce9dfbfc3b2edd25b77b9e4f90746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d63cdd6a279cdd9f7914a6e37a3f05906decc134ddfb0e8eb61775c05621719de9ce53dd2487d988265a83c890f080ab55a1b3331df81f60cdfcd38edf7649
|
7
|
+
data.tar.gz: 90d06e77fe132e07a055342d712de62370a9bdb5b7515d332c8f266f264cedf701bfa845728a0ef09bcdec6443db6bdd05d1746238c8f1cf7432feea3a2ffbc6
|
@@ -72,29 +72,33 @@ module Smalruby
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
75
|
+
def left_sensor_value
|
76
76
|
world.board.get_ir_photoreflector_value(PORT_A4).to_i
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def right_sensor_value
|
80
80
|
world.board.get_ir_photoreflector_value(PORT_A5).to_i
|
81
81
|
end
|
82
82
|
|
83
|
-
def turn_on_white_led
|
84
|
-
world.board.led(PORT_A1, ON)
|
85
|
-
end
|
86
|
-
|
87
|
-
def turn_off_white_led
|
88
|
-
world.board.led(PORT_A1, OFF)
|
89
|
-
end
|
90
|
-
|
91
83
|
def turn_on_blue_led
|
92
84
|
world.board.led(PORT_A0, ON)
|
93
85
|
end
|
86
|
+
alias_method :turn_on_left_led, :turn_on_blue_led
|
94
87
|
|
95
88
|
def turn_off_blue_led
|
96
89
|
world.board.led(PORT_A0, OFF)
|
97
90
|
end
|
91
|
+
alias_method :turn_off_left_led, :turn_off_blue_led
|
92
|
+
|
93
|
+
def turn_on_red_led
|
94
|
+
world.board.led(PORT_A1, ON)
|
95
|
+
end
|
96
|
+
alias_method :turn_on_right_led, :turn_on_red_led
|
97
|
+
|
98
|
+
def turn_off_red_led
|
99
|
+
world.board.led(PORT_A1, OFF)
|
100
|
+
end
|
101
|
+
alias_method :turn_off_right_led, :turn_off_red_led
|
98
102
|
|
99
103
|
private
|
100
104
|
|
@@ -39,14 +39,11 @@ module Smalruby
|
|
39
39
|
# Right Motor that is connected D9, D10, D11
|
40
40
|
attr_reader :right_motor
|
41
41
|
|
42
|
-
# Left
|
43
|
-
attr_reader :
|
42
|
+
# Left sensor that is connected A0
|
43
|
+
attr_reader :left_sensor
|
44
44
|
|
45
|
-
# Right
|
46
|
-
attr_reader :
|
47
|
-
|
48
|
-
# Light sensor that is connected A0
|
49
|
-
attr_reader :light_sensor
|
45
|
+
# Right sensor that is connected A1
|
46
|
+
attr_reader :right_sensor
|
50
47
|
|
51
48
|
def initialize(_)
|
52
49
|
@red_led = Led.new(pin: 'D13')
|
@@ -57,14 +54,28 @@ module Smalruby
|
|
57
54
|
@right_motor = MotorDriver.new(pin: 'D9')
|
58
55
|
@right_motor.speed = 100
|
59
56
|
|
60
|
-
@
|
61
|
-
@
|
62
|
-
|
63
|
-
@light_sensor = Sensor.new(pin: 'A0')
|
57
|
+
@left_sensor = Sensor.new(pin: 'A0')
|
58
|
+
@right_sensor = Sensor.new(pin: 'A1')
|
64
59
|
|
65
60
|
@current_motor_direction = :stop
|
66
61
|
end
|
67
62
|
|
63
|
+
def left_dc_motor_pace_ratio
|
64
|
+
@left_motor.speed
|
65
|
+
end
|
66
|
+
|
67
|
+
def left_dc_motor_pace_ratio=(val)
|
68
|
+
@left_motor.speed = val
|
69
|
+
end
|
70
|
+
|
71
|
+
def right_dc_motor_pace_ratio
|
72
|
+
@right_motor.speed
|
73
|
+
end
|
74
|
+
|
75
|
+
def right_dc_motor_pace_ratio=(val)
|
76
|
+
@right_motor.speed = val
|
77
|
+
end
|
78
|
+
|
68
79
|
# @!method forward(sec: nil)
|
69
80
|
# forward
|
70
81
|
#
|
@@ -104,6 +115,34 @@ module Smalruby
|
|
104
115
|
end
|
105
116
|
end
|
106
117
|
|
118
|
+
def left_sensor_value
|
119
|
+
@left_sensor.value.to_i
|
120
|
+
end
|
121
|
+
|
122
|
+
def right_sensor_value
|
123
|
+
@right_sensor.value.to_i
|
124
|
+
end
|
125
|
+
|
126
|
+
def turn_on_green_led
|
127
|
+
@green_led.turn_on
|
128
|
+
end
|
129
|
+
alias_method :turn_on_left_led, :turn_on_green_led
|
130
|
+
|
131
|
+
def turn_off_green_led
|
132
|
+
@green_led.turn_off
|
133
|
+
end
|
134
|
+
alias_method :turn_off_left_led, :turn_off_green_led
|
135
|
+
|
136
|
+
def turn_on_red_led
|
137
|
+
@red_led.turn_on
|
138
|
+
end
|
139
|
+
alias_method :turn_on_right_led, :turn_on_red_led
|
140
|
+
|
141
|
+
def turn_off_red_led
|
142
|
+
@red_led.turn_off
|
143
|
+
end
|
144
|
+
alias_method :turn_off_right_led, :turn_off_red_led
|
145
|
+
|
107
146
|
private
|
108
147
|
|
109
148
|
def run(direction, sec: nil)
|
data/lib/smalruby/version.rb
CHANGED
data/lib/smalruby.rb
CHANGED
@@ -69,7 +69,6 @@ module Smalruby
|
|
69
69
|
private
|
70
70
|
|
71
71
|
def init_window_application
|
72
|
-
Window.windowed = false unless Util.windows?
|
73
72
|
Window.caption = File.basename($PROGRAM_NAME)
|
74
73
|
Window.fps = 15
|
75
74
|
Window.bgcolor = [255, 255, 255]
|
@@ -220,6 +219,12 @@ end
|
|
220
219
|
|
221
220
|
include Smalruby
|
222
221
|
|
222
|
+
if Util.windows? || ENV['SMALRUBY_WINDOWED']
|
223
|
+
Window.windowed = true
|
224
|
+
else
|
225
|
+
Window.windowed = false
|
226
|
+
end
|
227
|
+
|
223
228
|
at_exit do
|
224
229
|
Smalruby.start if !$ERROR_INFO && !Smalruby.started?
|
225
230
|
end
|
@@ -6,7 +6,8 @@ EOS
|
|
6
6
|
|
7
7
|
require 'smalruby'
|
8
8
|
|
9
|
-
init_hardware
|
9
|
+
init_hardware(device: ENV['SMALRUBOT_DEVICE'],
|
10
|
+
baud: ENV['SMALRUBOT_BAUD'] ? ENV['SMALRUBOT_BAUD'].to_i : nil)
|
10
11
|
|
11
12
|
stage1 = Stage.new(color: 'white')
|
12
13
|
|
@@ -92,28 +93,28 @@ stage1.on(:start) do
|
|
92
93
|
|
93
94
|
if Input.key_down?(K_W)
|
94
95
|
fill(color: 'white')
|
95
|
-
draw_font(string: '
|
96
|
+
draw_font(string: '右のLEDを光らせる', color: 'black')
|
96
97
|
|
97
|
-
smalrubot_s1.
|
98
|
+
smalrubot_s1.turn_on_right_led
|
98
99
|
|
99
100
|
await until !Input.key_down?(K_W)
|
100
101
|
|
101
102
|
fill(color: 'white')
|
102
103
|
|
103
|
-
smalrubot_s1.
|
104
|
+
smalrubot_s1.turn_off_right_led
|
104
105
|
end
|
105
106
|
|
106
107
|
if Input.key_down?(K_B)
|
107
108
|
fill(color: 'white')
|
108
|
-
draw_font(string: '
|
109
|
+
draw_font(string: '左のLEDを光らせる', color: 'black')
|
109
110
|
|
110
|
-
smalrubot_s1.
|
111
|
+
smalrubot_s1.turn_on_left_led
|
111
112
|
|
112
113
|
await until !Input.key_down?(K_B)
|
113
114
|
|
114
|
-
|
115
|
+
smalrubot_s1.turn_off_left_led
|
115
116
|
|
116
|
-
|
117
|
+
fill(color: 'white')
|
117
118
|
end
|
118
119
|
end
|
119
120
|
end
|
@@ -6,9 +6,8 @@ EOS
|
|
6
6
|
|
7
7
|
require 'smalruby'
|
8
8
|
|
9
|
-
init_hardware
|
10
|
-
|
11
|
-
Smalrubot.debug_mode = true
|
9
|
+
init_hardware(device: ENV['SMALRUBOT_DEVICE'],
|
10
|
+
baud: ENV['SMALRUBOT_BAUD'] ? ENV['SMALRUBOT_BAUD'].to_i : nil)
|
12
11
|
|
13
12
|
stage1 = Stage.new(color: 'white')
|
14
13
|
stage1.smalrubot_v3
|
@@ -72,64 +71,56 @@ stage1.on(:start) do
|
|
72
71
|
|
73
72
|
if Input.key_down?(K_W) || Input.key_down?(K_S)
|
74
73
|
if Input.key_down?(K_W)
|
75
|
-
smalrubot_v3.
|
74
|
+
smalrubot_v3.left_dc_motor_pace_ratio += 10
|
76
75
|
else
|
77
|
-
smalrubot_v3.
|
76
|
+
smalrubot_v3.left_dc_motor_pace_ratio -= 10
|
78
77
|
end
|
79
78
|
|
80
79
|
fill(color: 'white')
|
81
|
-
draw_font(string: "左の速度: #{smalrubot_v3.
|
80
|
+
draw_font(string: "左の速度: #{smalrubot_v3.left_dc_motor_pace_ratio}%",
|
82
81
|
color: 'black')
|
83
82
|
end
|
84
83
|
|
85
84
|
if Input.key_down?(K_O) || Input.key_down?(K_L)
|
86
85
|
if Input.key_down?(K_O)
|
87
|
-
smalrubot_v3.
|
86
|
+
smalrubot_v3.right_dc_motor_pace_ratio += 10
|
88
87
|
else
|
89
|
-
smalrubot_v3.
|
88
|
+
smalrubot_v3.right_dc_motor_pace_ratio -= 10
|
90
89
|
end
|
91
90
|
|
92
91
|
fill(color: 'white')
|
93
|
-
draw_font(string: "右の速度: #{smalrubot_v3.
|
92
|
+
draw_font(string: "右の速度: #{smalrubot_v3.right_dc_motor_pace_ratio}%",
|
94
93
|
color: 'black')
|
95
94
|
end
|
96
95
|
|
97
96
|
if Input.key_down?(K_SPACE)
|
98
97
|
fill(color: 'white')
|
99
|
-
draw_font(string: '
|
98
|
+
draw_font(string: '右のLEDを光らせる', color: 'black')
|
100
99
|
|
101
|
-
smalrubot_v3.
|
100
|
+
smalrubot_v3.turn_on_right_led
|
102
101
|
|
103
102
|
sleep(1)
|
104
103
|
|
105
|
-
smalrubot_v3.
|
104
|
+
smalrubot_v3.turn_off_right_led
|
106
105
|
|
107
106
|
fill(color: 'white')
|
108
|
-
draw_font(string: '
|
107
|
+
draw_font(string: '左のLEDを光らせる', color: 'black')
|
109
108
|
|
110
|
-
smalrubot_v3.
|
109
|
+
smalrubot_v3.turn_on_left_led
|
111
110
|
|
112
111
|
sleep(1)
|
113
112
|
|
114
|
-
smalrubot_v3.
|
115
|
-
end
|
113
|
+
smalrubot_v3.turn_off_left_led
|
116
114
|
|
117
|
-
if Input.key_down?(K_B)
|
118
|
-
until !Input.key_down?(K_B)
|
119
|
-
fill(color: 'white')
|
120
|
-
draw_font(string: "光センサーの情報: #{smalrubot_v3.light_sensor.value}",
|
121
|
-
color: 'black')
|
122
|
-
await
|
123
|
-
end
|
124
115
|
fill(color: 'white')
|
125
116
|
end
|
126
117
|
|
127
118
|
if Input.key_down?(K_H)
|
128
119
|
until !Input.key_down?(K_H)
|
129
120
|
fill(color: 'white')
|
130
|
-
msg = '
|
131
|
-
"左 #{smalrubot_v3.
|
132
|
-
"右 #{smalrubot_v3.
|
121
|
+
msg = 'センサーの情報: ' +
|
122
|
+
"左 #{smalrubot_v3.left_sensor_value} " +
|
123
|
+
"右 #{smalrubot_v3.right_sensor_value}"
|
133
124
|
draw_font(string: msg, color: 'black')
|
134
125
|
await
|
135
126
|
end
|
@@ -138,49 +129,92 @@ stage1.on(:start) do
|
|
138
129
|
end
|
139
130
|
end
|
140
131
|
|
132
|
+
THRESHOLD = 400
|
133
|
+
|
141
134
|
stage1.on(:key_push, K_A) do
|
142
135
|
loop do
|
143
136
|
fill(color: 'white')
|
144
137
|
draw_font(string: '自動運転', color: 'black')
|
145
138
|
|
146
|
-
|
147
|
-
|
148
|
-
draw_font(string: '前方障害物発見!', color: 'black')
|
149
|
-
|
150
|
-
smalrubot_v3.backward(sec: 0.5)
|
151
|
-
if rand(2) == 1
|
152
|
-
smalrubot_v3.turn_left(sec: 0.2)
|
153
|
-
else
|
154
|
-
smalrubot_v3.turn_right(sec: 0.2)
|
155
|
-
end
|
156
|
-
|
157
|
-
next
|
158
|
-
end
|
159
|
-
|
160
|
-
if smalrubot_v3.right_touch_sensor.on?
|
161
|
-
fill(color: 'white')
|
162
|
-
draw_font(string: '右側障害物発見!', color: 'black')
|
139
|
+
left_sensor = smalrubot_v3.left_sensor_value < THRESHOLD
|
140
|
+
right_sensor = smalrubot_v3.right_sensor_value < THRESHOLD
|
163
141
|
|
164
|
-
|
165
|
-
smalrubot_v3.
|
166
|
-
|
167
|
-
next
|
142
|
+
if !left_sensor && !right_sensor
|
143
|
+
smalrubot_v3.forward
|
168
144
|
end
|
169
145
|
|
170
|
-
|
171
|
-
|
172
|
-
|
146
|
+
loop do
|
147
|
+
if left_sensor || right_sensor
|
148
|
+
if left_sensor && right_sensor
|
149
|
+
fill(color: 'white')
|
150
|
+
draw_font(string: '前方障害物発見!', color: 'black')
|
151
|
+
|
152
|
+
smalrubot_v3.backward
|
153
|
+
|
154
|
+
loop do
|
155
|
+
left_sensor = smalrubot_v3.left_sensor_value < THRESHOLD
|
156
|
+
right_sensor = smalrubot_v3.right_sensor_value < THRESHOLD
|
157
|
+
if !left_sensor && !right_sensor
|
158
|
+
smalrubot_v3.stop
|
159
|
+
break
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
if rand(2) == 1
|
164
|
+
smalrubot_v3.turn_left(sec: 0.1)
|
165
|
+
else
|
166
|
+
smalrubot_v3.turn_right(sec: 0.1)
|
167
|
+
end
|
168
|
+
else
|
169
|
+
if right_sensor
|
170
|
+
fill(color: 'white')
|
171
|
+
draw_font(string: '右側障害物発見!', color: 'black')
|
172
|
+
|
173
|
+
#smalrubot_v3.backward(sec: 0.1)
|
174
|
+
smalrubot_v3.turn_left
|
175
|
+
|
176
|
+
loop do
|
177
|
+
left_sensor = smalrubot_v3.left_sensor_value < THRESHOLD
|
178
|
+
right_sensor = smalrubot_v3.right_sensor_value < THRESHOLD
|
179
|
+
if !left_sensor && !right_sensor
|
180
|
+
smalrubot_v3.stop
|
181
|
+
break
|
182
|
+
end
|
183
|
+
end
|
184
|
+
else
|
185
|
+
if left_sensor
|
186
|
+
fill(color: 'white')
|
187
|
+
draw_font(string: '左側障害物発見!', color: 'black')
|
188
|
+
|
189
|
+
#smalrubot_v3.backward(sec: 0.1)
|
190
|
+
smalrubot_v3.turn_right
|
191
|
+
|
192
|
+
loop do
|
193
|
+
left_sensor = smalrubot_v3.left_sensor_value < THRESHOLD
|
194
|
+
right_sensor = smalrubot_v3.right_sensor_value < THRESHOLD
|
195
|
+
if !left_sensor && !right_sensor
|
196
|
+
smalrubot_v3.stop
|
197
|
+
break
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
break
|
204
|
+
end
|
173
205
|
|
174
|
-
|
175
|
-
|
206
|
+
if Input.key_down?(K_Y)
|
207
|
+
fill(color: 'white')
|
208
|
+
break
|
209
|
+
end
|
176
210
|
|
177
|
-
|
211
|
+
left_sensor = smalrubot_v3.left_sensor_value < THRESHOLD
|
212
|
+
right_sensor = smalrubot_v3.right_sensor_value < THRESHOLD
|
178
213
|
end
|
179
214
|
|
180
|
-
smalrubot_v3.forward(sec: 0.5)
|
181
|
-
|
182
215
|
if Input.key_down?(K_Y)
|
183
216
|
fill(color: 'white')
|
217
|
+
smalrubot_v3.stop
|
184
218
|
break
|
185
219
|
end
|
186
220
|
end
|
data/smalruby.gemspec
CHANGED
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
40
40
|
if is_windows
|
41
41
|
spec.add_runtime_dependency 'dxruby', '1.4.0'
|
42
42
|
else
|
43
|
-
spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.
|
43
|
+
spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.13'
|
44
44
|
end
|
45
45
|
spec.add_runtime_dependency 'smalrubot', '~> 0.0.5'
|
46
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smalruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Kouji Takao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|