smalruby 0.1.3 → 0.1.4

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: 1ee7bfa97bf4f6b1e8691e86af1d9617b52e3279
4
- data.tar.gz: e186289f5699b0aead9dcb2829251c3b850bb47e
3
+ metadata.gz: 2183b4f4a9939796027d8e12cb2432baa9c293ab
4
+ data.tar.gz: a6092b282cdbc1acbbe5cb8f80f4e6ee68300ac7
5
5
  SHA512:
6
- metadata.gz: 4132f6b082f968a59d4bc81f963fb96ccba1b798e7671632734cf556daf2c9f42b810fe96af832df926e4a230df2a0bf7fbea03d38a8eee85332d70759049d41
7
- data.tar.gz: 9f5108758dad9fc3ec58bf845403389a94408d322a73bcb30e3f0681263bdad40c42fdef5d409dd13a5914696149be87ee9de6bf5a727c6b32d8fd469cb8b0a0
6
+ metadata.gz: df8e9248b7f7c0458a18d48728bb241448173c9db683cf84681ad1381084c27768f5c1c7ed611f756db16668a996f15c795307705b263b9ba55eebe90224426b
7
+ data.tar.gz: b484ca9b742a2e93119bb3a54eb99ed548983c50489317fb37a7e2a263c62225ac680dcbbf4d1f2a76ca2abc6aaddcbe4202252321accc8b4ea48ba8732baf94
@@ -7,7 +7,8 @@ module Smalruby
7
7
  class SmalrubotS1
8
8
  include Smalrubot::Board::Studuino
9
9
 
10
- DC_MOTOR_PACE = (255 * 0.50).round
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
- world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
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
- world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
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
- world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
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
- world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
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
- world.board.dc_motor_power(PORT_M1, DC_MOTOR_PACE)
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
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -14,7 +14,8 @@ stage1.on(:start) do
14
14
  fill(color: 'white')
15
15
  draw_font(string: DESCRIPTION, color: 'black')
16
16
 
17
- stage1.smalrubot_s1
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
@@ -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.4'
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-28 00:00:00.000000000 Z
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.4
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.4
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: