<?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>32leaves</title>
	<atom:link href="http://blog.32leaves.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.32leaves.net</link>
	<description>creative software hackery</description>
	<lastBuildDate>Sun, 01 Aug 2010 16:32:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>STL slicing for 3D printing</title>
		<link>http://blog.32leaves.net/?p=988</link>
		<comments>http://blog.32leaves.net/?p=988#comments</comments>
		<pubDate>Sun, 01 Aug 2010 16:31:57 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[3D printing]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[VTK]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=988</guid>
		<description><![CDATA[Some 3D printing methods like the additive layer manufacturing require the model to be sliced into discrete layers, which are then being printed one after another. These days I&#8217;m playing around with 3D printing thus I needed to perform some slicing myself. Unfortunately I didn&#8217;t like the methods to perform such slicing that much, so [...]]]></description>
			<content:encoded><![CDATA[<div class="p">Some <a href="http://www.candyfab.org/">3D printing methods</a> like the <em><a href="http://en.wikipedia.org/wiki/Additive_manufacturing">additive layer manufacturing</a></em> require the model to be sliced into discrete layers, which are then being printed one after another. These days I&#8217;m playing around with 3D printing thus I needed to perform some slicing myself. Unfortunately I didn&#8217;t like the <a href="http://www.evilmadscientist.com/article.php/slicingstl">methods to perform</a> <a href="http://www.freesteel.co.uk/wpblog/slicer/">such slicing</a> that much, so I decided to give it a shot and write my own.
</div>
<div class="p">
Some time ago I wrote a utility that visualizes the flight of a quadrocopter. To make things easy I used the <a href="http://www.vtk.org/">Visualization Toolkit</a>. Remembering that I hit google and found an <a href="http://www.cmake.org/Wiki/VTK/Examples/VisualizationAlgorithms/vtkCutter">example</a> the pretty much did what I wanted. The model&#8217;s loaded using <a href="http://www.vtk.org/doc/release/4.0/html/classvtkSTLReader.html">vtkSTLReader</a> and <a href="http://www.vtk.org/doc/release/4.0/html/classvtkStripper.html">vtkStripper</a> is employed to merge the polyline strips to connected components.<br />
Unfortunately vtkStripper still has a <a href="http://www.cmake.org/Bug/view.php?id=832">bug</a> (since 2004!) which rendered it unusable for my endeavor. It causes some images to look quite wrong (thus they&#8217;d be printed wrong) as it combined some polylines in an unsuitable manner. The slice pictured below has that white/inverted triangle which is not supposed to be there.<br />
<center><a href="http://blog.32leaves.net/wp-content/uploads/2010/08/damagedSlice.png" rel="lightbox[988]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/08/damagedSlice-290x300.png" alt="" title="damagedSlice" width="290" height="300" class="aligncenter size-medium wp-image-991" /></a></center><br />
After patching <tt>vtkStripper.cxx</tt> with the patch attached to be <a href="http://www.cmake.org/Bug/view.php?id=832">bug</a>, everything was fine. (Well pretty much, I&#8217;ve still experienced the problem one time, but hey, what&#8217;s perfect in this world <img src='http://blog.32leaves.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )
</div>
<div class="p">
So the whole slicing process is:
<ol>
<li><b>Slice STL model using vtkCutter and store the polylines in vtp files.</b> By decuppling the cutting process from rendering the images, we gain flexibility, since we do not have to do the cutting each time we want to use a different rendering algorithm. The first step also computes the bounds of the model (using a bounding box) and stores them in a file.</li>
<li><b>Convert polyline to SVG.</b> We use SVG since it provides multiple benefits over directly rasterizing the polyline. First of all we retain control over the units (during the whole process you want to make sure you don&#8217;t mess up the units, or otherwise your printed object may be twice as large as anticipated or similar problems may occur).</li>
<li><b>Use ImageMagick to rasterize the SVG graphics.</b> Actually that&#8217;s something pretty cool, because in this step we can easily ensure that we&#8217;re using the correct resolution for our printer. So if we used an Ink printer to apply the binder during the 3D printing process, we could simply use the resolution of the printer.</li>
</ol>
<p>So now that we have all slices we can (of course) print them, or we could make a little movie out of them, which is exactly what I did:<br />
<object width="720" height="405"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13801714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13801714&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="405"></embed></object><br />
The model&#8217;s coming from <a href="http://www.thingiverse.com/thing:822">Thingiverse</a> and the music is from <a href="http://soundcloud.com/djfiddler/rex-rewire-his-brain-fiddler-remix">SoundCloud</a>. You might notice the full model in upper right corner, that&#8217;s just visual sugar for the video and not part of the sliced images.
</div>
<div class="p">
To make the whole process a little easier, I wrapped a Makefile around it and wrote a little ruby script that builds the environment for the makefile to work. That ruby script, as well as the source can be found in the ZIP file after the break. You&#8217;ll need VTK to build to build the tools and ImageMagick to run the whole thing.<br />
<strong>Download me</strong> <a href='http://blog.32leaves.net/wp-content/uploads/2010/08/slicing_01.zip'>here</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=988</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Word generation using an n-dimensional discrete hypercube</title>
		<link>http://blog.32leaves.net/?p=933</link>
		<comments>http://blog.32leaves.net/?p=933#comments</comments>
		<pubDate>Sat, 31 Jul 2010 00:37:31 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Maths]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[word generation]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=933</guid>
		<description><![CDATA[This algorithm is something a friend of mine and I have developed quite some time ago (probably a year or so). It might also be already known under some name and I&#8217;m not aware of it. None the less it&#8217;s an interesting solution to a quite interesting problem. Suppose that you wanted to generate the [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
This algorithm is something a friend of mine and I have developed quite some time ago (probably a year or so). It might also be already known under some name and I&#8217;m not aware of it. None the less it&#8217;s an interesting solution to a quite interesting problem.
</div>
<div class="p">
Suppose that you wanted to generate the words <img src="http://blog.32leaves.net/wp-content/cache/tex_149954589adccebb4d104e1128a6197e.gif" align="absmiddle" class="tex" alt="w \in \Sigma^n" /> of the alphabet <img src="http://blog.32leaves.net/wp-content/cache/tex_909efdff5d9fae8bc83b64d2b66d22ea.gif" align="absmiddle" class="tex" alt="\Sigma = \{\alpha_0, \alpha_1, \dots, \alpha_m\}" />. And that you wanted to do that in a parallel manner, such that you had a set of threads where each thread has a unique number out of <img src="http://blog.32leaves.net/wp-content/cache/tex_111a8e0f876011c88832d8a5b1191c53.gif" align="absmiddle" class="tex" alt="0\dots \vert\Sigma\vert^n" /> assigned.<br />
In that case it would be favorable to have a mapping in the form <img src="http://blog.32leaves.net/wp-content/cache/tex_66b54bead4ff99c1a5275689ca1c3702.gif" align="absmiddle" class="tex" alt="\underbrace{\{k: 0 \leq k < \vert\Sigma\vert^n\}}_S\to\Sigma^n" />, so that each thread could easily (reading with less computational effort) generate the word it&#8217;s supposed to work on. Notice that implicit definition of <img src="http://blog.32leaves.net/wp-content/cache/tex_8ae6c7ac5b6fc39e3e42636f55e3a617.gif" align="absmiddle" class="tex" alt="S:=\{k: 0 \leq k < \vert\Sigma\vert^n\}" />.
</div>
<div class="p">
To solve the problem described previously, we start with a function that maps elements of <img src="http://blog.32leaves.net/wp-content/cache/tex_5dbc98dcc983a70728bd082d1a47546e.gif" align="absmiddle" class="tex" alt="S" /> to points in an <img src="http://blog.32leaves.net/wp-content/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif" align="absmiddle" class="tex" alt="n" />-dimensional discrete hypercube. That mapping <img src="http://blog.32leaves.net/wp-content/cache/tex_adaccafdf763556bbbe2b94f2c0901dd.gif" align="absmiddle" class="tex" alt="V: S\to\{ k: 0\leq k < \vert\Sigma\vert \}^n" /> is defined as follows: <img src="http://blog.32leaves.net/wp-content/cache/tex_85f36e322cf43a758f84dd2eada3c6dd.gif" align="absmiddle" class="tex" alt="V(s) = \begin{bmatrix} \left\lfloor\frac{s}{l^0}\right\rfloor \mod l \\ \left\lfloor\frac{s}{l^1}\right\rfloor \mod l \\ \vdots \\ \left\lfloor\frac{s}{l^{n-1}}\right\rfloor \mod l \end{bmatrix}" /> where <img src="http://blog.32leaves.net/wp-content/cache/tex_eb81d9b300ab1cf8efe667ae39c66cc6.gif" align="absmiddle" class="tex" alt="l:=\vert\Sigma\vert" />. This mapping obviously maps a natural number <img src="http://blog.32leaves.net/wp-content/cache/tex_c8bdbdefe17f22d8ba986bd535f4b3cb.gif" align="absmiddle" class="tex" alt="s < \vert\Sigma\vert^n" /> to a point in a discrete <img src="http://blog.32leaves.net/wp-content/cache/tex_7b8b965ad4bca0e41ab51de7b31363a1.gif" align="absmiddle" class="tex" alt="n" />-dimensional hypercube with an edge length of <img src="http://blog.32leaves.net/wp-content/cache/tex_c9d27fa793106af37193469b562bddad.gif" align="absmiddle" class="tex" alt="\vert\Sigma\vert" />. <strong>Example:</strong> Consider <img src="http://blog.32leaves.net/wp-content/cache/tex_b9f564c1447c042beb69e50e579f770b.gif" align="absmiddle" class="tex" alt="\vert\Sigma\vert = 3" /> and <img src="http://blog.32leaves.net/wp-content/cache/tex_fa346db4ae0286d4c297bdfea3041cab.gif" align="absmiddle" class="tex" alt="n = 3" />. Then we can visualize <img src="http://blog.32leaves.net/wp-content/cache/tex_5206560a306a2e085a437fd258eb57ce.gif" align="absmiddle" class="tex" alt="V" /> as follows:<center><img src="http://blog.32leaves.net/wp-content/uploads/2010/07/HypercubeMapping.png" alt="" title="HypercubeMapping" width="285" height="300" class="aligncenter size-full wp-image-947" /></center>
</div>
<div class="p">
Now that we have a mapping from a natural number to a point in the hypercube, we need a mapping from a point in the hypercube to the word itself. Such a mapping <img src="http://blog.32leaves.net/wp-content/cache/tex_0a74f32893f48460ec1f39423085d1e0.gif" align="absmiddle" class="tex" alt="W: \{ k: 0\leq k < \vert\Sigma\vert \}^n \to \Sigma^n" /> is easy to find. Consider <img src="http://blog.32leaves.net/wp-content/cache/tex_48a6d532ce082de28a67acd75765c959.gif" align="absmiddle" class="tex" alt="W(p) := \alpha_{p_0}\alpha_{p_1}\dots\alpha_{p_n}" /> where the <img src="http://blog.32leaves.net/wp-content/cache/tex_eca91c83a74a2373ca5f796700e99fd3.gif" align="absmiddle" class="tex" alt="p_i" /> are the components of the vector <img src="http://blog.32leaves.net/wp-content/cache/tex_83878c91171338902e0fe0fb97a8c47a.gif" align="absmiddle" class="tex" alt="p" /> and <img src="http://blog.32leaves.net/wp-content/cache/tex_bc0af9ca8ad47c020b08074a14d279a4.gif" align="absmiddle" class="tex" alt="\alpha_i \in \Sigma" />.
</div>
<div class="p">
So our final mapping <img src="http://blog.32leaves.net/wp-content/cache/tex_1caf19caec7bb25c9284af543941ed31.gif" align="absmiddle" class="tex" alt="F: S\to\Sigma^n" /> is <img src="http://blog.32leaves.net/wp-content/cache/tex_c1246a2895899541ada8a134736afd76.gif" align="absmiddle" class="tex" alt="F:=W\circ V" /> and exactly what we desired. One might notice that <img src="http://blog.32leaves.net/wp-content/cache/tex_800618943025315f869e4e1f09471012.gif" align="absmiddle" class="tex" alt="F" /> must be surjective so that each word is computed if there are just enough threads. To prove that, we&#8217;ll prove that <img src="http://blog.32leaves.net/wp-content/cache/tex_5206560a306a2e085a437fd258eb57ce.gif" align="absmiddle" class="tex" alt="V" /> as well as <img src="http://blog.32leaves.net/wp-content/cache/tex_61e9c06ea9a85a5088a499df6458d276.gif" align="absmiddle" class="tex" alt="W" /> is surjective (since the functional composition of two surjective functions is surjective as well).
</div>
<div class="p">
<table>
<tr>
<td><b>Theorem:</b></td>
<td><img src="http://blog.32leaves.net/wp-content/cache/tex_5206560a306a2e085a437fd258eb57ce.gif" align="absmiddle" class="tex" alt="V" /> is surjective, so that <img src="http://blog.32leaves.net/wp-content/cache/tex_1fc534c6b9ec762abab73e4482480d6c.gif" align="absmiddle" class="tex" alt="\forall v \in \{ k: 0\leq k < \vert\Sigma\vert \}^n : \exists x \in S : V(x) = v" />.</td>
</tr>
<tr>
<td><b>Proof:</b></td>
<td>Let <img src="http://blog.32leaves.net/wp-content/cache/tex_eb81d9b300ab1cf8efe667ae39c66cc6.gif" align="absmiddle" class="tex" alt="l:=\vert\Sigma\vert" />, <img src="http://blog.32leaves.net/wp-content/cache/tex_1a00009a5a914f33d1986c700a42e549.gif" align="absmiddle" class="tex" alt="u_i\in\mathbb{N}" />, <img src="http://blog.32leaves.net/wp-content/cache/tex_33a6d8b80975d9c918839cb0afb26bcd.gif" align="absmiddle" class="tex" alt="y\in S" /> and <img src="http://blog.32leaves.net/wp-content/cache/tex_1996944b757bbc362631035e1ea41786.gif" align="absmiddle" class="tex" alt="v:=\begin{bmatrix} v_1 &#038; \dots &#038; v_n\end{bmatrix}^T" />. Assume that <img src="http://blog.32leaves.net/wp-content/cache/tex_896e3a57a0baa903239501b6f3e0f495.gif" align="absmiddle" class="tex" alt="y = v_1\cdot l^0 + \dots + v_n\cdot l^{n-1}" />, then </p>
<table border="0" width="100%">
<tr>
<td width="100%">
<img src="http://blog.32leaves.net/wp-content/cache/tex_15a0a49a6471d73714dc7faf20284620.gif" align="absmiddle" class="tex" alt="V(y) =<br />
	\begin{bmatrix}<br />
		v_1+\underbrace{\dots+v_{n}\cdot l^{n-1}}_{u_1\cdot l} \mod l \\<br />
		\vdots \\<br />
		\underbrace{\left\lfloor\frac{v_1\cdot l^0 + \dots}{l^{n-1}}\right\rfloor}_{u_n\cdot l} + v_n \mod l<br />
	\end{bmatrix}" />
</td>
<td>(1)</td>
</tr>
<tr>
<td width="100%">
<img src="http://blog.32leaves.net/wp-content/cache/tex_205abb92d25bbb7c870699d989ba4d03.gif" align="absmiddle" class="tex" alt="= \begin{bmatrix}<br />
		v_1 \mod l &#038; \dots &#038; v_n \mod l<br />
	\end{bmatrix}^T" />
</td>
<td>(2)</td>
</tr>
<tr>
<td width="100%">
<img src="http://blog.32leaves.net/wp-content/cache/tex_7df2ede361be17cc021f3fd5ae4713e9.gif" align="absmiddle" class="tex" alt="= \begin{bmatrix} v_1 &#038; \dots &#038; v_n\end{bmatrix}^T = v" />
</td>
<td>(3)</td>
</tr>
</table>
<p>The transition from (1) to (2) is allowed as <img src="http://blog.32leaves.net/wp-content/cache/tex_d67db508a20db8a1ea8dab8a7dbd46dd.gif" align="absmiddle" class="tex" alt="u_i\cdot l\mod l = 0" />. Similar goes for the equivalence of (2) and (3): <img src="http://blog.32leaves.net/wp-content/cache/tex_1fe763e659ee48dea4a2fa793cbaba71.gif" align="absmiddle" class="tex" alt="v_i \mod l = v_i" /> as <img src="http://blog.32leaves.net/wp-content/cache/tex_b52a7aa5053a455f48e475566c0c8616.gif" align="absmiddle" class="tex" alt="v_i \leq l" />.
</td>
</tr>
</table>
</div>
<div class="p">
<table>
<tr>
<td><b>Theorem:</b></td>
<td><img src="http://blog.32leaves.net/wp-content/cache/tex_61e9c06ea9a85a5088a499df6458d276.gif" align="absmiddle" class="tex" alt="W" /> is surjective, so that <img src="http://blog.32leaves.net/wp-content/cache/tex_0b54e0125cb2809b01e33f4dca615bc6.gif" align="absmiddle" class="tex" alt="\forall w \in \Sigma^n : \exists v \in \{ k: 0\leq k < \vert\Sigma\vert \}^n : W(v) = w" />.</td>
</tr>
<tr>
<td><b>Proof:</b></td>
<td>Let <img src="http://blog.32leaves.net/wp-content/cache/tex_b8f87bd2157a1fef58edb0245d809c90.gif" align="absmiddle" class="tex" alt="w:=\alpha_{v_1}\dots\alpha_{v_n}" /> then the vector <img src="http://blog.32leaves.net/wp-content/cache/tex_7b857bd662f663d786e1c565a248d0d9.gif" align="absmiddle" class="tex" alt="v=\begin{bmatrix}v_1 &#038; \dots &#038; v_n\end{bmatrix}" /> (which obviously fullfils <img src="http://blog.32leaves.net/wp-content/cache/tex_d3058d6293077a2b9ddcc5bc775016bd.gif" align="absmiddle" class="tex" alt="W(v)=w" />) must exist, since <img src="http://blog.32leaves.net/wp-content/cache/tex_93873778011b906d91887f67e4b2a17b.gif" align="absmiddle" class="tex" alt="v_i < \vert\Sigma\vert" /> and <img src="http://blog.32leaves.net/wp-content/cache/tex_8ca14f3cd55ec200100499ad5b63110b.gif" align="absmiddle" class="tex" alt="v\in \{ k: 0\leq k < \vert\Sigma\vert \}^n" />.
</td>
</tr>
</table>
</div>
<div class="p">
So the mapping <img src="http://blog.32leaves.net/wp-content/cache/tex_800618943025315f869e4e1f09471012.gif" align="absmiddle" class="tex" alt="F" /> is surjective and does exactly what we want. I consider that solution to be a particular elegant one and wanted of post it for about a year now. Finally I found some spare time to do so. If you use that solution, find a mistake or find it somewhere else (maybe even previously described) please drop a comment.
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=933</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Soap Bubble Bot</title>
		<link>http://blog.32leaves.net/?p=921</link>
		<comments>http://blog.32leaves.net/?p=921#comments</comments>
		<pubDate>Fri, 02 Jul 2010 14:51:14 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Studies]]></category>
		<category><![CDATA[LM3S6965]]></category>
		<category><![CDATA[soap bubbles]]></category>
		<category><![CDATA[TeachRobot]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=921</guid>
		<description><![CDATA[During my studies at the HFU, I have to participate in at least two semester projects. This time we built a new USB interface for some pretty old hardware. That old hardware is a robot arm built in 80&#8242;s (there is &#8220;Made in West Germany&#8221; written on it). I&#8217;ve blogged about it before. Today we [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
During my studies at the HFU, I have to participate in at least two semester projects. This time we built a new USB interface for some pretty old hardware. That old hardware is a robot arm built in 80&#8242;s (there is &#8220;Made in West Germany&#8221; written on it). I&#8217;ve <a href="/?p=817">blogged about it before</a>.</div>
<div class="p">
Today we got to present our work. But how do you show something as abstract as interface hardware/software? So we came up with that demo which we consider pretty neat: we taught the robot arm to make soap bubbles. Well, we used a bunch of ruby scripts to grad the events generated by a gamepad (HID device) and interpreted them, so that one can control the arm. We also taped something (I&#8217;d call a soap bubble device) at the front of robot. Add some of the soap fluid and we could&#8217;ve made soap bubbles manually. But that&#8217;s too easy. So we added a sequence of positions (one of the firmware&#8217;s features) and used that to do the work. Video&#8217;s after the break.
</div>
<div class="p" style="text-align: center">
<object width="720" height="405"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13034200&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13034200&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="405"></embed></object>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=921</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LogicAnalyzer &#8211; extensible logic debugging</title>
		<link>http://blog.32leaves.net/?p=912</link>
		<comments>http://blog.32leaves.net/?p=912#comments</comments>
		<pubDate>Tue, 29 Jun 2010 22:50:50 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[LogicAnalyzer]]></category>
		<category><![CDATA[SourceForge]]></category>
		<category><![CDATA[SUMP]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=912</guid>
		<description><![CDATA[In the past few months it has become quite on this blog. That&#8217;s not because I wasn&#8217;t involved in any activity, but rather because I was too involved in one (building a quadrocopter). During that particular activity we started using a logic analyzer. There is a great open source project building such a device (originally [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
In the past few months it has become quite on this blog. That&#8217;s not because I wasn&#8217;t involved in any activity, but rather because I was too involved in one (building a quadrocopter). During that particular activity we started using a logic analyzer. There is a <a href="http://www.gadgetfactory.net/gf/project/butterflylogic/">great open source project</a> building such a device (originally <a href="http://www.sump.org/projects/analyzer/">here</a>). Unfortunately for quite some time it was out of stock. So we set on to build one ourselves. In that process I started writing some client software for it, since there was a lack of extensible, open source, logic analyzer client software. In the meantime, the <a href="http://www.gadgetfactory.net/gf/project/butterflylogic/">Open Workbench Logic Sniffer</a> was <a href="http://www.seeedstudio.com/depot/open-workbench-logic-sniffer-p-612.html?cPath=61_68">in stock</a> again. So we ordered two of them. At the time they arrived, the <a href="http://logicanalyzer.sourceforge.net/">LogicAnalyzer</a> was pretty much usable.
</div>
<div class="p">
While designing the <a href="http://logicanalyzer.sourceforge.net/">LogicAnalyzer</a>, I had three major goals in mind:</p>
<ol>
<li>Extensibility: integrating new devices should be as easy as possible. Generally speaking, integrating any kind of data source should be easy.</li>
<li>Clean UI: some logic analyzer client software that is around has a pretty cluttered UI. The LogicAnalyzer UI should be clean and intuitive.</li>
<li>Architecture: in order to achieve the required extensibility and to enhance maintainability, a good and clean architecture is required.</li>
</ol>
<p>All goals have been met (although one might discuss how well goal three has been reached &#8211; that&#8217;s in the eye of the beholder).
</p></div>
<div class="p">
<a href="http://logicanalyzer.sourceforge.net/">LogicAnalyzer</a> is built using the Eclipse Rich Client Platform. This powerful platform provides mechanisms to extend applications built using it. So we&#8217;re using the extension point mechanism of Eclipse to provide the required extensibility. Special focus has been put on a clean API and unobtrusive interfaces. By using Eclipse RCP, we also gain multi-platform support. LA runs on Mac OSX, Linux and Windows.<br />
<br />
The clean UI is achieved by only showing what&#8217;s currently required. When you open <a href="http://logicanalyzer.sourceforge.net/">LogicAnalyzer</a>, all you&#8217;ll see is the button to get you started. The tools integrated into the program may require a UI, which is only shown when they&#8217;re selected. We wanted to maximize the amount of pixels available to show what&#8217;s really important: the data we&#8217;re visualizing.<br />
<br />
An important (but simple) rule during the design phase, has been a clear separation of concerns. Thus we&#8217;ve clearly separated UI from business logic. Most components are connected using Eclipse mechanisms (e.g. extension points). A lot has been designed against interfaces (where appropriate). Those measures resulted in a clean structure and good maintainability.
</div>
<div class="p">
If you want to know more (such as a list of features) or want to give it a try, I recommend that you have a look at <a href="http://logicanalyzer.sourceforge.net/">LogicAnalyzers homepage</a>. Some numbers for those interested: the initial commit was roughly 10k lines of code written in two weeks. Still, so far we&#8217;ve experienced only few (known but unfixed) bugs.
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=912</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making the world a safer place: self-verifying SMC</title>
		<link>http://blog.32leaves.net/?p=887</link>
		<comments>http://blog.32leaves.net/?p=887#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:18:05 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[DFA]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[verification]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=887</guid>
		<description><![CDATA[We all use code-generators, no matter if we love or hate them (or do both). But for most compilers you simply have to trust that they work correctly and do what they&#8217;re supposed to do. They typically do not provide any sort of proof for their correctness. Well, the SMC is different in that regard. [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
We all use code-generators, no matter if we love or hate them (or do both). But for most compilers you simply have to trust that they work correctly and do what they&#8217;re supposed to do. They typically do not provide any sort of proof for their correctness. Well, the <a href="http://blog.32leaves.net/?p=883">SMC</a> is different in that regard. It can generate verification code for its C backend.
</div>
<div class="p">
The idea of self-verifying compilers it not completely new. Several methods have been proposed for this task, <a href="http://en.wikipedia.org/wiki/Proof-Carrying_Code">proof-carying code</a> and <a href="http://portal.acm.org/citation.cfm?id=889016">credible compiler</a> to name a few. What I&#8217;m doing here is some mixture of both (with a bit more of the credible compiler &#8211; altough the SMC is no optimizing compiler, so there is only a single transformation involved). Basically once we generated C code out of the <a href="http://en.wikipedia.org/wiki/Finite-state_machine">FSM</a> description, we have two (possibly different) FSMs. The one we described and the one SMC generated. The intuitive perception of those two FSMs being equal, is that their languages (dented by <img src="http://blog.32leaves.net/wp-content/cache/tex_31483f4210c8a66e2a956c2464d34c0c.gif" align="absmiddle" class="tex" alt="\mathcal{L}(F)" />) are equal. But how do we show that?
</div>
<div class="p">
For our purpose it&#8217;s enough to show that the two transition functions are equal, as we only care about the generated FSM behaving exactly as the described one does. That still leaves us with the problem that we have to unobtrusively check the generated FSM.<br />
Let us define <img src="http://blog.32leaves.net/wp-content/cache/tex_af80d125e8d1788450e692bb07895662.gif" align="absmiddle" class="tex" alt="p=(t_1, \dots, t_n), t_i = ((s, \sigma), (s', A_{in}, A_{out}))\in\delta " /> to be a sequence of transitions (called path or trace). We&#8217;ll call a path <i>loop free</i> if <img src="http://blog.32leaves.net/wp-content/cache/tex_efc31c42ef6ba26aa1c440a6770b03c2.gif" align="absmiddle" class="tex" alt="\forall t: \neg\exists t': t = t' \vee s_t \neq s_{t'}" /> holds &#8211; meaning that there are no two transitions within a path having the same start state.<br />
Finally we accept the two FSMs to be equal iff for all loop-free paths in the original FSM, there exists an equivalent path in the generated machine. Following we accept the SMC to work correctly if the two FSMs (orignal one and generated one) are equal.
</div>
<div class=p>
Generating the traces of the original FSM is a rather trivial task. We already have a good structure to work on (the SMC AST). That&#8217;s not the case with the generated FSM. First of all generating the trace must be unobtrusive. We must be sure that our instrumentation does alter the behavior of the FSM. We can accept that a statement of the form</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;12345678&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>generally does not alter the behavior, if placed appropriate. So we simply place print statements (with a unique ID) at each transition and action. Then we generate code that causes the FSM to transit along the previously determined paths.<br />
If everything goes right, executing that code should cause a sequence of IDs to be printed. In case the SMC works correctly that sequence should be identical to those produced by traces of the original FSM.
</div>
<div class="p">
To use this verification mechanism, run the SMC with the <tt>cverify</tt> backend and execute the generated <tt>_checker.sh</tt> script. That script either ends with &#8220;NO ERRORS FOUND&#8221; (which should always be the case), with a list of traces which the generated FSM did not perform. Additionally a <tt>checker.log</tt> file is generated which contains entries like this:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#006600; font-weight:bold;">&#93;</span> AST_Transition<span style="color:#006600; font-weight:bold;">&#40;</span>_INIT,RT,List<span style="color:#006600; font-weight:bold;">&#40;</span>AST_ConstEqCondition<span style="color:#006600; font-weight:bold;">&#40;</span>CMD__MODE__RT<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,AST_Actions<span style="color:#006600; font-weight:bold;">&#40;</span>Some<span style="color:#006600; font-weight:bold;">&#40;</span>List<span style="color:#006600; font-weight:bold;">&#40;</span>clr<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,None<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> AST_Transition<span style="color:#006600; font-weight:bold;">&#40;</span>RT,_ERR,List<span style="color:#006600; font-weight:bold;">&#40;</span>AST_NegatedCondition<span style="color:#006600; font-weight:bold;">&#40;</span>AST_PredicateCondition<span style="color:#006600; font-weight:bold;">&#40;</span>command<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,AST_Actions<span style="color:#006600; font-weight:bold;">&#40;</span>None,None<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">&#91;</span>!<span style="color:#006600; font-weight:bold;">&#93;</span> A98601 T<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">93118478</span> T<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1152986909</span> ;<br />
<span style="color:#006600; font-weight:bold;">&#91;</span>?<span style="color:#006600; font-weight:bold;">&#93;</span> A98601 T<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">93118478</span> T<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1152986909</span> ;</div></td></tr></tbody></table></div>
<p>where the line marked by the exclamation mark denote the trace of  the original FSM, as opposed to question mark which marks trace of the generated FSM.
</p></div>
<div class="p">
Ahh, and there is yet another new feature, the SMC can now generate a <a href="http://nusmv.irst.itc.it/">NuSMV</a> model. Of course that&#8217;s all in the <a href="https://guest:guest@hs.32leaves.net/svn/misc/TeachRobotArm/trunk/StateMachine/">repository</a>.
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=887</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>State machine compiler</title>
		<link>http://blog.32leaves.net/?p=883</link>
		<comments>http://blog.32leaves.net/?p=883#comments</comments>
		<pubDate>Sun, 21 Feb 2010 20:28:33 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Studies]]></category>
		<category><![CDATA[DFA]]></category>
		<category><![CDATA[SMC]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=883</guid>
		<description><![CDATA[As mentioned in one my previous posts, next semester I&#8217;m going to participate in a project where we&#8217;re supposed to build a new interface to existing roboting hardware. To describe the protocol that is spoken between the computer and that hardware interface, I wanted to use some sort of DFA. I also wanted avoid having [...]]]></description>
			<content:encoded><![CDATA[<div class="p">As mentioned in one my previous posts, next semester I&#8217;m going to participate in a project where we&#8217;re supposed to build a new interface to existing roboting hardware. To describe the protocol that is spoken between the computer and that hardware interface, I wanted to use some sort of <a href="http://en.wikipedia.org/wiki/Deterministic_finite-state_machine">DFA</a>. I also wanted avoid having to implement that DFA in the different programming languages involved in the project. Especially since such implementations tend to diverge over time.</div>
<div class="p">
So I sat down and wrote something I call the <em>state machine compiler</em>. It allows the specification of a so called <em>predicate deterministic finite automaton</em>. Such a PDFA can be compiled to C or Java code &#8211; or to whichever language one writes a backend for. I won&#8217;t go into detail here, as I&#8217;ve written <a href="https://guest:guest@hs.32leaves.net/svn/misc/TeachRobotArm/trunk/StateMachine/doc/Manual.pdf">a manual</a> which explains everything in detail.
</div>
<div class="p">
You can grab the <a href="https://guest:guest@hs.32leaves.net/svn/misc/TeachRobotArm/trunk/StateMachine/">source code from subversion</a> (username: guest, password: guest). As usual it&#8217;s published under CC-BY-SA. Be aware that this is considered work in progress, so the generated code may still be far from being optimal.
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=883</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating syntax diagrams from Scala parser combinators</title>
		<link>http://blog.32leaves.net/?p=861</link>
		<comments>http://blog.32leaves.net/?p=861#comments</comments>
		<pubDate>Wed, 17 Feb 2010 23:54:12 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Studies]]></category>
		<category><![CDATA[EBNF]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[syntax diagrams]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=861</guid>
		<description><![CDATA[Scala parser combinators are a powerful concept which allow you to write parsers with the standard Scala distribution. They&#8217;re implemented as an internal DSL which makes them feel naturally in the language. As mentioned before I&#8217;m currently writing some sort of a state machine compiler. As I plan to write some documentation for that software [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
<a href="http://www.codecommit.com/blog/scala/the-magic-behind-parser-combinators">Scala parser combinators</a> are a powerful concept which allow you to write parsers with the <a href="http://www.scala-lang.org/">standard Scala distribution</a>. They&#8217;re implemented as an internal <a href="http://en.wikipedia.org/wiki/Domain_Specific_Language">DSL</a> which makes them feel naturally in the language. As mentioned <a href="http://blog.32leaves.net/?p=817">before</a> I&#8217;m currently writing some sort of a state machine compiler. As I plan to write some documentation for that software (which actually is kind of rare <img src='http://blog.32leaves.net/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ) I need some way to describe the syntax. Besides <a href="http://en.wikipedia.org/wiki/Extended_Backus–Naur_Form">EBNF</a>, <a href="http://en.wikipedia.org/wiki/Syntax_diagram">syntax diagrams</a> are a neat way to do that. The external DSL which is used to describe the state machines is directly written using the parser combinator, so I had figure out a way to generate syntax diagrams as well as EBNF out of them.
</div>
<div class="p">
My first approach was to pattern match the resulting Parser structure. But unfortunately the combinators themselves are mostly modeled as a function, thus do not appear in the resulting object graph. So I decided to write a Scala compiler plugin and run thru the AST. Basically all this software does is to transform trees from the AST to some intermediate expression structure to a graphing tree one. This approach suffers some limitations and I made some assumptions as well:</p>
<ul>
<li>The name of the class which contains the production rules must equal the filename without &#8220;.scala&#8221;</li>
<li>Production rules must not be named: &#8220;stringWrapper&#8221;, &#8220;literal&#8221;, &#8220;regex&#8221;, &#8220;Predef&#8221;, &#8220;r&#8221; or &#8220;accept&#8221;</li>
<li>def production rules must not have parameters, otherwise they&#8217;re not considered to be production rules</li>
<li>production rules defined via <em>val</em> will appear twice (this is most likely a bug)</li>
</ul>
<p>All in all this implementation works in my case, but might not work for others. This more of a quick hack than carefully engineered software, but it proofs the concept and gets the job done.
</p></div>
<div class="p">
With the ability to draw syntax diagrams and having the expression tree structure at hand (which can be seen as an AST for EBNF) writing an EBNF parser (which is semi <a href="http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf">ISO/IEC 14977 : 1996(E)</a> compatible) and feeding the diagram generator with the result was a snap.
</div>
<div class="p">
So let&#8217;s consider the following example (which actually is the EBNF parser I wrote):</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> start<span style="color: #000080;">:</span> Parser<span style="color: #F78811;">&#91;</span>List<span style="color: #F78811;">&#91;</span>ProductionRule<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> syntax<span style="color: #000080;">_</span>rule<span style="color: #000080;">*</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> syntax<span style="color: #000080;">_</span>rule <span style="color: #000080;">=</span> meta<span style="color: #000080;">_</span>identifier ~ <span style="color: #6666FF;">'='</span> ~ definitions<span style="color: #000080;">_</span>list ~ <span style="color: #6666FF;">';'</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> name ~ <span style="color: #000080;">_</span> ~ expr ~ <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span> ProductionRule<span style="color: #F78811;">&#40;</span>name, expr<span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> meta<span style="color: #000080;">_</span>identifier <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;&quot;</span><span style="color: #6666FF;">&quot;[a-zA-Z0-9]+&quot;</span><span style="color: #6666FF;">&quot;&quot;</span>r<br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> definitions<span style="color: #000080;">_</span>list<span style="color: #000080;">:</span>Parser<span style="color: #F78811;">&#91;</span>Expression<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#40;</span>single<span style="color: #000080;">_</span>definition ~ <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">'|'</span> ~ single<span style="color: #000080;">_</span>definition<span style="color: #F78811;">&#41;</span><span style="color: #000080;">*</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> t ~ o <span style="color: #000080;">=&gt;</span> OrExpression<span style="color: #F78811;">&#40;</span>t <span style="color: #000080;">::</span> o.<span style="color: #000000;">map</span><span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span> <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">match</span></a> <span style="color: #F78811;">&#123;</span> <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> <span style="color: #000080;">_</span> ~ x <span style="color: #000080;">=&gt;</span> x <span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> single<span style="color: #000080;">_</span>definition <span style="color: #000080;">=</span> <span style="color: #F78811;">&#40;</span>primary ~ <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;,&quot;</span><span style="color: #000080;">?</span><span style="color: #F78811;">&#41;</span> ~ primary<span style="color: #F78811;">&#41;</span><span style="color: #000080;">*</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> t ~ o <span style="color: #000080;">=&gt;</span> SeqExpression<span style="color: #F78811;">&#40;</span>t <span style="color: #000080;">::</span> o.<span style="color: #000000;">map</span><span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span> <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">match</span></a> <span style="color: #F78811;">&#123;</span> <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> <span style="color: #000080;">_</span> ~ x <span style="color: #000080;">=&gt;</span> x <span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> primary<span style="color: #000080;">:</span> Parser<span style="color: #F78811;">&#91;</span>Expression<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> optional<span style="color: #000080;">_</span>sequence | repeated<span style="color: #000080;">_</span>sequence | grouped<span style="color: #000080;">_</span>sequence | terminal<span style="color: #000080;">_</span>string | meta<span style="color: #000080;">_</span>identifier ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> s <span style="color: #000080;">=&gt;</span> RuleRefExpression<span style="color: #F78811;">&#40;</span>s<span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> optional<span style="color: #000080;">_</span>sequence <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;[&quot;</span> ~ definitions<span style="color: #000080;">_</span>list ~ <span style="color: #6666FF;">&quot;]&quot;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> <span style="color: #000080;">_</span> ~ os ~ <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span> OptionExpression<span style="color: #F78811;">&#40;</span>os<span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> repeated<span style="color: #000080;">_</span>sequence <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;{&quot;</span> ~ definitions<span style="color: #000080;">_</span>list ~ <span style="color: #6666FF;">&quot;}&quot;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> <span style="color: #000080;">_</span> ~ rs ~ <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span> ZeroToManyExpression<span style="color: #F78811;">&#40;</span>rs<span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> grouped<span style="color: #000080;">_</span>sequence <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;(&quot;</span> ~ definitions<span style="color: #000080;">_</span>list ~ <span style="color: #6666FF;">&quot;)&quot;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> <span style="color: #000080;">_</span> ~ gs ~ <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span> gs<br />
<span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> terminal<span style="color: #000080;">_</span>string <span style="color: #000080;">=</span> <span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;&quot;</span><span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#91;</span>^<span style="color: #6666FF;">&quot;<span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">\r</span><span style="color: #0000ff; font-weight: bold;">\n</span>]*(?:<span style="color: #0000ff; font-weight: bold;">\\</span>.[^&quot;</span>\\\r\n<span style="color: #F78811;">&#93;</span><span style="color: #000080;">*</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">*</span><span style="color: #6666FF;">&quot; &quot;</span><span style="color: #6666FF;">&quot;&quot;</span>r<span style="color: #F78811;">&#41;</span> ^^ <span style="color: #F78811;">&#123;</span><br />
&nbsp; <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">case</span></a> s <span style="color: #000080;">=&gt;</span> LiteralExpression<span style="color: #F78811;">&#40;</span>s<span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span></div></td></tr></tbody></table></div>
<p>The corresponding EBNF expression generated by this software is:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">start <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> syntax_rule <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
syntax_rule <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'[a-zA-Z0-9]+'</span> <span style="color: #0000ff;">'='</span> <span style="color: #009900;">&#40;</span> single_definition <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span> single_definition <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">';'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
meta_identifier <span style="color: #339933;">=</span> <span style="color: #0000ff;">'[a-zA-Z0-9]+'</span><span style="color: #339933;">;</span><br />
definitions_list <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> primary <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">','</span> <span style="color: #009900;">&#93;</span> primary <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span> single_definition <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
single_definition <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> optional_sequence <span style="color: #339933;">|</span> repeated_sequence <span style="color: #339933;">|</span> grouped_sequence <span style="color: #339933;">|</span> terminal_string <span style="color: #339933;">|</span> meta_identifier <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">','</span> <span style="color: #009900;">&#93;</span> primary <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
primary <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'['</span> definitions_list <span style="color: #0000ff;">']'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'{'</span> definitions_list <span style="color: #0000ff;">'}'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'('</span> definitions_list <span style="color: #0000ff;">')'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">'&quot;[^&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>]*(?:<span style="color: #000099; font-weight: bold;">\\</span>.[^&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>]*)*&quot; '</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">'[a-zA-Z0-9]+'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
optional_sequence <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'['</span> <span style="color: #009900;">&#40;</span> single_definition <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span> single_definition <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">']'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
repeated_sequence <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'{'</span> <span style="color: #009900;">&#40;</span> single_definition <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span> single_definition <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">'}'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
grouped_sequence <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'('</span> <span style="color: #009900;">&#40;</span> single_definition <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span> single_definition <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">')'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
terminal_string <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&quot;[^&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>]*(?:<span style="color: #000099; font-weight: bold;">\\</span>.[^&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>]*)*&quot; '</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>And of course the syntax diagrams we wanted:<br />

<a href='http://blog.32leaves.net/?attachment_id=876' title='terminal_string'><img width="150" height="51" src="http://blog.32leaves.net/wp-content/uploads/2010/02/terminal_string-150x51.png" class="attachment-thumbnail" alt="terminal_string" title="terminal_string" /></a>
<a href='http://blog.32leaves.net/?attachment_id=875' title='term'><img width="150" height="150" src="http://blog.32leaves.net/wp-content/uploads/2010/02/term-150x150.png" class="attachment-thumbnail" alt="term" title="term" /></a>
<a href='http://blog.32leaves.net/?attachment_id=874' title='syntax_rule'><img width="150" height="91" src="http://blog.32leaves.net/wp-content/uploads/2010/02/syntax_rule-150x91.png" class="attachment-thumbnail" alt="syntax_rule" title="syntax_rule" /></a>
<a href='http://blog.32leaves.net/?attachment_id=873' title='start'><img width="136" height="91" src="http://blog.32leaves.net/wp-content/uploads/2010/02/start.png" class="attachment-thumbnail" alt="start" title="start" /></a>
<a href='http://blog.32leaves.net/?attachment_id=872' title='single_definition'><img width="150" height="150" src="http://blog.32leaves.net/wp-content/uploads/2010/02/single_definition-150x150.png" class="attachment-thumbnail" alt="single_definition" title="single_definition" /></a>
<a href='http://blog.32leaves.net/?attachment_id=871' title='repeated_sequence'><img width="150" height="91" src="http://blog.32leaves.net/wp-content/uploads/2010/02/repeated_sequence-150x91.png" class="attachment-thumbnail" alt="repeated_sequence" title="repeated_sequence" /></a>
<a href='http://blog.32leaves.net/?attachment_id=870' title='primary'><img width="150" height="150" src="http://blog.32leaves.net/wp-content/uploads/2010/02/primary-150x150.png" class="attachment-thumbnail" alt="primary" title="primary" /></a>
<a href='http://blog.32leaves.net/?attachment_id=869' title='optional_sequence'><img width="150" height="91" src="http://blog.32leaves.net/wp-content/uploads/2010/02/optional_sequence-150x91.png" class="attachment-thumbnail" alt="optional_sequence" title="optional_sequence" /></a>
<a href='http://blog.32leaves.net/?attachment_id=868' title='meta_identifier'><img width="112" height="51" src="http://blog.32leaves.net/wp-content/uploads/2010/02/meta_identifier.png" class="attachment-thumbnail" alt="meta_identifier" title="meta_identifier" /></a>
<a href='http://blog.32leaves.net/?attachment_id=867' title='grouped_sequence'><img width="150" height="91" src="http://blog.32leaves.net/wp-content/uploads/2010/02/grouped_sequence-150x91.png" class="attachment-thumbnail" alt="grouped_sequence" title="grouped_sequence" /></a>
<a href='http://blog.32leaves.net/?attachment_id=865' title='definitions_list'><img width="150" height="111" src="http://blog.32leaves.net/wp-content/uploads/2010/02/definitions_list-150x111.png" class="attachment-thumbnail" alt="definitions_list" title="definitions_list" /></a>

</p></div>
<div class="p">
So far the syntax diagram generator understands two options:</p>
<ul>
<li><tt>-P:virtual:rule01,...,ruleN</tt>: declares rule01,&#8230;,ruleN to be virtual rules which causes them to be resolved wherever they&#8217;re referenced. Be aware that recursive virtual rules are only resolved to one level</li>
<li><tt>-P:depth:N</tt>: resolve rule references until a depth of <tt>N</tt> (recursive rules are only resolved for one level)</li>
</ul>
</div>
<div class="p">
If you&#8217;re interested in the code you can grab it from <a href="https://hs.32leaves.net/svn/misc/TeachRobotArm/trunk/SyntaxDiagramGenerator/">this SVN repository</a> (username: <em>guest</em>, password: <em>guest</em>). You&#8217;ll need Scala as well as Batik to run it.<br />
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/InteractiveResource" property="dc:title" rel="dc:type">SyntaxDiagramGenerator</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=861</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualizing Sorting Algorithms &#8211; my shot</title>
		<link>http://blog.32leaves.net/?p=832</link>
		<comments>http://blog.32leaves.net/?p=832#comments</comments>
		<pubDate>Mon, 08 Feb 2010 02:28:33 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Studies]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=832</guid>
		<description><![CDATA[These days I have to write some sort of reference card for basic sorting algorithms. Of course I wanted some sort of visualization of those algorithms on that card. The coolest sorting algorithm visualization I&#8217;ve seen so far has been created by Aldo Cortesi. He used Cairo to draw his stuff (according to his post [...]]]></description>
			<content:encoded><![CDATA[<div class="p">
These days I have to write some sort of reference card for basic sorting algorithms. Of course I wanted some sort of visualization of those algorithms on that card. The <a href="http://corte.si/posts/code/visualisingsorting/index.html">coolest sorting algorithm visualization</a> I&#8217;ve seen so far has been created by <a href="http://corte.si">Aldo Cortesi</a>. He used <a href="http://cairographics.org/">Cairo</a> to draw his stuff (according to his post learning <a href="http://cairographics.org/">Cairo</a> was the whole point of this excercise).
</div>
<div class="p">
Personally I still found those diagrams pretty hard to read if you really wanted to follow the algorithm. And of course I wanted to do something with Cairo, too. So I decided to rewrite the whole thing in C. My version shows distinct sections for each loop iteration (as most of those algorithms can be followed by thinking in that iterative loop way). In the diagrams below each number denotes the <em>loop nesting level</em> while <tt>B</tt> stands for being and <tt>E</tt> for end.
</div>
<div class="p">
The source can be downloaded <a href="http://blog.32leaves.net/wp-content/uploads/2010/02/sortingAlgVisualization.zip">here</a> and is under <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>.
</div>
<div class="p">
<a href="http://en.wikipedia.org/wiki/Insertionsort">Insertion sort</a>:</p>
<div style="text-align: center"><a href="http://blog.32leaves.net/wp-content/uploads/2010/02/insertion.png" rel="lightbox[832]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/02/insertion.png" alt="" title="insertion" width="700" height="250" class="aligncenter size-full wp-image-835" /></a></div>
<p><a href="http://en.wikipedia.org/wiki/Selection_sort">Selection sort</a>:</p>
<div style="text-align: center"><a href="http://blog.32leaves.net/wp-content/uploads/2010/02/selection.png" rel="lightbox[832]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/02/selection.png" alt="" title="selection" width="700" height="250" class="aligncenter size-full wp-image-835" /></a></div>
<p><a href="http://en.wikipedia.org/wiki/Bubble_sort">Bubble sort</a>:</p>
<div style="text-align: center"><a href="http://blog.32leaves.net/wp-content/uploads/2010/02/bubble.png" rel="lightbox[832]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/02/bubble.png" alt="" title="bubble" width="700" height="250" class="aligncenter size-full wp-image-835" /></a></div>
<p><a href="http://en.wikipedia.org/wiki/Shell_sort">Shell sort (<img src="http://blog.32leaves.net/wp-content/cache/tex_9b9401bd974f63a9bfe677bdd26b82a8.gif" align="absmiddle" class="tex" alt="k=\dots, 132, 57, 23, 10, 4, 1" />)</a>:</p>
<div style="text-align: center"><a href="http://blog.32leaves.net/wp-content/uploads/2010/02/shell.png" rel="lightbox[832]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/02/shell.png" alt="" title="shell" width="700" height="250" class="aligncenter size-full wp-image-835" /></a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=832</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling a robot arm using an ez430 Chronos</title>
		<link>http://blog.32leaves.net/?p=817</link>
		<comments>http://blog.32leaves.net/?p=817#comments</comments>
		<pubDate>Wed, 03 Feb 2010 01:31:02 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ez430]]></category>
		<category><![CDATA[TeachRobot]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=817</guid>
		<description><![CDATA[A few days ago the ez430 Chronos I ordered from Farnell was delivered. This particular piece of hardware is an evaluation platform for the MSP430 (or the MSP430 as a CC430F6137 SoC to be more precise) which comes as a sports watch. It&#8217;s got some pretty neat features such as a temperature sensor, accelerometers on [...]]]></description>
			<content:encoded><![CDATA[<div class="p" style="text-align: center">
<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/KwGtTwsyrW0&#038;hl=de_DE&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/KwGtTwsyrW0&#038;hl=de_DE&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></div>
<div class="p">A few days ago the <a href="http://www.ti-estore.com/Merchant2/merchant.mvc?Screen=PROD&#038;Product_Code=EZ430-Chronos-868">ez430 Chronos</a> I ordered from <a href="http://farnell.com">Farnell</a> was delivered. This particular piece of hardware is an evaluation platform for the <a href="http://en.wikipedia.org/wiki/TI_MSP430">MSP430</a> (or the MSP430 as a <a href="http://focus.ti.com/docs/prod/folders/print/cc430f6137.html">CC430F6137</a> SoC to be more precise) which comes as a sports watch. It&#8217;s got some pretty neat features such as a temperature sensor, accelerometers on all three axis (which is why I&#8217;m using it here) and an RF transceiver built in. The first thing I did to it was to enable the watch to display the current time binary encoded.
</div>
<div class="p">After getting this to work (which was not that hard at all) I moved on to trying to get some data using the RF link. In the <a href="http://wiki.msp430.com/index.php/EZ430-Chronos">ez430 Chronos Wiki</a> someone posted a <a href="http://wiki.msp430.com/index.php/EZ430-Chronos#PC.2FChronos_Communication">Python program</a> which polls the RF hub for accelerometer data. Having a Mac and not wanting to spend hours on getting pyserial to work, I wrote my own version in Ruby.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<br />
<span style="color:#008000; font-style:italic;"># on my machine a simple require does not work for this library</span><br />
<span style="color:#CC00FF; font-weight:bold;">Kernel</span>.<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'serialport'</span><br />
<br />
<br />
SERIAL = SerialPort.<span style="color:#9900CC;">new</span> ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006666;">115200</span><br />
SERIAL.<span style="color:#9900CC;">read_timeout</span> = <span style="color:#006666;">1000</span><br />
<span style="color:#9966CC; font-weight:bold;">def</span> serial<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span>; data.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> SERIAL.<span style="color:#CC0066; font-weight:bold;">putc</span><span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>; SERIAL.<span style="color:#9900CC;">flush</span> <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># start access point</span><br />
serial<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>0xFF, 0x07, 0x03<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># request the data</span><br />
&nbsp; serial<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; accel = SERIAL.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">7</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> accel.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; accel = accel.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> c<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> accel<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> accel<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">4</span>..6<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; STDOUT.<span style="color:#9900CC;">flush</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
SERIAL.<span style="color:#9900CC;">close</span></div></td></tr></tbody></table></div>
<p>That&#8217;s pretty nice, but I wanted some real time graphs of the data, so a half an hour later I got a short Processing sketch running which does exactly that.</p>
<div style="text-align: center"><a href="http://blog.32leaves.net/wp-content/uploads/2010/02/Bild-1.png" rel="lightbox[817]"><img src="http://blog.32leaves.net/wp-content/uploads/2010/02/Bild-1-300x233.png" alt="" title="Processing sketch showing accelerometer data retrieved from an ez430 Chronos" width="300" height="233" class="aligncenter size-medium wp-image-823" /></a></div>
</div>
<div class="p">
Next semester I&#8217;ll participate in a project in which we&#8217;ll built a new hardware interface to some pretty old robot arm hardware (it states &#8220;Made in West Germany&#8221;, that&#8217;s quite some time ago). In order to do that we need some sort of protocol to communicate with the new hardware interface. In preparation for that project I wrote a simulator for the robot (actually that&#8217;s supposed to be a part of the project, but I simply couldn&#8217;t resist) which uses an early draft of that particular protocol. Just to have that mentioned, the protocol itself is described as a state machine in a <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> which can be compiled to virtually any programming language. I&#8217;ll probably write a post about that nice piece of Scala code at some later time.</div>
<div class="p">
So with a working robot arm simulator,  a watch which has accelerometers built in and is capable of wireless communication what else could I&#8217;ve done than to combine those two. That said I got to work and enhanced the script above to communicate with the simulator. About an hour later I got the first movements controlled by the accelerometer data of the watch. You might have seen the video already, if not go and watch it <img src='http://blog.32leaves.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
</div>
<div class="p">
<b>Update: </b> We had some spare time to spent and did some really basic proof of concept with the real hardware. Here we go:</p>
<div style="text-align: center">
<object width="640" height="505"><param name="movie" value="http://www.youtube-nocookie.com/v/SDG9dqrxRQg&#038;hl=de_DE&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/SDG9dqrxRQg&#038;hl=de_DE&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=817</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Readonly hardware IRC client</title>
		<link>http://blog.32leaves.net/?p=805</link>
		<comments>http://blog.32leaves.net/?p=805#comments</comments>
		<pubDate>Wed, 27 Jan 2010 22:28:54 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[LM3S6965]]></category>
		<category><![CDATA[Luminary]]></category>

		<guid isPermaLink="false">http://blog.32leaves.net/?p=805</guid>
		<description><![CDATA[Right after we got the network running on my board (see my previous post) I got the board of the talented hacker mentioned before and started to hack a small read-only IRC client for it (after having a look at RFC1459 and RFC2812. About an hour later I was able to connect to a server, [...]]]></description>
			<content:encoded><![CDATA[<div class="p">Right after we got the network running on my board (see my <a href="http://blog.32leaves.net/?p=789">previous post</a>) I got the board of the talented hacker mentioned before and started to hack a small read-only IRC client for it (after having a look at <a href="http://tools.ietf.org/html/rfc1459">RFC1459</a> and <a href="http://tools.ietf.org/html/rfc2812">RFC2812</a>. About an hour later I was able to connect to a server, join a channel and listen for messages which are displayed on the OLED display. Unfortunately the display is broken on that particular board. But none the less, there is a lot of cool stuff ahead.
</div>
<div class="p">
Again we have some screenshots:<br />

<a href='http://blog.32leaves.net/?attachment_id=813' title='2010-01-27 23.49.52'><img width="150" height="150" src="http://blog.32leaves.net/wp-content/uploads/2010/01/2010-01-27-23.49.52-150x150.jpg" class="attachment-thumbnail" alt="2010-01-27 23.49.52" title="2010-01-27 23.49.52" /></a>
<a href='http://blog.32leaves.net/?attachment_id=812' title='2010-01-27 23.17.37'><img width="150" height="150" src="http://blog.32leaves.net/wp-content/uploads/2010/01/2010-01-27-23.17.37-150x150.jpg" class="attachment-thumbnail" alt="2010-01-27 23.17.37" title="2010-01-27 23.17.37" /></a>

</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.32leaves.net/?feed=rss2&amp;p=805</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
