<?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; Dampened COG</title>
	<atom:link href="http://blog.dyadica.net/archives/tags/dampened-cog/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>Dampened and Standard COG</title>
		<link>http://blog.dyadica.net/archives/dampened-and-standard-cog</link>
		<comments>http://blog.dyadica.net/archives/dampened-and-standard-cog#comments</comments>
		<pubDate>Wed, 15 Jul 2009 22:23:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Balance Board]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Cent]]></category>
		<category><![CDATA[Center Of Gravity]]></category>
		<category><![CDATA[Dampened COG]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2187</guid>
		<description><![CDATA[A bit of history: Inspired by endquotes WPF implementation of COG I developed an equivalent system for WiimoteLib that provides  facility for Dampened COG output. As stated, I find the two systems can be used ...]]></description>
			<content:encoded><![CDATA[<p>A bit of history: Inspired by endquotes <a title="endquotes COG" href="http://www.brianpeek.com/forums/t/928.aspx">WPF implementation of COG</a> I developed an equivalent system for WiimoteLib that provides  facility for Dampened COG output. As stated, I find the two systems can be used to compliment each other greatly depending upon the desired application requirement. To me the next obvious step was to group both of the outputs together as two available types under the single banner CenterOfGravity.</p>
<p>Using the format of the Wiimote Test application, once complete this instruction will enable access to each COG output as follows:</p>
<blockquote><p>// Standard COG<br />
lblCOG.Text = ws.BalanceBoardState.CenterOfGravity.Standard.ToString();<br />
// Dampened COG<br />
lblDampenedCOG.Text = ws.BalanceBoardState.CenterOfGravity.Dampened.ToString();</p></blockquote>
<p>Before you start this instruction assumes use of a raw copy of WiimoteLib 1.7 and have looked at the <a title="dampened cog instruction" href="http://blog.dyadica.net/pages/balance-board/dampened-cog">Adding Dampened COG to WiimoteLib</a> instruction.</p>
<p>Here is how its done:<span id="more-2187"></span></p>
<p>First we are going to add new public struct CenterOfGravity to Data Types.cs. Just below the existing BalanceBoardState struct add the following block of code:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center Of Gravity Types and Variables<br />
/// &lt;/summary&gt;<br />
[Serializable]<br />
[DataContract]<br />
public struct CenterOfGravity<br />
{<br />
/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public PointF Standard;<br />
/// &lt;summary&gt;<br />
/// Dampened Center of gravity of Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point Dampened;<br />
/// &lt;summary&gt;<br />
/// Offset for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampOffset;<br />
/// &lt;summary&gt;<br />
/// Limits for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public int DampX, DampY;<br />
}</p></blockquote>
<p>As you can see this block contains all the same code as within the previous dampened COG instruction, however we have also added a new member &#8220;Standard&#8221;. Standard is going to reflect the existing COG setup when we are done.</p>
<p>Next (Assuming a raw copy of WiimoteLib 1.7) we need to remove the existing code block defining CenterOfGravity from the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public PointF CenterOfGravity;</p></blockquote>
<p>and replace it with the following new definition:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public CenterOfGravity CenterOfGravity;</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. These functions are in essence the same as within the dampened COG instruction, however now containing the new updated syntax.</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.CenterOfGravity.DampOffset = 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 />
{<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X += (mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y += (mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);</p>
<p>if (mWiimoteState.BalanceBoardState.CenterOfGravity.DampX == 0 || mWiimoteState.BalanceBoardState.CenterOfGravity.DampY == 0)<br />
{<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampX = 500; // hack to cater for zero value at start up<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampY = 800; // hack to cater for zero value at start up<br />
}</p>
<p>int DampX = mWiimoteState.BalanceBoardState.CenterOfGravity.DampX;<br />
int DampY = mWiimoteState.BalanceBoardState.CenterOfGravity.DampY;</p>
<p>mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X = mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X / DampX;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y = mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y / DampY;</p>
<p>return mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened;<br />
}</p></blockquote>
<p>As before, 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.CenterOfGravity.Dampened.X = DCOG.X &#8211; mWiimoteState.BalanceBoardState.CenterOfGravity.DampOffset.X;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y = DCOG.Y &#8211; mWiimoteState.BalanceBoardState.CenterOfGravity.DampOffset.Y;</p></blockquote>
<p>Whilst we are here we also need to update the existing COG code to reflect the new syntax. Just above the code you have just put in update the COG alocations to reflect the following:</p>
<blockquote><p>mWiimoteState.BalanceBoardState.CenterOfGravity.Standard.X = ((float)(Kx &#8211; 1) / (float)(Kx + 1)) * (float)(-BSL / 2);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Standard.Y = ((float)(Ky &#8211; 1) / (float)(Ky + 1)) * (float)(-BSW / 2);</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 both the Standard and Dampened COG values via the new CenterOfGravity grouping. As a final thought, yes it has dawned on me that dampened may be better as damped lol!<a id="update" class="update"></a></p>
<p><strong>Update: The SetBalanceBoardDefaults() Function</strong></p>
<p>Whilst developing the code for the Orientation implementation, it became apparent that there was need for an initialize function that could be used to define defaults and provide facility for resetting etc.</p>
<p>I have decided to add the definition here as really Damped COG  is the first time that we needed its capabilities, remember the hack to cater for zero values at start up:</p>
<blockquote><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></blockquote>
<p>This modification will <span style="text-decoration: line-through;">not only allow us to remove it, but also</span> provide a location for defining other variables later on. Start off by adding the following variable definitions to the top of Wiimote.cs just above the default constructor:</p>
<blockquote><p>private int Dx = 500;<br />
private int Dy = 800;</p></blockquote>
<p>Next we need to add the function itself. Add the following right below the ParseExtension function:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Function used to set the initial defaults.<br />
/// These can be customised above and/or at runtime.<br />
/// &lt;/summary&gt;<br />
private void SetBalanceBoardDefaults()<br />
{<br />
// set the individual damping tolerances for both the<br />
// X and Y axies of the board (good for a rectangle)<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampX = Dx;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampY = Dy;<br />
}</p></blockquote>
<p>With this in place all we need to do now is to add a call to the function at startup. Add the following (Currently I am undecided about merging the two together!) right before the call to SetDampenOffset() within the InitializeExtension() function.</p>
<blockquote><p>SetBalanceBoardDefaults();</p></blockquote>
<p>With that done we are finished and now have provision for defining defaults etc!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/dampened-and-standard-cog/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
