Class: Phidgets::AdvancedServo
- Inherits:
-
Object
- Object
- Phidgets::AdvancedServo
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/advanced_servo.rb
Overview
This class represents a PhidgetAdvancedServo.
Defined Under Namespace
Classes: AdvancedServoServos
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetAdvancedServo
Instance Attribute Summary collapse
-
#advanced_servos ⇒ AdvancedServoServos
readonly
Collection of servo motors.
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetAdvancedServo.
Instance Method Summary collapse
-
#on_current_change(obj = nil, &block) ⇒ Boolean
Sets a current change handler handler callback function.
-
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function.
-
#on_velocity_change(obj = nil, &block) ⇒ Boolean
Sets a velocity change handler callback function.
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
#advanced_servos ⇒ AdvancedServoServos (readonly)
Collection of servo motors
11 12 13 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 11 def advanced_servos @advanced_servos end |
#attributes ⇒ Object (readonly)
The attributes of a PhidgetAdvancedServo
16 17 18 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 16 def attributes @attributes end |
Instance Method Details
#on_current_change(obj = nil, &block) ⇒ Boolean
Sets a current change handler 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.
70 71 72 73 74 75 76 77 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 70 def on_current_change(obj=nil, &block) @on_current_change_obj = obj @on_current_change = Proc.new { |device, obj_ptr, index, current| yield self, @advanced_servos[index], current, object_for(obj_ptr) } Klass.set_OnCurrentChange_Handler(@handle, @on_current_change, pointer_for(obj)) end |
#on_position_change(obj = nil, &block) ⇒ Boolean
Sets a position change handler callback function. This is called when the servo position 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.
51 52 53 54 55 56 57 58 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 51 def on_position_change(obj=nil, &block) @on_position_change_obj = obj @on_position_change = Proc.new { |device, obj_ptr, index, position| yield self, @advanced_servos[index], position, object_for(obj_ptr) } Klass.set_OnPositionChange_Handler(@handle, @on_position_change, 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 servo 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.
32 33 34 35 36 37 38 39 |
# File 'lib/phidgets-ffi/advanced_servo.rb', line 32 def on_velocity_change(obj=nil, &block) @on_velocity_change_obj = obj @on_velocity_change = Proc.new { |device, obj_ptr, index, velocity| yield self, @advanced_servos[index], velocity, object_for(obj_ptr) } Klass.set_OnVelocityChange_Handler(@handle, @on_velocity_change, pointer_for(obj)) end |