Class Rubotz::MotorGenerator
In: lib/rubotz/motor_generator.rb
Parent: Object

The MotorGenerator initializes with an options hash instead of a block. For example:

  motor :synchronized => true,
        :direction => :reverse,
        :ports => [:B, :C],
        :power => 25,
        :turn => 0

The NXC API has a number of different options for motors. This seemed like the best way to implement them, but currently MotorGenerator implements only a subset of available motor functionality, and if/when that functionality expands, the structure of the class may change.

Currently MotorGenerators can only generate Sync commands, and only know how to power ports B and C.

The methods in this class are basically irrelevant from a user perspective. What matters is the keywords you use, or more precisely the symbol keys to the options hash. First the lame stuff: :synchronized makes no difference at all, and the only legal values for :ports is [:B, :C], and you have to specify that. Sorry.

However, :direction, :power, and :turn are all actually valid and usable. They‘re all also reasonably obvious. :direction is either :reverse or :forwards. I‘m pretty sure :power maxes out at 100, and I know it starts at 0. :turn also starts at 0 but honestly I have no idea what its legal maximum is, if any. Feel free to experiment with this!

Methods

Public Class methods

Public Instance methods

[Validate]