class Robolove::Bot
Constants
- DEFAULTS
Attributes
brick[R]
left_motor[R]
right_motor[R]
speed[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/robolove/bot.rb, line 13 def initialize(options = {}) options = DEFAULTS.merge options @brick = options[:brick] || LegoNXT::LowLevel.connect @left_motor = options[:left_motor] || DEFAULTS[:left_motor] @right_motor = options[:right_motor] || DEFAULTS[:right_motor] @speed = options[:speed] || DEFAULTS[:speed] end
Public Instance Methods
backward(duration = 1)
click to toggle source
# File lib/robolove/bot.rb, line 30 def backward(duration = 1) self.brick.run_motor(self.left_motor, -self.speed) self.brick.run_motor(self.right_motor, -self.speed) sleep duration self.brick.stop_motor(self.left_motor) self.brick.stop_motor(self.right_motor) end
forward(duration = 1)
click to toggle source
# File lib/robolove/bot.rb, line 22 def forward(duration = 1) self.brick.run_motor(self.left_motor, self.speed) self.brick.run_motor(self.right_motor, self.speed) sleep duration self.brick.stop_motor(self.left_motor) self.brick.stop_motor(self.right_motor) end
left(duration = 0.5)
click to toggle source
# File lib/robolove/bot.rb, line 46 def left(duration = 0.5) self.brick.run_motor(self.right_motor, self.speed) self.brick.run_motor(self.left_motor, -self.speed) sleep duration self.brick.stop_motor(self.right_motor) self.brick.stop_motor(self.left_motor) end
right(duration = 0.5)
click to toggle source
# File lib/robolove/bot.rb, line 38 def right(duration = 0.5) self.brick.run_motor(self.left_motor, self.speed) self.brick.run_motor(self.right_motor, -self.speed) sleep duration self.brick.stop_motor(self.left_motor) self.brick.stop_motor(self.right_motor) end