Class: Phidgets::MotorControl
- Inherits:
-
Object
- Object
- Phidgets::MotorControl
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/motor_control.rb
Overview
This class represents a PhidgetMotorControl.
Defined Under Namespace
Classes: MotorControlAnalogSensors, MotorControlDigitalInputs, MotorControlEncoders, MotorControlMotors
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetMotorControl
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetMotorControl.
-
#encoders ⇒ MotorControlEncoders
readonly
Collection of encoders.
-
#inputs ⇒ MotorControlDigitalInputs
readonly
Collection of digital inputs.
-
#motors ⇒ MotorControlMotors
readonly
Collection of motors.
-
#sensors ⇒ MotorControlAnalogSensors
readonly
Collection of analog sensors.
Instance Method Summary collapse
-
#on_back_emf_update(obj = nil, &block) ⇒ Boolean
Sets a Back EMF update handler callback function.
-
#on_current_change(obj = nil, &block) ⇒ Boolean
Sets a current change handler callback function.
-
#on_current_update(obj = nil, &block) ⇒ Boolean
Sets a current update handler callback function.
-
#on_input_change(obj = nil, &block) ⇒ Boolean
Sets an input change handler callback function.
-
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function.
-
#on_position_update(obj = nil, &block) ⇒ Boolean
Sets a position update handler callback function.
-
#on_sensor_update(obj = nil, &block) ⇒ Boolean
Sets a sensor update handler callback function.
-
#on_velocity_change(obj = nil, &block) ⇒ Boolean
Sets a velocity change handler callback function.
-
#ratiometric ⇒ Boolean
(also: #ratiometric?)
Returns the ratiometric state or raises an error.
-
#ratiometric=(new_state) ⇒ Boolean
Sets the ratiometric state of the board.
Methods included from Common
#attached?, #attached_to_server?, attributes, #close, #detached?, #detached_to_server?, device_class, #device_class, device_id, #id, #initialize, #label, #label=, #name, #on_attach, #on_detach, #on_error, #on_server_connect, #on_server_disconnect, #on_sleep, #on_wake, #serial_number, #server_address, server_address, #server_id, server_id, server_status, #type, #version, #wait_for_attachment
Instance Attribute Details
#attributes ⇒ Object (readonly)
The attributes of a PhidgetMotorControl
28 29 30 |
# File 'lib/phidgets-ffi/motor_control.rb', line 28 def attributes @attributes end |
#encoders ⇒ MotorControlEncoders (readonly)
Collection of encoders
15 16 17 |
# File 'lib/phidgets-ffi/motor_control.rb', line 15 def encoders @encoders end |
#inputs ⇒ MotorControlDigitalInputs (readonly)
Collection of digital inputs
19 20 21 |
# File 'lib/phidgets-ffi/motor_control.rb', line 19 def inputs @inputs end |
#motors ⇒ MotorControlMotors (readonly)
Collection of motors
11 12 13 |
# File 'lib/phidgets-ffi/motor_control.rb', line 11 def motors @motors end |
#sensors ⇒ MotorControlAnalogSensors (readonly)
Collection of analog sensors
23 24 25 |
# File 'lib/phidgets-ffi/motor_control.rb', line 23 def sensors @sensors end |
Instance Method Details
#on_back_emf_update(obj = nil, &block) ⇒ Boolean
Sets a Back EMF update handler callback function. This is called at a steady rate of 16ms, when BackEMF sensing is enabled.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
126 127 128 129 130 131 132 |
# File 'lib/phidgets-ffi/motor_control.rb', line 126 def on_back_emf_update(obj=nil, &block) @on_back_emf_update_obj = obj @on_back_emf_update = Proc.new { |device, obj_ptr, motor, voltage| yield self, @motors[motor], voltage, object_for(obj_ptr) } Klass.set_OnBackEMFUpdate_Handler(@handle, @on_back_emf_update, pointer_for(obj)) end |
#on_current_change(obj = nil, &block) ⇒ Boolean
Sets a current change handler callback function. This is called when the current consumed by a motor changes.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
68 69 70 71 72 73 74 75 76 |
# File 'lib/phidgets-ffi/motor_control.rb', line 68 def on_current_change(obj=nil, &block) @on_current_change_obj = obj @on_current_change = Proc.new { |device, obj_ptr, motor, current| yield self, @motors[motor], current, object_for(obj_ptr) } Klass.set_OnCurrentChange_Handler(@handle, @on_current_change, pointer_for(obj)) end |
#on_current_update(obj = nil, &block) ⇒ Boolean
Sets a current update handler callback function. This is called when the current consumed by a motor changes.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
88 89 90 91 92 93 94 95 96 |
# File 'lib/phidgets-ffi/motor_control.rb', line 88 def on_current_update(obj=nil, &block) @on_current_update_obj = obj @on_current_update = Proc.new { |device, obj_ptr, motor, current| yield self, @motors[motor], current, object_for(obj_ptr) } Klass.set_OnCurrentChange_Handler(@handle, @on_current_update, pointer_for(obj)) end |
#on_input_change(obj = nil, &block) ⇒ Boolean
Sets an input change handler callback function. This is called when a digital input on the PhidgetMotorControl board has changed.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
108 109 110 111 112 113 114 |
# File 'lib/phidgets-ffi/motor_control.rb', line 108 def on_input_change(obj=nil, &block) @on_input_change_obj = obj @on_input_change = Proc.new { |device, obj_ptr, index, state| yield self, @inputs[index], (state == 0 ? false : true), object_for(obj_ptr) } Klass.set_OnInputChange_Handler(@handle, @on_input_change, pointer_for(obj)) end |
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function. This event provides data about how many ticks have occured, and how much time has passed since the last position change event, but does not contain an absolute position. This be be obtained from Phidgets::MotorControl::MotorControlEncoders#position
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
144 145 146 147 148 149 150 151 152 |
# File 'lib/phidgets-ffi/motor_control.rb', line 144 def on_position_change(obj=nil, &block) @on_position_change_obj = obj @on_position_change = Proc.new { |device, obj_ptr, encoder, time, position| yield self, @encoders[encoder], time, position, object_for(obj_ptr) } Klass.set_OnEncoderPositionChange_Handler(@handle, @on_position_change, pointer_for(obj)) end |
#on_position_update(obj = nil, &block) ⇒ Boolean
Sets a position update handler callback function. This event provides data about how many ticks have occured since the last update event. It is called at a steady rate of 8ms.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
164 165 166 167 168 169 170 171 172 |
# File 'lib/phidgets-ffi/motor_control.rb', line 164 def on_position_update(obj=nil, &block) @on_position_update_obj = obj @on_position_update = Proc.new { |device, obj_ptr, encoder, position| yield self, @encoders[encoder], position, object_for(obj_ptr) } Klass.set_OnEncoderPositionUpdate_Handler(@handle, @on_position_update, pointer_for(obj)) end |
#on_sensor_update(obj = nil, &block) ⇒ Boolean
Sets a sensor update handler callback function. This is called at a steady rate of 8ms.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
184 185 186 187 188 189 190 |
# File 'lib/phidgets-ffi/motor_control.rb', line 184 def on_sensor_update(obj=nil, &block) @on_sensor_update_obj = obj @on_sensor_update = Proc.new { |device, obj_ptr, index, value| yield self, @sensors[index], value, object_for(obj_ptr) } Klass.set_OnSensorUpdate_Handler(@handle, @on_sensor_update, pointer_for(obj)) end |
#on_velocity_change(obj = nil, &block) ⇒ Boolean
Sets a velocity change handler callback function. This is called when the velocity of a motor changes.
As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
48 49 50 51 52 53 54 55 56 |
# File 'lib/phidgets-ffi/motor_control.rb', line 48 def on_velocity_change(obj=nil, &block) @on_velocity_change_obj = obj @on_velocity_change = Proc.new { |device, obj_ptr, motor, velocity| yield self, @motors[motor], velocity, object_for(obj_ptr) } Klass.set_OnVelocityChange_Handler(@handle, @on_velocity_change, pointer_for(obj)) end |
#ratiometric ⇒ Boolean Also known as: ratiometric?
Returns the ratiometric state or raises an error
195 196 197 198 199 |
# File 'lib/phidgets-ffi/motor_control.rb', line 195 def ratiometric ptr = ::FFI::MemoryPointer.new(:int) Klass.getRatiometric(@handle, ptr) (ptr.get_int(0) == 0) ? false : true end |
#ratiometric=(new_state) ⇒ Boolean
Sets the ratiometric state of the board.
205 206 207 208 209 |
# File 'lib/phidgets-ffi/motor_control.rb', line 205 def ratiometric=(new_state) tmp = new_state ? 1 : 0 Klass.setRatiometric(@handle, tmp) new_state end |