smalruby 0.1.2-x86-mingw32 → 0.1.3-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d4ec449019b1e028e6ccaf477c20686cb7df8d1
4
- data.tar.gz: 97424d8c19c1ff8082b08ae7530ec60dac16bfde
3
+ metadata.gz: e9c7d79fbba60758c64d066b9abd9eca99553824
4
+ data.tar.gz: 3caaefb79371fa79e97965750191432e1c2ecc04
5
5
  SHA512:
6
- metadata.gz: 87dcea92d065219e69007fed09eac2da801d0393c59e992c3d79d971f7fe0ce3ff2bc6d918eda9f6d34d0a23a6f815dac6ae1e4a4508533f91593799cbca437d
7
- data.tar.gz: 699be7d82891b6a359c92ef42e88995e1bf4bdecdd6b03b4d51429dff241832b05a101612d4be66712b03be1f22b80ed95a403fa2d8c310c7a7ff3fabaf33c86
6
+ metadata.gz: bfeb102659f0936bb341b3eca22c00dc695879e89b8d90bb679d7738e4f55b0697f41e9ac527068979e919ab4b22cf19a4c6c1238568dc37733ced79ea944215
7
+ data.tar.gz: f76a9ab3d5fd13c32fcac3600c859c093c7abebf39e85195333bed040e5e5d4d02dd59f84590b2d465ecac1f52c19f7d5a8c37f672e32f80b195abb92e678bca
data/Gemfile CHANGED
@@ -3,6 +3,10 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in smalruby.gemspec
4
4
  gemspec
5
5
 
6
- if File.exist?(File.expand_path('~/work/dxruby_sdl/'))
7
- gem 'dxruby_sdl', path: '~/work/dxruby_sdl/'
6
+ if File.exist?(File.expand_path('~/work/smalruby/dxruby_sdl/'))
7
+ gem 'dxruby_sdl', path: '~/work/smalruby/dxruby_sdl/'
8
+ end
9
+
10
+ if File.exist?(File.expand_path('~/work/smalruby/smalrubot/'))
11
+ gem 'smalrubot', path: '~/work/smalruby/smalrubot/'
8
12
  end
@@ -411,9 +411,9 @@ module Smalruby
411
411
  Hardware.create_hardware(Hardware::SmalrubotV3)
412
412
  end
413
413
 
414
- # create or get Hardware::Studuino instance
415
- def studuino
416
- Hardware.create_hardware(Hardware::Studuino)
414
+ # create or get Hardware::SmalrubotS1 instance
415
+ def smalrubot_s1
416
+ Hardware.create_hardware(Hardware::SmalrubotS1)
417
417
  end
418
418
 
419
419
  # @!endgroup
@@ -3,15 +3,21 @@ require 'smalruby/hardware'
3
3
 
4
4
  module Smalruby
5
5
  module Hardware
6
- # Studuino class
7
- class Studuino
6
+ # Smalrubot on Studuino v1 class
7
+ class SmalrubotS1
8
8
  include Smalrubot::Board::Studuino
9
9
 
10
+ DC_MOTOR_PACE = (255 * 0.50).round
11
+
10
12
  def initialize(_)
11
13
  world.board.init_dc_motor_port(PORT_M1, 0)
12
14
  world.board.init_dc_motor_port(PORT_M2, 0)
13
15
 
14
- world.board.init_sensor_port(PORT_A0, PIDIRPHOTOREFLECTOR)
16
+ world.board.init_sensor_port(PORT_A0, PIDLED)
17
+ world.board.init_sensor_port(PORT_A1, PIDLED)
18
+
19
+ world.board.init_sensor_port(PORT_A4, PIDIRPHOTOREFLECTOR)
20
+ world.board.init_sensor_port(PORT_A5, PIDIRPHOTOREFLECTOR)
15
21
  end
16
22
 
17
23
  # @!method forward(sec: nil)
@@ -44,8 +50,28 @@ module Smalruby
44
50
  end
45
51
  end
46
52
 
