Class: Phidgets::MotorControl::MotorControlMotors

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

Overview

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

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetMotorControl

Instance Method Summary collapse

Instance Method Details

#accelerationFloat

Returns the acceleration of a motor, or raises an error.

Returns:

  • (Float)

    returns the acceleration of a motor, or raises an error.



232
233
234
235
236
# File 'lib/phidgets-ffi/motor_control.rb', line 232

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 motor, or raises an error.

Parameters:

  • new_acceleration (Integer)

    new acceleration

Returns:

  • (Float)

    returns acceleration of a motor, or raises an error.



241
242
243
244
# File 'lib/phidgets-ffi/motor_control.rb', line 241

def acceleration=(new_acceleration)
  Klass.setAcceleration(@handle, @index, new_acceleration.to_f)
	  new_acceleration
end

#acceleration_maxFloat

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

Returns:

  • (Float)

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



247
248
249
250
251
# File 'lib/phidgets-ffi/motor_control.rb', line 247

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 motor will accept, or raises an error.

Returns:

  • (Float)

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



254
255
256
257
258
# File 'lib/phidgets-ffi/motor_control.rb', line 254

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

#back_emfFloat

Returns the back EMF value of a motor, in volts, or raises an error.

Returns:

  • (Float)

    returns the back EMF value of a motor, in volts, or raises an error.



284
285
286
287
288
# File 'lib/phidgets-ffi/motor_control.rb', line 284

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

#back_emf_sensingBoolean

Returns the back EMF sensing state of a motor, or raises an error.

Returns:

  • (Boolean)

    returns the back EMF sensing state of a motor, or raises an error.



277
278
279
280
281
# File 'lib/phidgets-ffi/motor_control.rb', line 277

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

#back_emf_sensing=(new_back_emf_sensing) ⇒ Boolean

Sets the back EMF sensing state of a motor, or raises an error.

Parameters:

  • new_back_emf_sensing (Boolean)

    new back EMf sensing state

Returns:

  • (Boolean)

    sets the back EMF sensing state of a motor, or raises an error.



270
271
272
273
274
# File 'lib/phidgets-ffi/motor_control.rb', line 270

def back_emf_sensing=(new_back_emf_sensing)
  tmp = new_back_emf_sensing ? 1 : 0
  Klass.setBackEMFSensingState(@handle, @index, tmp)
  new_back_emf_sensing
end

#brakingFloat

Returns the braking value of a motor, or raises an error.

Returns:

  • (Float)

    returns the braking value of a motor, or raises an error.



306
307
308
309
310
# File 'lib/phidgets-ffi/motor_control.rb', line 306

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

#braking=(new_braking) ⇒ Float

Sets the braking value of a motor, or raises an error. The value can be between 0-100%

Parameters:

  • new_braking (Integer)

    new braking

Returns:

  • (Float)

    returns the braking value of a motor, or raises an error.



315
316
317
318
# File 'lib/phidgets-ffi/motor_control.rb', line 315

def braking=(new_braking)
  Klass.setBraking(@handle, @index, new_braking.to_f)
	  new_braking
end

#currentFloat

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

Returns:

  • (Float)

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



261
262
263
264
265
# File 'lib/phidgets-ffi/motor_control.rb', line 261

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

#indexInteger

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

Returns:

  • (Integer)

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



227
228
229
# File 'lib/phidgets-ffi/motor_control.rb', line 227

def index 
	@index
end

#inspectObject

Displays data for the motor.



222
223
224
# File 'lib/phidgets-ffi/motor_control.rb', line 222

def inspect
     "#<#{self.class} @index=#{index}, @acceleration=#{acceleration}, @acceleration_min=#{acceleration_min}, @acceleration_max=#{acceleration_max}, @velocity=#{velocity}>"
end

#velocityFloat

Returns the velocity of a motor, or raises an error.

Returns:

  • (Float)

    returns the velocity of a motor, or raises an error.



291
292
293
294
295
# File 'lib/phidgets-ffi/motor_control.rb', line 291

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

#velocity=(new_velocity) ⇒ Float

Sets the velocity of a motor, or raises an error.

Parameters:

  • new_velocity (Integer)

    new velocity

Returns:

  • (Float)

    returns the velocity of a motor, or raises an error.



300
301
302
303
# File 'lib/phidgets-ffi/motor_control.rb', line 300

def velocity=(new_velocity)
  Klass.setVelocity(@handle, @index, new_velocity.to_f)
	  new_velocity
end