class BBB::Components::WiiMotionPlus::AxisValue
Constants
- FACTOR
- MAX_AMPLITUDE
- MAX_MEASUREMENT
Attributes
slow[R]
value[R]
zero_value[R]
Public Class Methods
new()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 94 def initialize @value = 0 @slow = 0 @zero_value = 8063 # has to be adjusted during calibration @calibration_values = [] end
Public Instance Methods
degrees()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 107 def degrees value / FACTOR * slow_correction end
slow_correction()
click to toggle source
At high speed (slow bit = 0) raw values read are small with the same deg/s to reach higher values on top, so you must multiply it by 2000/440 (they are the max reference in the two modes in deg/s [1]).
Example: reading 8083 raw value and assuming 8063 as zero, 20 unit in slow/normal mode are 1,45 deg/s and in fast mode are 1.45*2000/440=6.59 deg/s.
# File lib/BBB/components/wii_motion_plus.rb, line 134 def slow_correction slow ? 2000/440 : 1 end
start_calibration!()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 115 def start_calibration! @calibrating = true end
stop_calibration!()
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 119 def stop_calibration! @calibrating = false arr = @calibration_values @zero_value = arr.inject(0) { |sum, el| sum + el } / arr.size @calibration_values = [] end
update(value, slow)
click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 101 def update(value, slow) @value = value @slow = slow @calibration_values << value if @calibrating end