dyadica.net

Fun and Games in the Dyadic Sea

Adding Dampened COG to WiimoteLib

permalink image comments image
Tuesday, 14 July '09 :
Here is a post that I meant to publish along time ago but never got around too. Originally drafted 20/09/08 may I introduce COG Dampening!

Please note that I have renamed Dampened to Damped please update as required!

Inspired by endquotes WPF implementation of COG I have developed an equivalent system for WiimoteLib that provides the library with facility for Dampened COG output. I find the two systems can be used to compliment each other greatly depending upon the desired application requirement. Before you start this instruction assumes use of a raw copy of WiimoteLib 1.7

Here is how its done:

Open up Data Types.cs and within the public struct BalanceBoardState add the following blocks of code:

/// <summary>
/// Dampened Center of gravity of Balance Board
/// </summary>
[DataMember]
public Point DampenedCOG;

/// <summary>
/// Offset for Center of gravity Damping
/// </summary>
[DataMember]
public Point DampingOffset;

/// <summary>
/// Limits for Center of gravity Damping
/// </summary>
[DataMember]
public int DampX, DampY;

Next we need to add the following two new functions to Wiimote.cs, I have included them just below the ParseExtension function. These functions are used to provide an initial damping offset (calibration value) and calculate the Dampened COG at run time.

/// <summary>
/// Function used to set the damping offset
/// </summary>
public void SetDampenOffset()
{ mWiimoteState.BalanceBoardState.DampingOffset = GetDampenedCenterOfGravity(); }

/// <summary>
/// Function to get Dampened COG without the offset so it can also be used to set the offset
/// </summary>
private Point GetDampenedCenterOfGravity()
{

mWiimoteState.BalanceBoardState.DampenedCOG.X += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft);
mWiimoteState.BalanceBoardState.DampenedCOG.Y += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight);
mWiimoteState.BalanceBoardState.DampenedCOG.X += (mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);
mWiimoteState.BalanceBoardState.DampenedCOG.Y += (mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);

if (mWiimoteState.BalanceBoardState.DampX == 0 || mWiimoteState.BalanceBoardState.DampY == 0)
{
mWiimoteState.BalanceBoardState.DampX = 500; // hack to cater for zero value at start up
mWiimoteState.BalanceBoardState.DampY = 800; // hack to cater for zero value at start up
}

int DampX = mWiimoteState.BalanceBoardState.DampX;
int DampY = mWiimoteState.BalanceBoardState.DampY;

mWiimoteState.BalanceBoardState.DampenedCOG.X = mWiimoteState.BalanceBoardState.DampenedCOG.X / DampX;
mWiimoteState.BalanceBoardState.DampenedCOG.Y = mWiimoteState.BalanceBoardState.DampenedCOG.Y / DampY;

return mWiimoteState.BalanceBoardState.DampenedCOG;

}

The inclusion of the DampX and DampY variables enables individual axis stiffness customization, which is usefull due the rectangular nature of the Balance Board.

Next in order to use these functions we need to add the following code to the parse extension function. I do this just below the existing COG code:

Point DCOG = GetDampenedCenterOfGravity();

mWiimoteState.BalanceBoardState.DampenedCOG.X = DCOG.X – mWiimoteState.BalanceBoardState.DampingOffset.X;
mWiimoteState.BalanceBoardState.DampenedCOG.Y = DCOG.Y – mWiimoteState.BalanceBoardState.DampingOffset.Y;

Ok, we are nearly done. Finally we need to add a call to the SetDampenOffset() function in order to define an offset value at start up. Still within Wiimote.cs add the following call within InitializeExtension() inside the ExtensionType.BalanceBoard case,  just above the break.

SetDampenOffset();

And thats it, now you should have acces to DampenedCOG in the usual manner!

Tags: , , , , , , ,

page meta

get trackback image get trackback image
details
  • Posted: Tuesday, 14 July '09
  • Edited: Sunday, 16 August '09
  • Category: C#, Wii, hardware
  • 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