Class: Phidgets::Servo::ServoServos
- Inherits:
-
Object
- Object
- Phidgets::Servo::ServoServos
- 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
-
#engaged ⇒ Boolean
Returns the engaged state of a servo motor, or raises an error.
-
#engaged=(new_state) ⇒ Boolean
Sets the engaged state of a servo motor, or raises an error.
-
#index ⇒ Integer
Returns the index of the servo motor, or raises an error.
-
#inspect ⇒ Object
Displays data for the servo motor.
-
#position ⇒ Float
Returns the position of the servo motor, or raises an error.
-
#position=(new_position) ⇒ Float
Sets the position of the servo motor, or raises an error.
-
#position_max ⇒ Float
Returns the largest position value that the servo motor will accept, or raises an error.
-
#position_min ⇒ Float
Returns the largest position value that the servo motor will accept, or raises an error.
-
#set_servo_parameters(min_pcm, max_pcm, degrees) ⇒ Boolean
Sets custom servo parameters for using a servo not in the predefined list.
-
#type ⇒ Phidgets::FFI::ServoType
Returns the servo type of the servo motor, or raises an error.
-
#type=(servo_type = :default) ⇒ Phidgets::FFI:ServoType
Sets the servo type of the servo motor, or raises an error.
Instance Method Details
#engaged ⇒ 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.
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 |
#index ⇒ 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 |
#inspect ⇒ Object
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 |
#position ⇒ 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.
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_max ⇒ 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_min ⇒ 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.
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 |
#type ⇒ Phidgets::FFI::ServoType
Returns the servo type of the servo motor, or raises an error.
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.
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 |