class NXT::Connector::Output::Motor
Implements the “motor” output for the NXT
2.0 module.
Constants
- DIRECTION
- DURATION_AFTER
- DURATION_TYPE
Attributes
interface[RW]
port[RW]
Public Class Methods
new(port, interface)
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 26 def initialize(port, interface) @port = port @interface = interface end
Public Instance Methods
backwards()
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 52 def backwards self.direction = :backwards self end
duration=(duration, options = {})
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 31 def duration=(duration, options = {}) raise(TypeError, 'Expected duration to be a number') unless duration.is_a?(Integer) @duration = duration self.duration_type = options[:type] self.duration_after = options[:after] case @duration_type when :rotations self.tacho_limit = @duration * 360 when :degrees self.tacho_limit = @duration end end
forwards()
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 47 def forwards self.direction = :forwards self end
move()
click to toggle source
takes block for response, or can return the response instead.
# File lib/nxt/connector/output/motor.rb, line 65 def move update_output_state(duration.positive? && duration_type != :seconds) if duration.positive? && duration_type == :seconds wait_after_move else reset end end
reset()
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 75 def reset self.duration = 0 self.direction = :forwards self.power = 75 self.mode = :motor_on self.regulation_mode = :idle self.run_state = :running self.tacho_limit = 0 end
stop(mode = :coast)
click to toggle source
# File lib/nxt/connector/output/motor.rb, line 57 def stop(mode = :coast) self.power = 0 self.mode = mode move end