Class: Phidgets::MotorControl::MotorControlEncoders

Inherits:
Object
  • Object
show all
Defined in:
lib/phidgets-ffi/motor_control.rb

Overview

This class represents an encoder for a PhidgetMotorControl. All the properties of an encoder are stored and modified in this class.

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetMotorControl

Instance Method Summary collapse

Instance Method Details

#indexInteger

Returns index of the digital input, or raises an error.

Returns:

  • (Integer)

    returns index of the digital input, or raises an error.



419
420
421
# File 'lib/phidgets-ffi/motor_control.rb', line 419

def index 
	@index
end

#inspectObject

Displays data for the encoder



414
415
416
# File 'lib/phidgets-ffi/motor_control.rb', line 414

def inspect
  "#<#{self.class} @index=#{index}, @position=#{position}>"
end

#positionInteger

Returns the position of an encoder, or raises an error.

Returns:

  • (Integer)

    returns the position of an encoder, or raises an error.



424
425
426
427
428
# File 'lib/phidgets-ffi/motor_control.rb', line 424

def position
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getEncoderPosition(@handle, @index, ptr)
  ptr.get_int(0)
end

#position=(new_position) ⇒ Integer

Sets the position of an encoder, or raises an error.

Parameters:

  • new_position (Integer)

    new position

Returns:

  • (Integer)

    returns the position of an encoder, or raises an error.



433
434
435
436
# File 'lib/phidgets-ffi/motor_control.rb', line 433

def position=(new_position)
  Klass.setEncoderPosition(@handle, @index, new_position.to_i)
  new_position
end