dyadica.net

Fun and Games in the Dyadic Sea

The Balance Board Quadzone Filter for WiimoteLib

permalink image comments image
Tuesday, 14 July '09 :

There are times when using the WiiFit Balance Board with WiimoteLib that I find it useful to have direct access to which particular “Zone” currently has focus (most weight or COG applied), just think WiiFit areobics etc. Output is fed back as a string which can then be used as desired eg in a switch or if statement etc.

Here’s how its done:

First of all open up Data Types.cs and add the following code block within the BalanceBoardState struct:

/// <summary>
/// Current Balance Board Zone
/// </summary>
[DataMember]
public string Quadzone;

Next open up Wiimote.cs and locate the parse extension function. For convenience sake the following block shorthands the values included with WiimoteLib to help with RSI. Add the following code below the existing COG code just above the break:

// Shorthand the values for lazyness (Raw)
// float TLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft;
// float TRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight;
// float BLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft;
// float BRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight;

// Shorthand the values for lazyness (Kg)
float TLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
float TRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
float BLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
float BRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;

As you can see I have included facility for using the raw values, but personally I have not found a need to yet! Next we need to add the code that will enable Zone output at run time. Below the shorthand code add the following block:

if ((TLkg + TRkg) > (TLkg + BLkg) &&
(TLkg + TRkg) > (TLkg + BLkg) &&
(TLkg + TRkg) > (BLkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Top”; }

if ((BLkg + BRkg) > (TLkg + BLkg) &&
(BLkg + BRkg) > (TLkg + BLkg) &&
(BLkg + BRkg) > (TLkg + TRkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Bottom”; }

if ((TLkg + BLkg) > (TLkg + TRkg) &&
(TLkg + BLkg) > (BLkg + BRkg) &&
(TLkg + BLkg) > (TRkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Left”; }

if ((TRkg + BRkg) > (TLkg + TRkg) &&
(TRkg + BRkg) > (BLkg + BRkg) &&
(TRkg + BRkg) > (TLkg + BLkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Right”; }

If you want you can also add definitions for angle zones however as with the raw value definitions I dont really find much use for them, however here they are just in case:

//if ((TLkg + BRkg) > (TLkg + TRkg) &&
//     (TLkg + BRkg) > (BLkg + BRkg) &&
//     (TLkg + BRkg) > (TLkg + BLkg) &&
//     (TLkg + BRkg) > (TRkg + BLkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Left-Right”; }

//if ((TRkg + BLkg) > (TLkg + TRkg) &&
//     (TRkg + BLkg) > (BLkg + BRkg) &&
//     (TRkg + BLkg) > (TLkg + BLkg) &&
//     (TRkg + BLkg) > (TLkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = “Right-Left”; }

Once complete Quadzone is now available by the normal means for example:

WiimoteState ws = state;
BalanceBoardState bb = ws.BalanceBoardState;

string current_zone = bb.Quadzone;

That’s all there is to it easy eh!

Tags: , , , , , ,

page meta

get trackback image get trackback image
details
  • Posted: Tuesday, 14 July '09
  • Edited: Sunday, 16 August '09
  • Category: C#, Wii
  • Author: admin

say what do you think

RSS feed | Trackback URI

css | xhtml | dyadica.net © admin 2010 | powered: wordpress | fuel: ps-wii-elite | top | sign-up