Class: BrickPi::Bot
- Inherits:
-
Object
- Object
- BrickPi::Bot
- Includes:
- Configuration
- Defined in:
- lib/brick_pi/bot.rb
Instance Attribute Summary collapse
-
#motor_A ⇒ Object
Returns the value of attribute motor_A.
-
#motor_B ⇒ Object
Returns the value of attribute motor_B.
-
#motor_C ⇒ Object
Returns the value of attribute motor_C.
-
#motor_D ⇒ Object
Returns the value of attribute motor_D.
-
#sensor_1 ⇒ Object
Returns the value of attribute sensor_1.
-
#sensor_2 ⇒ Object
Returns the value of attribute sensor_2.
-
#sensor_3 ⇒ Object
Returns the value of attribute sensor_3.
-
#sensor_4 ⇒ Object
Returns the value of attribute sensor_4.
Instance Method Summary collapse
-
#initialize ⇒ Bot
constructor
A new instance of Bot.
- #schedule(&block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Configuration
#color_sensor, #configure, #motor, #sensor, #touch_sensor, #ultrasonic_sensor
Constructor Details
Instance Attribute Details
#motor_A ⇒ Object
Returns the value of attribute motor_A.
9 10 11 |
# File 'lib/brick_pi/bot.rb', line 9 def motor_A @motor_A end |
#motor_B ⇒ Object
Returns the value of attribute motor_B.
9 10 11 |
# File 'lib/brick_pi/bot.rb', line 9 def motor_B @motor_B end |
#motor_C ⇒ Object
Returns the value of attribute motor_C.
9 10 11 |
# File 'lib/brick_pi/bot.rb', line 9 def motor_C @motor_C end |
#motor_D ⇒ Object
Returns the value of attribute motor_D.
9 10 11 |
# File 'lib/brick_pi/bot.rb', line 9 def motor_D @motor_D end |
#sensor_1 ⇒ Object
Returns the value of attribute sensor_1.
10 11 12 |
# File 'lib/brick_pi/bot.rb', line 10 def sensor_1 @sensor_1 end |
#sensor_2 ⇒ Object
Returns the value of attribute sensor_2.
10 11 12 |
# File 'lib/brick_pi/bot.rb', line 10 def sensor_2 @sensor_2 end |
#sensor_3 ⇒ Object
Returns the value of attribute sensor_3.
10 11 12 |
# File 'lib/brick_pi/bot.rb', line 10 def sensor_3 @sensor_3 end |
#sensor_4 ⇒ Object
Returns the value of attribute sensor_4.
10 11 12 |
# File 'lib/brick_pi/bot.rb', line 10 def sensor_4 @sensor_4 end |
Instance Method Details
#schedule(&block) ⇒ Object
53 54 55 |
# File 'lib/brick_pi/bot.rb', line 53 def schedule(&block) @queue.push block end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/brick_pi/bot.rb', line 19 def start @stop = false Native.ClearTick() Native.Timeout = 50 Native.BrickPiSetTimeout() Thread.new do until @stop do Native.BrickPiUpdateValues() sleep 50/1000 end end Thread.new do until @stop do code = @queue.pop begin code.call rescue => e $stderr.puts e. $stderr.puts e.backtrace.join("\n") end end end Thread.new do yield end.join stop end |
#stop ⇒ Object
47 48 49 50 51 |
# File 'lib/brick_pi/bot.rb', line 47 def stop schedule do @stop = true end end |