47
- def ir_photoreflector_value
48
- world.board.get_ir_photoreflector_value(0).to_i
53
+ def left_ir_photoreflector_value
54
+ world.board.get_ir_photoreflector_value(PORT_A4).to_i
55
+ end
56
+
57
+ def right_ir_photoreflector_value
58
+ world.board.get_ir_photoreflector_value(PORT_A5).to_i
59
+ end
60
+
61
+ def turn_on_white_led
62
+ world.board.led(PORT_A1, ON)
63
+ end
64
+
65
+ def turn_off_white_led
66
+ world.board.led(PORT_A1, OFF)
67
+ end
68
+
69
+ def turn_on_blue_led
70
+ world.board.led(PORT_A0, ON)
71
+ end
72
+
73
+ def turn_off_blue_led
74
+ world.board.led(PORT_A0, OFF)
49
75
  end
50
76
 
51
77
  private
@@ -53,23 +79,23 @@ module Smalruby
53
79
  def run(direction, sec: nil)
54
80
  case direction
55
81
  when :forward
56
- world.board.dc_motor_power(PORT_M1, 255)
57
- world.board.dc_motor_power(PORT_M2, 255)
82
+ world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
83
+ world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
58
84
  world.board.dc_motor_control(PORT_M1, NORMAL)
59
85
  world.board.dc_motor_control(PORT_M2, NORMAL)
60
86
  when :backward
61
- world.board.dc_motor_power(PORT_M1, 255)
62
- world.board.dc_motor_power(PORT_M2, 255)
87
+ world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
88
+ world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
63
89
  world.board.dc_motor_control(PORT_M1, REVERSE)
64
90
  world.board.dc_motor_control(PORT_M2, REVERSE)
65
91
  when :turn_left
66
- world.board.dc_motor_power(PORT_M1, 255)
67
- world.board.dc_motor_power(PORT_M2, 255)
92
+ world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
93
+ world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
68
94
  world.board.dc_motor_control(PORT_M1, REVERSE)
69
95
  world.board.dc_motor_control(PORT_M2, NORMAL)
70
96
  when :turn_right
71
- world.board.dc_motor_power(PORT_M1, 255)
72
- world.board.dc_motor_power(PORT_M2, 255)
97
+ world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
98
+ world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
73
99
  world.board.dc_motor_control(PORT_M1, NORMAL)
74
100
  world.board.dc_motor_control(PORT_M2, REVERSE)
75
101
  when :stop
@@ -85,8 +111,8 @@ module Smalruby
85
111
  end
86
112
 
87
113
  def _stop
88
- world.board.dc_motor_power(PORT_M1, 255)
89
- world.board.dc_motor_power(PORT_M2, 255)
114
+ world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
115
+ world.board.dc_motor_power(PORT_M2, DC_MOTOR_PACE)
90
116
  world.board.dc_motor_control(PORT_M1, COAST)
91
117
  world.board.dc_motor_control(PORT_M2, COAST)
92
118
  end
@@ -21,7 +21,7 @@ module Smalruby
21
21
  autoload :Sensor
22
22
 
23
23
  autoload :SmalrubotV3
24
- autoload :Studuino
24
+ autoload :SmalrubotS1
25
25
 
26
26
  module_function
