Class Motor
In: lib/motor.rb
Parent: Brick

Controls an NXT motor.


  m ='a')
  m.forward(:degrees => 180, :power => 50)


backward   forward   name   new   read_state   reset_tacho   run   stop  




ratio  [RW] 

Public Class methods

Public Instance methods

Rotate the motor backwards. See Motor#forward and Motor#run.

Rotate the motor forwards. See Motor#run. Examples:

  m.forward(:degrees => 360, :power => 20)

The above rotates the motor 360 degrees forward at 20% power.

  m.forward(:time => 5)

The above rotates the motor forwards for 5 seconds at 25% power (because 25% is the default).

Return the current state of the motor as a hash. See NXTComm#get_output_state for info on what data is available here.

Resets the motor’s tachometer movement count (i.e. +:degree_count+ in Motor#state).

Low-level command for initiating motor rotation. Options is a hash with the following keys:

Power from 0 to 100. Default is 25.
Maximum time to run the motor in seconds. By default there is no time limit. If :degrees is also specified then the motor will only turn as far as :degrees and will stop and wait out the remaining :time has expired.
False to disable power regulation. It is true (i.e. on)
          by default.
The maximum tachometer degrees to turn before automatically
          stopping. Use negative values for backward movement (need to
          double check that this is in fact true)
Direction in which the motor should move. 1 for forward,
          -1 for backward. The default is 1 (i.e. forward).
If true, the motor will block further commands
           until this command is complete. This is true by default when
           :degrees or :time is specified, false by default otherwise.
           NOTE: currently this setting is always on and cannot be turned off
           when :time is specified... this will probably be fixed in the future
If true, the motor will try to hard brake when the
                 command completes (otherwise when the command finishes the
                 motor may continue to coast for a while -- especially at higher
                 power levels). This is true by default when :degrees or :time
                 is specified, false by default otherwise.


Rotate backward up to 90 degrees: => 90, :direction => -1)

Rotate forward for 8 seconds at 100% power: => 8, :power => 100)

Forward for 3 seconds up to 180 degrees at 50% power. If the 180 degree rotation takes only 1 second to complete, the motor will sit there and wait out the full 3 seconds anyway: => 50, :degrees => 180, :time => 3)

Rotate forward indefinitely (until Motor#stop is called).

Stop movement.