Class: Phidgets::AdvancedServo::AdvancedServoServos

Inherits:
Object
  • Object
show all
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

Instance Method Details

#accelerationFloat

Returns the acceleration of a servo, in degrees/second, or raises an error.

Returns:

  • (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.

Parameters:

  • new_acceleration (Integer)

    new acceleration

Returns:

  • (Float)

    returns 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_maxFloat

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

Returns:

  • (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_minFloat

Returns the smallest acceleration value that the servo motor will accept, or raises an error.

Returns:

  • (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

#currentFloat

Returns the current consumption of a servo motor, in Amps, or raises an error.

Returns:

  • (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

#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.



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.

Parameters:

  • new_state (Boolean)

    new state

Returns:

  • (Boolean)

    returns 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

#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.



96
97
98
# File 'lib/phidgets-ffi/advanced_servo.rb', line 96

def index 
	@index
end

#inspectObject

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

#positionFloat

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

Returns:

  • (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.

Parameters:

  • new_position (Float)

    new position

Returns:

  • (Float)

    returns 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_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.



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.

Parameters:

  • new_position_max (Float)

    new maximum position

Returns:

  • (Float)

    returns 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_minFloat

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

Returns:

  • (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.

Parameters:

  • new_position_min (Float)

    new minimum position

Returns:

  • (Float)

    returns 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.

Returns:

  • (Boolean)

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



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_rampingBoolean

Returns the speed ramping state of the servo motor, or raises an error.

Returns:

  • (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.

Parameters:

  • new_state (Boolean)

    new state

Returns:

  • (Boolean)

    returns 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

#stoppedBoolean

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

Returns:

  • (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

#typePhidgets::FFI::AdvancedServoType

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

Returns:



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.

Parameters:

Returns:



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

#velocityFloat

Returns the current velocity of the servo motor, or raises an error.

Returns:

  • (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_limitFloat

Returns the velocity limit of the servo motor, or raises an error.

Returns:

  • (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.

Parameters:

  • new_velocity_limit (Float)

    new velocity limit

Returns:

  • (Float)

    returns 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_maxFloat

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

Returns:

  • (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_minFloat

Returns the smallest velocity value that the servo motor will accept, or raises an error.

Returns:

  • (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