27
27
 
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ DESCRIPTION = <<EOS
4
+ Smalrubot on Studuino v1を操作します
5
+ EOS
6
+
7
+ require 'smalruby'
8
+
9
+ init_hardware
10
+
11
+ stage1 = Stage.new(color: 'white')
12
+
13
+ stage1.on(:start) do
14
+ fill(color: 'white')
15
+ draw_font(string: DESCRIPTION, color: 'black')
16
+
17
+ stage1.smalrubot_s1
18
+
19
+ loop do
20
+ if Input.key_down?(K_UP)
21
+ fill(color: 'white')
22
+ draw_font(string: '進む', color: 'black')
23
+
24
+ smalrubot_s1.forward
25
+
26
+ await until !Input.key_down?(K_UP)
27
+
28
+ fill(color: 'white')
29
+
30
+ smalrubot_s1.stop
31
+ end
32
+
33
+ if Input.key_down?(K_DOWN)
34
+ fill(color: 'white')
35
+ draw_font(string: 'バックする', color: 'black')
36
+
37
+ smalrubot_s1.backward
38
+
39
+ await until !Input.key_down?(K_DOWN)
40
+
41
+ fill(color: 'white')
42
+
43
+ smalrubot_s1.stop
44
+ end
45
+
46
+ if Input.key_down?(K_LEFT)
47
+ fill(color: 'white')
48
+ draw_font(string: '左に旋回する', color: 'black')
49
+
50
+ smalrubot_s1.turn_left
51
+
52
+ await until !Input.key_down?(K_LEFT)
53
+
54
+ fill(color: 'white')
55
+
56
+ smalrubot_s1.stop
57
+ end
58
+
59
+ if Input.key_down?(K_RIGHT)
60
+ fill(color: 'white')
61
+ draw_font(string: '右に旋回する', color: 'black')
62
+
63
+ smalrubot_s1.turn_right
64
+
65
+ await until !Input.key_down?(K_RIGHT)
66
+
67
+ fill(color: 'white')
68
+
69
+ smalrubot_s1.stop
70
+ end
71
+
72
+ if Input.key_down?(K_S)
73
+ until !Input.key_down?(K_S)
74
+ fill(color: 'white')
75
+ draw_font(string: "ライントレーサーの情報: 左(#{smalrubot_s1.left_ir_photoreflector_value}) 右(#{smalrubot_s1.right_ir_photoreflector_value})",
76
+ color: 'black')
77
+ await
78
+ end
79
+
80
+ fill(color: 'white')
81
+ end
82
+
83
+ if Input.key_down?(K_W)
84
+ fill(color: 'white')
85
+ draw_font(string: '白色LEDを光らせる', color: 'black')
86
+
87
+ smalrubot_s1.turn_on_white_led
88
+
89
+ await until !Input.key_down?(K_W)
90
+
91
+ fill(color: 'white')
92
+
93
+ smalrubot_s1.turn_off_white_led
94
+ end
95
+
96
+ if Input.key_down?(K_B)
97
+ fill(color: 'white')
98
+ draw_font(string: '青色LEDを光らせる', color: 'black')
99
+
100
+ smalrubot_s1.turn_on_blue_led
101
+
102
+ await until !Input.key_down?(K_B)
103
+
104
+ fill(color: 'white')
105
+
106
+ smalrubot_s1.turn_off_blue_led
107
+ end
108
+ end
109
+ end
110
+
111
+ stage1.on(:key_push, K_A) do
112
+ loop do
113
+ fill(color: 'white')
114
+ draw_font(string: '自動運転', color: 'black')
115
+
116
+ smalrubot_s1.forward
117
+
118
+ loop do
119
+ if smalrubot_s1.left_ir_photoreflector_value < 300 && smalrubot_s1.right_ir_photoreflector_value < 300
120
+ fill(color: 'white')
121
+ draw_font(string: '前方障害物発見!', color: 'black')
122
+
123
+ smalrubot_s1.backward
124
+ sleep(0.25)
125
+ if rand(2) == 1
126
+ smalrubot_s1.turn_left
127
+ sleep(0.1)
128
+ else
129
+ smalrubot_s1.turn_right
130
+ sleep(0.1)
131
+ end
132
+ break
133
+ end
134
+
135
+ if smalrubot_s1.left_ir_photoreflector_value < 300
136
+ fill(color: 'white')
137
+ draw_font(string: '左側障害物発見!', color: 'black')
138
+
139
+ smalrubot_s1.backward
140
+ sleep(0.25)
141
+ smalrubot_s1.turn_right
142
+ sleep(0.1)
143
+ break
144
+ end
145
+
146
+ if smalrubot_s1.right_ir_photoreflector_value < 300
147
+ fill(color: 'white')
148
+ draw_font(string: '右側障害物発見!', color: 'black')
149
+
150
+ smalrubot_s1.backward
151
+ sleep(0.25)
152
+ smalrubot_s1.turn_left
153
+ sleep(0.1)
154
+ break
155
+ end
156
+
157
+ if Input.key_down?(K_Y)
158
+ fill(color: 'white')
159
+ break
160
+ end
161
+ end
162
+ smalrubot_s1.stop
163
+ sleep(0.1)
164
+
165
+ if Input.key_down?(K_Y)
166
+ fill(color: 'white')
167
+ break
168
+ end
169
+ end
170
+ end
data/smalruby.gemspec CHANGED
@@ -42,5 +42,5 @@ Gem::Specification.new do |spec|
42
42
  else
43
43
  spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.12'
44
44
  end
45
- spec.add_runtime_dependency 'smalrubot', '~> 0.0.3'
45
+ spec.add_runtime_dependency 'smalrubot', '~> 0.0.4'
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.2
4
+ version: 0.1.3
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-01-27 00:00:00.000000000 Z
11
+ date: 2015-01-28 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.3
201
+ version: 0.0.4
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.3
208
+ version: 0.0.4
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:
@@ -265,8 +265,8 @@ files:
265
265
  - lib/smalruby/hardware/rgb_led_cathode.rb
