Class: Phidgets::AdvancedServo::AdvancedServoServos
- Inherits:
-
Object
- Object
- Phidgets::AdvancedServo::AdvancedServoServos
- Defined in:
- lib/phidgets-ffi/advanced_servo.rb
Overview
This class represents a servo motor for a PhidgetAdvancedServo. All the properties of an servo motor are stored and modified in this class.
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetAdvancedServo
Instance Method Summary collapse
-
#acceleration ⇒ Float
Returns the acceleration of a servo, in degrees/second, or raises an error.
-
#acceleration=(new_acceleration) ⇒ Float
Sets the acceleration of a servo, in degrees/second, or raises an error.
-
#acceleration_max ⇒ Float
Returns the largest acceleration value that the servo motor will accept, or raises an error.
-
#acceleration_min ⇒ Float
Returns the smallest acceleration value that the servo motor will accept, or raises an error.
-
#current ⇒ Float
Returns the current consumption of a servo motor, in Amps, or raises an error.
-
#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, in degrees, or raises an error.
-
#position=(new_position) ⇒ Float
Sets the position of the servo motor, in degrees, or raises an error.
-
#position_max ⇒ Float
Returns the largest position value that the servo motor will accept, or raises an error.
-
#position_max=(new_position_max) ⇒ Float
Sets the largest position value that the servo motor will accept, or raises an error.
-
#position_min ⇒ Float
Returns the smallest position value that the servo motor will accept, or raises an error.
-
#position_min=(new_position_min) ⇒ Float
Sets the smallest position value that the servo motor will accept, or raises an error.
-
#set_servo_parameters(min_us, max_us, degrees, velocity_max) ⇒ Boolean
Sets custom servo parameters for using a servo not in the predefined list.
-
#speed_ramping ⇒ Boolean
Returns the speed ramping state of the servo motor, or raises an error.
-
#speed_ramping=(new_state) ⇒ Boolean
Sets the speed ramping state that the servo motor will accept, or raises an error.
-
#stopped ⇒ Boolean
Returns the stopped state of the servo motor, or raises an error.
-
#type ⇒ Phidgets::FFI::AdvancedServoType
Returns the servo type of the servo motor, or raises an error.
-
#type=(new_type = :default) ⇒ Phidgets::FFI::AdvancedServoType
Sets the servo type of the servo motor, or raises an error.
-
#velocity ⇒ Float
Returns the current velocity of the servo motor, or raises an error.
-
#velocity_limit ⇒ Float
Returns the velocity limit of the servo motor, or raises an error.
-
#velocity_limit=(new_velocity_limit) ⇒ Float
Sets the velocity limit of the servo motor, or raises an error.
-
#velocity_max ⇒ Float
Returns the largest velocity value that the servo motor will accept, or raises an error.
-
#velocity_min ⇒ Float
Returns the smallest velocity value that the servo motor will accept, or raises an error.
Instance Method Details
#acceleration ⇒ Float
Returns the acceleration of a servo, in degrees/second, or raises an error.
101 102 103 104 105 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 101 def acceleration ptr = ::FFI::MemoryPointer.new(:double) Klass.getAcceleration(@handle, @index, ptr) ptr.get_double(0) end |
#acceleration=(new_acceleration) ⇒ Float
Sets the acceleration of a servo, in degrees/second, or raises an error.
110 111 112 113 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 110 def acceleration=(new_acceleration) Klass.setAcceleration(@handle, @index, new_acceleration.to_f) new_acceleration end |
#acceleration_max ⇒ Float
Returns the largest acceleration value that the servo motor will accept, or raises an error.
116 117 118 119 120 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 116 def acceleration_max ptr = ::FFI::MemoryPointer.new(:double) Klass.getAccelerationMax(@handle, @index, ptr) ptr.get_double(0) end |
#acceleration_min ⇒ Float
Returns the smallest acceleration value that the servo motor will accept, or raises an error.
123 124 125 126 127 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 123 def acceleration_min ptr = ::FFI::MemoryPointer.new(:double) Klass.getAccelerationMin(@handle, @index, ptr) ptr.get_double(0) end |
#current ⇒ Float
Returns the current consumption of a servo motor, in Amps, or raises an error.
130 131 132 133 134 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 130 def current ptr = ::FFI::MemoryPointer.new(:double) Klass.getCurrent(@handle, @index, ptr) ptr.get_double(0) end |
#engaged ⇒ Boolean
Returns the engaged state of a servo motor, or raises an error.
137 138 139 140 141 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 137 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.
146 147 148 149 150 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 146 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.
96 97 98 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 96 def index @index end |
#inspect ⇒ Object
Displays data for the servo motor.
91 92 93 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 91 def inspect "#<#{self.class} @index=#{index}, @acceleration=#{acceleration}, @acceleration_min=#{acceleration_min}, @acceleration_max=#{acceleration_max}, @current=#{current}, @engaged=#{engaged}, @position=#{position}, @position_max=#{position_max}, @position_min=#{position_min}, @speed_ramping=#{speed_ramping}, @stopped=#{stopped}, @type=#{type}, @velocity=#{velocity}, @velocity_limit=#{velocity_limit}, @velocity_min=#{velocity_min}, @velocity_max=#{velocity_max}>" end |
#position ⇒ Float
Returns the position of the servo motor, in degrees, or raises an error.
153 154 155 156 157 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 153 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, in degrees, or raises an error.
162 163 164 165 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 162 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.
168 169 170 171 172 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 168 def position_max ptr = ::FFI::MemoryPointer.new(:double) Klass.getPositionMax(@handle, @index, ptr) ptr.get_double(0) end |
#position_max=(new_position_max) ⇒ Float
Sets the largest position value that the servo motor will accept, or raises an error.
177 178 179 180 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 177 def position_max=(new_position_max) Klass.setPositionMax(@handle, @index, new_position_max.to_f) new_position_max end |
#position_min ⇒ Float
Returns the smallest position value that the servo motor will accept, or raises an error.
183 184 185 186 187 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 183 def position_min ptr = ::FFI::MemoryPointer.new(:double) Klass.getPositionMin(@handle, @index, ptr) ptr.get_double(0) end |
#position_min=(new_position_min) ⇒ Float
Sets the smallest position value that the servo motor will accept, or raises an error.
192 193 194 195 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 192 def position_min=(new_position_min) Klass.setPositionMin(@handle, @index, new_position_min.to_f) new_position_min end |
#set_servo_parameters(min_us, max_us, degrees, velocity_max) ⇒ Boolean
Sets custom servo parameters for using a servo not in the predefined list. Pulse widths are specified in microseconds, velocity in degrees/second.
274 275 276 277 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 274 def set_servo_parameters(min_us, max_us, degrees, velocity_max) Klass.setServoParameters(@handle, @index, min_us, max_us, degrees, velocity_max) true end |
#speed_ramping ⇒ Boolean
Returns the speed ramping state of the servo motor, or raises an error.
198 199 200 201 202 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 198 def speed_ramping ptr = ::FFI::MemoryPointer.new(:int) Klass.getSpeedRampingOn(@handle, @index, ptr) (ptr.get_int(0) == 0) ? false : true end |
#speed_ramping=(new_state) ⇒ Boolean
Sets the speed ramping state that the servo motor will accept, or raises an error.
207 208 209 210 211 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 207 def speed_ramping=(new_state) tmp = new_state ? 1 : 0 Klass.setSpeedRampingOn(@handle, @index, tmp) new_state end |
#stopped ⇒ Boolean
Returns the stopped state of the servo motor, or raises an error.
214 215 216 217 218 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 214 def stopped ptr = ::FFI::MemoryPointer.new(:int) Klass.getStopped(@handle, @index, ptr) (ptr.get_int(0) == 0) ? false : true end |
#type ⇒ Phidgets::FFI::AdvancedServoType
Returns the servo type of the servo motor, or raises an error.
221 222 223 224 225 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 221 def type ptr = ::FFI::MemoryPointer.new(:int) Klass.getServoType(@handle, @index, ptr) Phidgets::FFI::ServoType[ptr.get_int(0)] end |
#type=(new_type = :default) ⇒ Phidgets::FFI::AdvancedServoType
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. The default type is :default.
230 231 232 233 234 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 230 def type=(new_type=:default) ptr = ::FFI::MemoryPointer.new(:int) Klass.setServoType(@handle, @index, Phidgets::FFI::AdvancedServoType[new_type]) new_type end |
#velocity ⇒ Float
Returns the current velocity of the servo motor, or raises an error.
237 238 239 240 241 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 237 def velocity ptr = ::FFI::MemoryPointer.new(:double) Klass.getVelocity(@handle, @index, ptr) ptr.get_double(0) end |
#velocity_limit ⇒ Float
Returns the velocity limit of the servo motor, or raises an error.
244 245 246 247 248 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 244 def velocity_limit ptr = ::FFI::MemoryPointer.new(:double) Klass.getVelocityLimit(@handle, @index, ptr) ptr.get_double(0) end |
#velocity_limit=(new_velocity_limit) ⇒ Float
Sets the velocity limit of the servo motor, or raises an error.
253 254 255 256 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 253 def velocity_limit=(new_velocity_limit) Klass.setVelocityLimit(@handle, @index, new_velocity_limit.to_f) new_velocity_limit end |
#velocity_max ⇒ Float
Returns the largest velocity value that the servo motor will accept, or raises an error.
259 260 261 262 263 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 259 def velocity_max ptr = ::FFI::MemoryPointer.new(:double) Klass.getVelocityMax(@handle, @index, ptr) ptr.get_double(0) end |
#velocity_min ⇒ Float
Returns the smallest velocity value that the servo motor will accept, or raises an error.
266 267 268 269 270 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 266 def velocity_min ptr = ::FFI::MemoryPointer.new(:double) Klass.getVelocityMin(@handle, @index, ptr) ptr.get_double(0) end |