<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dyadica.net &#187; Center of</title>
	<atom:link href="http://blog.dyadica.net/archives/tags/center-of/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.dyadica.net</link>
	<description>Fun and Games in the Dyadic Sea</description>
	<lastBuildDate>Wed, 21 Jul 2010 14:04:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding Dampened COG to WiimoteLib</title>
		<link>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib</link>
		<comments>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib#comments</comments>
		<pubDate>Tue, 14 Jul 2009 16:32:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Center of]]></category>
		<category><![CDATA[Center Of Gravity]]></category>
		<category><![CDATA[COG]]></category>
		<category><![CDATA[Dampened COG]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2133</guid>
		<description><![CDATA[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 ...]]></description>
			<content:encoded><![CDATA[<p>Inspired by endquotes <a title="endquotes COG" href="http://www.brianpeek.com/forums/t/928.aspx">WPF implementation of COG</a> 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</p>
<p>Here is how its done:</p>
<p>Open up Data Types.cs and within the public struct BalanceBoardState add the following blocks of code:<span id="more-2133"></span></p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Dampened Center of gravity of Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampenedCOG;</p>
<p>/// &lt;summary&gt;<br />
/// Offset for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampingOffset;</p>
<p>/// &lt;summary&gt;<br />
/// Limits for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public int DampX, DampY;</p></blockquote>
<p>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.</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Function used to set the damping offset<br />
/// &lt;/summary&gt;<br />
public void SetDampenOffset()<br />
{ mWiimoteState.BalanceBoardState.DampingOffset = GetDampenedCenterOfGravity(); }</p>
<p>/// &lt;summary&gt;<br />
/// Function to get Dampened COG without the offset so it can also be used to set the offset<br />
/// &lt;/summary&gt;<br />
private Point GetDampenedCenterOfGravity()<br />
{</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.X += (mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y += (mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);</p>
<p>if (mWiimoteState.BalanceBoardState.DampX == 0 || mWiimoteState.BalanceBoardState.DampY == 0)<br />
{<br />
mWiimoteState.BalanceBoardState.DampX = 500; // hack to cater for zero value at start up<br />
mWiimoteState.BalanceBoardState.DampY = 800; // hack to cater for zero value at start up<br />
}</p>
<p>int DampX = mWiimoteState.BalanceBoardState.DampX;<br />
int DampY = mWiimoteState.BalanceBoardState.DampY;</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X = mWiimoteState.BalanceBoardState.DampenedCOG.X / DampX;<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y = mWiimoteState.BalanceBoardState.DampenedCOG.Y / DampY;</p>
<p>return mWiimoteState.BalanceBoardState.DampenedCOG;</p>
<p>}</p></blockquote>
<p>The inclusion of the DampX and DampY variables enables individual axis stiffness customization, which is usefull due the rectangular nature of the Balance Board.</p>
<p>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:</p>
<blockquote><p>Point DCOG = GetDampenedCenterOfGravity();</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X = DCOG.X &#8211; mWiimoteState.BalanceBoardState.DampingOffset.X;<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y = DCOG.Y &#8211; mWiimoteState.BalanceBoardState.DampingOffset.Y;</p></blockquote>
<p>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.</p>
<blockquote><p>SetDampenOffset();</p></blockquote>
<p>And thats it, now you should have acces to DampenedCOG in the usual manner!<a id="update" class="update"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
