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

Controls an NXT motor.

Example:

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

Methods

backward   forward   name   new   read_state   reset_tacho   run   stop  

Constants

POLL_INTERVAL = 0.5

Attributes

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+
Power from 0 to 100. Default is 25.
+:time+
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.
+:regulate+
False to disable power regulation. It is true (i.e. on)
          by default.
+:degrees+
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+
Direction in which the motor should move. 1 for forward,
          -1 for backward. The default is 1 (i.e. forward).
+:wait_until_complete+
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
+:brake_on_stop+
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.

Examples:

Rotate backward up to 90 degrees:

  m.run(:degrees => 90, :direction => -1)

Rotate forward for 8 seconds at 100% power:

  m.run(:time => 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:

  m.run(:power => 50, :degrees => 180, :time => 3)

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

  m.run

Stop movement.

[Validate]