smalruby 0.1.3-x86-mingw32 → 0.1.4-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 +51 -11
- data/lib/smalruby/version.rb +1 -1
- data/samples/check_hardware_smalrubot_s1.rb +11 -1
- data/smalruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba662932637fa77948191d7ba00cd41b679368c
|
4
|
+
data.tar.gz: 60742405c7e343cc468ad33b6eae645ddb8eef6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da9ed79c667e6f487d31171096582b8b59b0918a7917115b7896aab7eb51f8e9b3cce0d4ab01d0e4553f7cd447da671dd2415d9f97faae0749782ddcead3482
|
7
|
+
data.tar.gz: 258dde75fb8473cb20254dce0116bad2ccf782282009a0baa1e00b139733fbc63d45c5bf0ffe84565582d01baaaff17af7cc158ce629614d4e420846f88743a1
|
@@ -7,7 +7,8 @@ module Smalruby
|
|
7
7
|
class SmalrubotS1
|
8
8
|
include Smalrubot::Board::Studuino
|
9
9
|
|
10
|
-
|
10
|
+
# default dc motor pace ratio
|
11
|
+
DEFAULT_DC_MOTOR_PACE_RATIO = 50
|
11
12
|
|
12
13
|
def initialize(_)
|
13
14
|
world.board.init_dc_motor_port(PORT_M1, 0)
|
@@ -18,6 +19,27 @@ module Smalruby
|
|
18
19
|
|
19
20
|
world.board.init_sensor_port(PORT_A4, PIDIRPHOTOREFLECTOR)
|
20
21
|
world.board.init_sensor_port(PORT_A5, PIDIRPHOTOREFLECTOR)
|
22
|
+
|
23
|
+
@dc_motor_pace_ratios = {
|
24
|
+
PORT_M1 => DEFAULT_DC_MOTOR_PACE_RATIO,
|
25
|
+
PORT_M2 => DEFAULT_DC_MOTOR_PACE_RATIO,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def left_dc_motor_pace_ratio
|
30
|
+
@dc_motor_pace_ratios[PORT_M1]
|
31
|
+
end
|
32
|
+
|
33
|
+
def left_dc_motor_pace_ratio=(val)
|
34
|
+
set_dc_motor_pace_ratio(PORT_M1, val)
|
35
|
+
end
|
36
|
+
|
37
|
+
def right_dc_motor_pace_ratio
|
38
|
+
@dc_motor_pace_ratios[PORT_M2]
|
39
|
+
end
|
40
|
+
|
41
|
+
def right_dc_motor_pace_ratio=(val)
|
42
|
+
set_dc_motor_pace_ratio(PORT_M2, val)
|
21
43
|
end
|
22
44
|
|
23
45
|
# @!method forward(sec: nil)
|
@@ -76,26 +98,45 @@ module Smalruby
|
|
76
98
|
|
77
99
|
private
|
78
100
|
|
101
|
+
def set_dc_motor_pace_ratio(port, val)
|
102
|
+
if val < 0
|
103
|
+
@dc_motor_pace_ratios[port] = 0
|
104
|
+
elsif val > 100
|
105
|
+
@dc_motor_pace_ratios[port] = 100
|
106
|
+
else
|
107
|
+
@dc_motor_pace_ratios[port] = val
|
108
|
+
end
|
109
|
+
set_dc_motor_power(port)
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_dc_motor_power(port)
|
113
|
+
ratio = @dc_motor_pace_ratios[port]
|
114
|
+
power = Smalrubot::Board::HIGH * (ratio.to_f / 100)
|
115
|
+
world.board.dc_motor_power(port, power.round)
|
116
|
+
end
|
117
|
+
|
118
|
+
def set_dc_motor_powers
|
119
|
+
@dc_motor_pace_ratios.keys.each do |port|
|
120
|
+
set_dc_motor_power(port)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
79
124
|
def run(direction, sec: nil)
|
80
125
|
case direction
|
81
126
|
when :forward
|
82
|
-
|
83
|
-
world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
|
127
|
+
set_dc_motor_powers
|
84
128
|
world.board.dc_motor_control(PORT_M1, NORMAL)
|
85
129
|
world.board.dc_motor_control(PORT_M2, NORMAL)
|
86
130
|
when :backward
|
87
|
-
|
88
|
-
world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
|
131
|
+
set_dc_motor_powers
|
89
132
|
world.board.dc_motor_control(PORT_M1, REVERSE)
|
90
133
|
world.board.dc_motor_control(PORT_M2, REVERSE)
|
91
134
|
when :turn_left
|
92
|
-
|
93
|
-
world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
|
135
|
+
set_dc_motor_powers
|
94
136
|
world.board.dc_motor_control(PORT_M1, REVERSE)
|
95
137
|
world.board.dc_motor_control(PORT_M2, NORMAL)
|
96
138
|
when :turn_right
|
97
|
-
|
98
|
-
world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
|
139
|
+
set_dc_motor_powers
|
99
140
|
world.board.dc_motor_control(PORT_M1, NORMAL)
|
100
141
|
world.board.dc_motor_control(PORT_M2, REVERSE)
|
101
142
|
when :stop
|
@@ -111,8 +152,7 @@ module Smalruby
|
|
111
152
|
end
|
112
153
|
|
113
154
|
def _stop
|
114
|
-
|
115
|
-
world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
|
155
|
+
set_dc_motor_powers
|
116
156
|
world.board.dc_motor_control(PORT_M1, COAST)
|
117
157
|
world.board.dc_motor_control(PORT_M2, COAST)
|
118
158
|
end
|
data/lib/smalruby/version.rb
CHANGED
@@ -14,7 +14,8 @@ stage1.on(:start) do
|
|
14
14
|
fill(color: 'white')
|
15
15
|
draw_font(string: DESCRIPTION, color: 'black')
|
16
16
|
|
17
|
-
|
17
|
+
smalrubot_s1.left_dc_motor_pace_ratio = 100
|
18
|
+
smalrubot_s1.right_dc_motor_pace_ratio = 100
|
18
19
|
|
19
20
|
loop do
|
20
21
|
if Input.key_down?(K_UP)
|
@@ -25,8 +26,17 @@ stage1.on(:start) do
|
|
25
26
|
|
26
27
|
await until !Input.key_down?(K_UP)
|
27
28
|
|
29
|
+
[75, 50, 25].each do |ratio|
|
30
|
+
smalrubot_s1.left_dc_motor_pace_ratio = ratio
|
31
|
+
smalrubot_s1.right_dc_motor_pace_ratio = ratio
|
32
|
+
sleep(0.1)
|
33
|
+
end
|
34
|
+
|
28
35
|
fill(color: 'white')
|
29
36
|
|
37
|
+
smalrubot_s1.left_dc_motor_pace_ratio = 100
|
38
|
+
smalrubot_s1.right_dc_motor_pace_ratio = 100
|
39
|
+
|
30
40
|
smalrubot_s1.stop
|
31
41
|
end
|
32
42
|
|
data/smalruby.gemspec
CHANGED
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.4
|
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-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -198,14 +198,14 @@ dependencies:
|
|
198
198
|
requirements:
|
199
199
|
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: 0.0.
|
201
|
+
version: 0.0.5
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: 0.0.
|
208
|
+
version: 0.0.5
|
209
209
|
description: smalruby is a 2D game development library. This is part of "Smalruby"
|
210
210
|
project that is a learning ruby programming environment for kids.
|
211
211
|
email:
|