266
266
  - lib/smalruby/hardware/sensor.rb
267
267
  - lib/smalruby/hardware/servo.rb
268
+ - lib/smalruby/hardware/smalrubot_s1.rb
268
269
  - lib/smalruby/hardware/smalrubot_v3.rb
269
- - lib/smalruby/hardware/studuino.rb
270
270
  - lib/smalruby/hardware/two_wheel_drive_car.rb
271
271
  - lib/smalruby/stage.rb
272
272
  - lib/smalruby/util.rb
@@ -278,8 +278,8 @@ files:
278
278
  - samples/car.rb
279
279
  - samples/cat.rb
280
280
  - samples/check_hardware_motor_driver.rb
281
+ - samples/check_hardware_smalrubot_s1.rb
281
282
  - samples/check_hardware_smalrubot_v3.rb
282
- - samples/check_hardware_studuino.rb
283
283
  - samples/console.rb
284
284
  - samples/costume.rb
285
285
  - samples/costumes.rb
@@ -1,121 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- DESCRIPTION = <<EOS
4
- Studuinoを操作します
5
- EOS
6
-
7
- require 'smalruby'
8
-
9
- init_hardware
10
-
11
- stage1 = Stage.new(color: 'white')
12
-
13
- stage1.on(:start) do
14
- fill(color: 'white')
15
- draw_font(string: DESCRIPTION, color: 'black')
16
-
17
- stage1.studuino
18
-
19
- loop do
20
- if Input.key_down?(K_UP)
21
- fill(color: 'white')
22
- draw_font(string: '進む', color: 'black')
23
-
24
- studuino.forward
25
-
26
- await until !Input.key_down?(K_UP)
27
-
28
- fill(color: 'white')
29
-
30
- studuino.stop
31
- end
32
-
33
- if Input.key_down?(K_DOWN)
34
- fill(color: 'white')
35
- draw_font(string: 'バックする', color: 'black')
36
-
37
- studuino.backward
38
-
39
- await until !Input.key_down?(K_DOWN)
40
-
41
- fill(color: 'white')
42
-
43
- studuino.stop
44
- end
45
-
46
- if Input.key_down?(K_LEFT)
47
- fill(color: 'white')
48
- draw_font(string: '左に旋回する', color: 'black')
49
-
50
- studuino.turn_left
51
-
52
- await until !Input.key_down?(K_LEFT)
53
-
54
- fill(color: 'white')
55
-
56
- studuino.stop
57
- end
58
-
59
- if Input.key_down?(K_RIGHT)
60
- fill(color: 'white')
61
- draw_font(string: '右に旋回する', color: 'black')
62
-
63
- studuino.turn_right
64
-
65
- await until !Input.key_down?(K_RIGHT)
66
-
67
- fill(color: 'white')
68
-
69
- studuino.stop
70
- end
71
-
72
- if Input.key_down?(K_B)
73
- until !Input.key_down?(K_B)
74
- fill(color: 'white')
75
- draw_font(string: "ライントレーサーの情報: #{studuino.ir_photoreflector_value}",
76
- color: 'black')
77
- await
78
- end
79
- fill(color: 'white')
80
- end
81
- end
82
- end
83
-
84
- stage1.on(:key_push, K_A) do
85
- loop do
86
- fill(color: 'white')
87
- draw_font(string: '自動運転', color: 'black')
88
-
89
- studuino.forward
90
-
91
- loop do
92
- if studuino.ir_photoreflector_value < 500
93
- fill(color: 'white')
94
- draw_font(string: '前方障害物発見!', color: 'black')
95
-
96
- studuino.backward
97
- sleep(0.25)
98
- if rand(2) == 1
99
- studuino.turn_left
100
- sleep(0.1)
101
- else
102
- studuino.turn_left
103
- sleep(0.1)
104
- end
105
- break
106
- end
107
-
108
- if Input.key_down?(K_Y)
109
- fill(color: 'white')
110
- break
111
- end
112
- end
113
- studuino.stop
114
- sleep(0.1)
115
-
116
- if Input.key_down?(K_Y)
117
- fill(color: 'white')
118
- break
119
- end
120
- end
121
- end