Class: Phidgets::Servo::ServoServos

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

Overview

This class represents a servo motor for a PhidgetServo. All the properties of an servo motor are stored and modified in this class.

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetServo

Instance Method Summary collapse

Instance Method Details

#engagedBoolean

Returns the engaged state of a servo motor, or raises an error.

Returns:

  • (Boolean)

    returns the engaged state of a servo motor, or raises an error.



61
62
63
64
65
# File 'lib/phidgets-ffi/servo.rb', line 61

def engaged
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getEngaged(@handle, @index, ptr)
  (ptr.get_int(0) == 0) ? false : true
end

#engaged=(new_state) ⇒ Boolean

Sets the engaged state of a servo motor, or raises an error.

Parameters:

  • new_state (Boolean)

    new state

Returns:

  • (Boolean)

    returns engaged state of a servo motor, or raises an error.



70
71
72
73
74
# File 'lib/phidgets-ffi/servo.rb', line 70

def engaged=(new_state)
  tmp = new_state ? 1 : 0
  Klass.setEngaged(@handle, @index, tmp)
  new_state
end

#indexInteger

Returns the index of the servo motor, or raises an error.

Returns:

  • (Integer)

    returns the index of the servo motor, or raises an error.



56
57
58
# File 'lib/phidgets-ffi/servo.rb', line 56

def index 
	@index
end

#inspectObject

Displays data for the servo motor.



51
52
53
# File 'lib/phidgets-ffi/servo.rb', line 51

def inspect
     "#<#{self.class} @index=#{index}, @engaged=#{engaged}, @position_min=#{position_min}, @position_max=#{position_max}, @type=#{type}>"
end

#positionFloat

Returns the position of the servo motor, or raises an error.

Returns:

  • (Float)

    returns the position of the servo motor, or raises an error.



91
92
93
94
95
# File 'lib/phidgets-ffi/servo.rb', line 91

def position
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getPosition(@handle, @index, ptr)
  ptr.get_double(0)
end

#position=(new_position) ⇒ Float

Sets the position of the servo motor, or raises an error.

Parameters:

  • new_position (Float)

    new position

Returns:

  • (Float)

    returns the position of the servo motor, or raises an error.



100
101
102
103
# File 'lib/phidgets-ffi/servo.rb', line 100

def position=(new_position)
  Klass.setPosition(@handle, @index, new_position.to_f)
  new_position
end

#position_maxFloat

Returns the largest position value that the servo motor will accept, or raises an error.

Returns:

  • (Float)

    returns the largest position value that the servo motor will accept, or raises an error.



84
85
86
87
88
# File 'lib/phidgets-ffi/servo.rb', line 84

def position_max
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getPositionMax(@handle, @index, ptr)
  ptr.get_double(0)
end

#position_minFloat

Returns the largest position value that the servo motor will accept, or raises an error.

Returns:

  • (Float)

    returns the largest position value that the servo motor will accept, or raises an error.



77
78
79
80
81
# File 'lib/phidgets-ffi/servo.rb', line 77

def position_min
  ptr = ::FFI::MemoryPointer.new(:double)
  Klass.getPositionMin(@handle, @index, ptr)
  ptr.get_double(0)
end

#set_servo_parameters(min_pcm, max_pcm, degrees) ⇒ Boolean

Sets custom servo parameters for using a servo not in the predefined list. Pulse widths are specified in microseconds.

Parameters:

  • new_minimum_pulse_width (Float)

    new minimum pulse width

  • new_maximum_pulse_width (Float)

    new maximum pulse width

  • new_degrees (Float)

    new degrees

Returns:

  • (Boolean)

    returns true if the servo parameters are successfully set, or raises an error.



126
127
128
129
# File 'lib/phidgets-ffi/servo.rb', line 126

def set_servo_parameters(min_pcm, max_pcm, degrees)
  Klass.setServoParameters(@handle, @index, min_pcm.to_f, max_pcm.to_f, degrees.to_f)
  true
end

#typePhidgets::FFI::ServoType

Returns the servo type of the servo motor, or raises an error.

Returns:



106
107
108
109
110
# File 'lib/phidgets-ffi/servo.rb', line 106

def type
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getServoType(@handle, @index, ptr)
  Phidgets::FFI::ServoType[ptr.get_int(0)]
end

#type=(servo_type = :default) ⇒ Phidgets::FFI:ServoType

Sets the servo type of the servo motor, or raises an error. This determines how degrees are calculated from PCM pulses, and sets min and max angles.

Parameters:

Returns:

  • (Phidgets::FFI:ServoType)

    returns the servo type of the servo motor, or raises an error.



115
116
117
118
119
# File 'lib/phidgets-ffi/servo.rb', line 115

def type=(servo_type=:default)
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.setServoType(@handle, @index, Phidgets::FFI::ServoType[servo_type])
  servo_type
end