class BBB::Components::WiiMotionPlus::Gyro

DATA FORMAT WII MOTION PLUS (GYRO)

as taken from: wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus

The YAW, PITCH and ROLL values are 14 bit integers (maximum value = 2^14 - 1 = 16383).

The first 8 bits are available in the first Byte. The last 6 bits are available in bits 8 to 13 in byte 3.

Bit positions count from right to left. So bit position 0 is the most ‘right’ bit, and bit 13 bit is the most ‘left’ bit.

this is also why you see the <13:8> position definition in bytes 3,4 and 5.

|——|————————————————————–| | | Bit | |——|————————————————————–| | Byte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |——|————————————————————–| | 0 | Yaw Down Speed<7:0> | |——|————————————————————–| | 1 | Roll Left Speed<7:0> | |——|————————————————————–| | 2 | Pitch Left Speed<7:0> | |——|————————————————————–| | 3 | Yaw Down Speed<13:8> | yaw | pitch | | | | slow | slow | | | | mode | mode | |——|————————————————————–| | 4 | Roll left speed<13:8> | roll | ext. | | | | slow | conn- | | | | mode | ected | |——|————————————————————–| | 5 | Pitch left speed<13:8> | 1 | 0 | |——|————————————————————–|

Constants

HIGH_MASK

Attributes

pitch[R]
roll[R]
yaw[R]

Public Class Methods

new() click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 184
def initialize
  @yaw   = AxisValue.new
  @pitch = AxisValue.new
  @roll  = AxisValue.new
  @calibrating = false
end

Public Instance Methods

calibrating?() click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 191
def calibrating?
  @calibrating
end
set_pitch(bytes) click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 217
def set_pitch(bytes)
  value = (bytes[4] & HIGH_MASK) << 6 | bytes[1]
  slow = bytes[3] & 0b00000001
  pitch.update(value, slow)
end
set_roll(bytes) click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 223
def set_roll(bytes)
  value = (bytes[5] & HIGH_MASK) << 6 | bytes[2]
  slow = bytes[4] & 0b00000010 >> 1
  roll.update(value, slow)
end
set_yaw(bytes) click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 211
def set_yaw(bytes)
  value = (bytes[3] & HIGH_MASK) << 6 | bytes[0]
  slow = bytes[3] & 0b00000010 >> 1
  yaw.update(value, slow)
end
start_calibration!() click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 195
def start_calibration!
  @calibrating = true
  [yaw,pitch,roll].each(&:start_calibration!)
end
stop_calibration!() click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 200
def stop_calibration!
  [yaw,pitch,roll].each(&:stop_calibration!)
  @calibrating = false
end
update(bytes) click to toggle source
# File lib/BBB/components/wii_motion_plus.rb, line 205
def update(bytes)
  set_yaw(bytes)
  set_pitch(bytes)
  set_roll(bytes)
end