module Rumba::Dsl

Constants

DEFAULT_SPEED

Remember, Roomba speeds are defined in mm/s (max is 200)

RADIUS

Radius of an average Roomba, used for calculating rotation

Public Instance Methods

backward(distance, speed: DEFAULT_SPEED) click to toggle source

distance is in mm!

# File lib/rumba/dsl.rb, line 31
def backward(distance, speed: DEFAULT_SPEED)
  straight_distance(distance, speed: -speed)
end
Also aliased as: backwards
backwards(distance, speed: DEFAULT_SPEED)
Alias for: backward
forward(distance, speed: DEFAULT_SPEED) click to toggle source

distance is in mm!

# File lib/rumba/dsl.rb, line 26
def forward(distance, speed: DEFAULT_SPEED)
  straight_distance(distance, speed: speed)
end
Also aliased as: forwards
forwards(distance, speed: DEFAULT_SPEED)

eh, why not?

Alias for: forward
rotate(direction, speed: DEFAULT_SPEED) click to toggle source

Direction can either be a Fixnum for number of degrees, or a symbol for the direction (:left, :right)

# File lib/rumba/dsl.rb, line 37
def rotate(direction, speed: DEFAULT_SPEED)
  # handle symbols...
  # note that counter-clockwise is positive
  case direction
    when :left
      direction = 90
    when :right
      direction = -90
  end

  direction > 0 ? spin_right(speed) : spin_left(speed)

  total = 0
  goal  = direction.abs / 2
  loop do
    raw_angle = get_sensor(:angle)

    # taken from the official docs to convert output to degrees...
    degrees = (360 * raw_angle)/(258 * Math::PI)
    total += degrees.abs
    break if total >= goal
  end

  halt
end
Also aliased as: turn
straight_distance(distance, speed: DEFAULT_SPEED) click to toggle source

move both wheels at the same speed in a certain direction! NOTE THAT THIS BLOCKS UNTIL COMPLETE

# File lib/rumba/dsl.rb, line 14
def straight_distance(distance, speed: DEFAULT_SPEED)
  total = 0
  straight(speed)
  loop do
    total += get_sensor(:distance).abs
    break if total >= distance
  end

  halt
end
turn(direction, speed: DEFAULT_SPEED)
Alias for: rotate