Class: Phidgets::Spatial
- Inherits:
-
Object
- Object
- Phidgets::Spatial
- Includes:
- Common
- Defined in:
- lib/phidgets-ffi/spatial.rb
Overview
This class represents a PhidgetSpatial.
Defined Under Namespace
Classes: SpatialAccelerometerAxes, SpatialCompassAxes, SpatialGyroAxes
Constant Summary collapse
- Klass =
Phidgets::FFI::CPhidgetSpatial
Instance Attribute Summary collapse
-
#accelerometer_axes ⇒ SpatialAccelerometerAxes
readonly
Collection of accelerometer axes.
-
#attributes ⇒ Object
readonly
The attributes of a PhidgetSpatial.
-
#compass_axes ⇒ SpatialCompassAxes
readonly
Collection of compass axes.
-
#gyro_axes ⇒ SpatialGyroAxes
readonly
Collection of gyro axes.
Instance Method Summary collapse
-
#data_rate ⇒ Integer
Returns data rate in ms, or raises an error.
-
#data_rate=(new_data_rate) ⇒ Integer
Sets the data rate in ms, or raises an error.
-
#data_rate_max ⇒ Integer
Returns maximum data rate in ms, or raises an error.
-
#data_rate_min ⇒ Integer
Returns minimum data rate in ms, or raises an error.
-
#on_spatial_data(obj = nil, &block) ⇒ Boolean
Sets a spatial data handler callback function.
-
#reset_compass_correction_parameters ⇒ Boolean
Resets correction parameters for the magnetometer triad.
-
#set_compass_correction_parameters(new_mag_field, new_offset0, new_offset1, new_offset2, new_gain0, new_gain1, new_gain2, new_t0, new_t1, new_t2, new_t3, new_t4, new_t5) ⇒ Boolean
Sets correction paramaters for the magnetometer triad.
-
#zero_gyro ⇒ Boolean
Zeroes the gyro.
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
#accelerometer_axes ⇒ SpatialAccelerometerAxes (readonly)
Collection of accelerometer axes
11 12 13 |
# File 'lib/phidgets-ffi/spatial.rb', line 11 def accelerometer_axes @accelerometer_axes end |
#attributes ⇒ Object (readonly)
The attributes of a PhidgetSpatial
24 25 26 |
# File 'lib/phidgets-ffi/spatial.rb', line 24 def attributes @attributes end |
#compass_axes ⇒ SpatialCompassAxes (readonly)
Collection of compass axes
15 16 17 |
# File 'lib/phidgets-ffi/spatial.rb', line 15 def compass_axes @compass_axes end |
#gyro_axes ⇒ SpatialGyroAxes (readonly)
Collection of gyro axes
19 20 21 |
# File 'lib/phidgets-ffi/spatial.rb', line 19 def gyro_axes @gyro_axes end |
Instance Method Details
#data_rate ⇒ Integer
Returns data rate in ms, or raises an error.
105 106 107 108 109 |
# File 'lib/phidgets-ffi/spatial.rb', line 105 def data_rate ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRate(@handle, @index, ptr) ptr.get_int(0) end |
#data_rate=(new_data_rate) ⇒ Integer
Sets the data rate in ms, or raises an error.
114 115 116 117 |
# File 'lib/phidgets-ffi/spatial.rb', line 114 def data_rate=(new_data_rate) Klass.setDataRate(@handle, @index, new_data_rate.to_i) new_data_rate.to_i end |
#data_rate_max ⇒ Integer
Returns maximum data rate in ms, or raises an error.
127 128 129 130 131 |
# File 'lib/phidgets-ffi/spatial.rb', line 127 def data_rate_max ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRateMax(@handle, @index, ptr) ptr.get_int(0) end |
#data_rate_min ⇒ Integer
Returns minimum data rate in ms, or raises an error.
120 121 122 123 124 |
# File 'lib/phidgets-ffi/spatial.rb', line 120 def data_rate_min ptr = ::FFI::MemoryPointer.new(:int) Klass.getDataRateMin(@handle, @index, ptr) ptr.get_int(0) end |
#on_spatial_data(obj = nil, &block) ⇒ Boolean
Sets a spatial data handler callback function. This is called at a fixed rate as determined by the data rate property. Contains data for acceleration/gyro/compass depending on what the board supports.
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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/phidgets-ffi/spatial.rb', line 41 def on_spatial_data(obj=nil, &block) @on_spatial_data_obj = obj @on_spatial_data = Proc.new { |device, obj_ptr, data, data_count| acceleration = [] if accelerometer_axes.size > 0 acceleration = [accelerometer_axes[0].acceleration, accelerometer_axes[1].acceleration, accelerometer_axes[2].acceleration] end magnetic_field= [] if compass_axes.size > 0 #Even when there is a compass chip, sometimes there won't be valid data in the event. begin magnetic_field = [compass_axes[0].magnetic_field, compass_axes[1].magnetic_field, compass_axes[2].magnetic_field] rescue Phidgets::Error::UnknownVal => e magnetic_field = ['Unknown', 'Unknown', 'Unknown'] end end angular_rate = [] if gyro_axes.size > 0 angular_rate = [gyro_axes[0].angular_rate, gyro_axes[1].angular_rate, gyro_axes[2].angular_rate] end yield self, acceleration, magnetic_field, angular_rate, object_for(obj_ptr) } Klass.set_OnSpatialData_Handler(@handle, @on_spatial_data, pointer_for(obj)) end |
#reset_compass_correction_parameters ⇒ Boolean
Resets correction parameters for the magnetometer triad. This returns magnetometer output to raw magnetic field strength.
79 80 81 82 |
# File 'lib/phidgets-ffi/spatial.rb', line 79 def reset_compass_correction_parameters Klass.resetCompassCorrectionParameters(@handle) true end |
#set_compass_correction_parameters(new_mag_field, new_offset0, new_offset1, new_offset2, new_gain0, new_gain1, new_gain2, new_t0, new_t1, new_t2, new_t3, new_t4, new_t5) ⇒ Boolean
Sets correction paramaters for the magnetometer triad. This is for filtering out hard and soft iron offsets, and scaling the output to match the local field strength. These parameters can be obtained from the compass calibration program provided by Phidgets Inc.
99 100 101 102 |
# File 'lib/phidgets-ffi/spatial.rb', line 99 def set_compass_correction_parameters(new_mag_field, new_offset0, new_offset1, new_offset2, new_gain0, new_gain1, new_gain2, new_t0, new_t1, new_t2, new_t3, new_t4, new_t5) Klass.setCompassCorrectionParameters(@handle, new_mag_field, new_offset0, new_offset1, new_offset2, new_gain0, new_gain1, new_gain2, new_t0, new_t1, new_t2, new_t3, new_t4, new_t5) true end |
#zero_gyro ⇒ Boolean
Zeroes the gyro. This takes 1-2 seconds to complete and should only be called when the board is stationary.
72 73 74 75 |
# File 'lib/phidgets-ffi/spatial.rb', line 72 def zero_gyro Klass.zeroGyro(@handle) true end |