<?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>eclecticc &#187; python</title>
	<atom:link href="http://eclecti.cc/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://eclecti.cc</link>
	<description></description>
	<lastBuildDate>Sun, 05 Sep 2010 20:47:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Easy Absolute Orientation: PNI SpacePoint Fusion in Python</title>
		<link>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python</link>
		<comments>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python#comments</comments>
		<pubDate>Mon, 01 Feb 2010 08:42:21 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[imu]]></category>
		<category><![CDATA[magnetometer]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[spacepoint fusion]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=414</guid>
		<description><![CDATA[My college roommate Donnie mentioned the PNI SpacePoint Fusion in comments of the HMC5843 post, and it seemed too good to be true.  A 9 DOF controller (3 axes each of magnetometer, accelerometer, and gyro) with a Kalman filter to calculate a smooth quaternion that interfaces as a USB HID device, all for under $100.  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclecti.cc/files/2010/01/spacepoint.jpg"><img class="alignnone size-large wp-image-439" title="That is the cel shading tutorial from Panda3D, with the character quaternion set by the SpacePoint Fusion." src="http://eclecti.cc/files/2010/01/spacepoint-700x525.jpg" alt="SpacePoint Fusion" width="700" height="525" /></a></p>
<p>My college roommate Donnie mentioned the <a href="http://www.pnicorp.com/products/all/spacepoint-fusion">PNI SpacePoint Fusion</a> in comments of the <a href="http://eclecti.cc/hardware/hmc5843-magnetometer-library-for-arduino">HMC5843 post</a>, and it seemed too good to be true.  A 9 DOF controller (3 axes each of magnetometer, accelerometer, and gyro) with a <a href="http://en.wikipedia.org/wiki/Kalman_filter">Kalman filter</a> to calculate a smooth quaternion that interfaces as a USB HID device, all for under $100.  I&#8217;d be surprised if PNI is making any profit on it.  I sound more like a shill than I&#8217;m normally comfortable with, but I&#8217;m truly impressed with this gadget.  I have some plans for it involving a <a href="http://www.microvision.com/showwx/">Microvision SHOWWX</a> that I&#8217;m quite excited about; I&#8217;ll write more on that when it&#8217;s available in a couple of months.</p>
<p><a href="http://eclecti.cc/files/2010/01/innards.jpg"><img class="alignnone size-large wp-image-442" title="There's a mini usb port inside too, how convenient!" src="http://eclecti.cc/files/2010/01/innards-700x525.jpg" alt="SpacePoint Fusion Innards" width="700" height="525" /></a></p>
<p>PNI provides some Windows only <a href="http://www.pnicorp.com/support/downloads/spacepoint-fusion">sample apps</a> that show off how weirdly stable and precise the SpacePoint Fusion is.  Luckily, since it&#8217;s a normal USB HID device (redundant, I know), and PNI provides <a href="http://www.pnicorp.com/files/SpacePoint%20Fusion%20Game%20Pad%20Application%20Note.pdf">application notes</a>, it&#8217;s easy to use on any platform.  I wrote a Python module that uses <a href="http://libhid.alioth.debian.org/">libhid</a> via python-hid to make it easy to prototype with in Linux.  The usage is pretty simple, as shown below.  Note that when plugging the device in, you need to keep it still for a few seconds while the gyros are calibrated.  After that, the quaternion, accelerometer, and button data can be updated 62.5 times a second.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> spacepoint
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion = spacepoint.<span style="color: black;">SpacePoint</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">quat</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span><span style="color: #ff4500;">0.987518310546875</span>, -<span style="color: #ff4500;">0.04425048828125</span>, -<span style="color: #ff4500;">0.04119873046875</span>, <span style="color: #ff4500;">0.145294189453125</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">accel</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span>-<span style="color: #ff4500;">0.054016113354999999</span>, <span style="color: #ff4500;">0.018859863306999999</span>, -<span style="color: #ff4500;">0.89648437622400001</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">buttons</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion<span style="color: black;">&#41;</span>
accel: <span style="color: black;">&#40;</span>-<span style="color: #ff4500;">0.054016113354999999</span>, <span style="color: #ff4500;">0.018859863306999999</span>, -<span style="color: #ff4500;">0.89648437622400001</span><span style="color: black;">&#41;</span>
 quat: <span style="color: black;">&#40;</span><span style="color: #ff4500;">0.97186279296875</span>, -<span style="color: #ff4500;">0.233428955078125</span>, -<span style="color: #ff4500;">0.030548095703125</span>, <span style="color: #ff4500;">0.005401611328125</span><span style="color: black;">&#41;</span>
 buttons: <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>Update on February 7, 2010:</strong> I emailed PNI about a bug in the firmware, and got the following response:</p>
<blockquote><p>Thank you for submitting the SpacePoint bug regarding libusb, Python, and Linux.  You&#8217;re right!  There is a bug in the SpacePoint FW that prevented opening interface 1 without opening interface 0 when using libusb under Linux.  While your work around was effective in allowing the device to operate normally, one should be able to open interface 1 directly without the work around.  We were able to use your Python source code to quickly diagnose and repair the bug.  Please see the attached for the modified Python script.  Please feel free to post this paragraph, the modified code, and all bragging rights on your blog (http://eclecti.cc/).</p></blockquote>
<p>Units being shipped now have the fix.  I modified the Python module to handle units both with and without the firmware fix and bumped the version to 0.2.</p>
<p><strong>Download:<a href="http://eclecti.cc/files/2010/02/spacepoint-0.2.tar.gz"><br />
SpacePoint Python Module</a></strong> or<br />
Standalone <strong><a href="http://eclecti.cc/files/2010/01/spacepoint.py">spacepoint.py</a></strong></p>
<h3>Setting udev rules to get the permissions right</h3>
<p>In most cases, the module will just work properly.  However, if you get the following error, you probably don&#8217;t have the right permissions to access the usb device.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> spacepoint
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion = spacepoint.<span style="color: black;">SpacePoint</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
hid_force_open failed <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">code</span> 12.</pre></div></div>

<p>On most modern Linux distros, you can fix this by setting a <a href="http://reactivated.net/writing_udev_rules.html">udev rule</a> for the device.  In Ubuntu Karmic Koala, saving the following as <code>/etc/udev/rules.d/45-spacepoint.rules</code> , running <code>sudo service udev restart</code> , and then unplugging and replugging in the device should fix it:</p>

<div class="wp_syntax"><div class="code"><pre class="cmake" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># PNI SpacePoint Fusion</span>
SYSFS{idVendor}==<span style="color: #912f11;">&quot;20ff&quot;</span>, SYSFS{idProduct}==<span style="color: #912f11;">&quot;0100&quot;</span>, MODE=<span style="color: #912f11;">&quot;0664&quot;</span>, GROUP=<span style="color: #912f11;">&quot;admin&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Deep Sheep: A Global Game Jam Entry</title>
		<link>http://eclecti.cc/videogames/deep-sheep-a-global-game-jam-entry</link>
		<comments>http://eclecti.cc/videogames/deep-sheep-a-global-game-jam-entry#comments</comments>
		<pubDate>Wed, 04 Feb 2009 05:35:36 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Video Games]]></category>
		<category><![CDATA[deep sheep]]></category>
		<category><![CDATA[global game jam]]></category>
		<category><![CDATA[panda3d]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=185</guid>
		<description><![CDATA[I spent last weekend at the Entertainment Technology Center (ETC) for the Global Game Jam, designing and programming a game about sheep.  The process of coming up with a game concept in our team of 7 randomly thrown together geeks (though we ended the weekend with 5 [attrition, not cannibalism {though I did get pretty [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" title="This picture is so much better with the sound effects." src="http://eclecti.cc/files/2009/02/deepsheep.png" alt="Deep Sheep" width="700" height="550" /></p>
<p style="text-align: left;">I spent last weekend at the <a href="http://www.etc.cmu.edu/" target="_blank">Entertainment Technology Center</a> (ETC) for the <a href="http://globalgamejam.org/" target="_blank">Global Game Jam</a>, designing and programming a game about sheep.  The process of coming up with a game concept in our team of 7 randomly thrown together geeks (though we ended the weekend with 5 [attrition, not cannibalism {though I did get pretty hungry from all the coding}]), was quite a whirlwind.  Somehow we started at a blob of mercury and ended with a dream in which you control an alarm clock being chased and covered by bouncy sheep.  The premise is that you&#8217;ve fallen asleep counting sheep, which follow you into your dream.  The sheep try to keep you in the dream forever by smothering the alarm clock and preventing it from ringing.  To win, you must knock all of the sheep off of the clock by ramming into obstacles or falling from heights, and then quickly roll back to the bed before any sheep catch up and reattach.  It plays a lot like a reverse <a href="http://en.wikipedia.org/wiki/Katamari_Damacy" target="_blank">Katamari Damacy</a>, though that was not necessarily the intent.</p>
<p style="text-align: left;">This is the second time I&#8217;ve done a 3d game, and this one came out far better than Robobear Apocalypse, an entry for the <a href="http://www.wildpockets.com/?mod=demo" target="_blank">Wild Pockets</a> Game Jam.  The engine this uses is <a href="http://panda3d.org/" target="_blank">Panda3D</a>, another product of the ETC.  It was actually quite nice to learn and use, and I was impressed by how well it worked cross-platform.  It helps that it uses regular old Python instead of proprietary languages that seem to be all the rage in game engines today.   I also learned just how nice it was to have modellers/animators on a game project.  Finally a game that isn&#8217;t made up of spheres, cubes, and stock models!</p>
<p style="text-align: left;">You can download the game on its <a href="http://globalgamejam.org/games/deep-sheep" target="_blank">Global Game Jam page</a>.  The <a href="http://globalgamejam.org/sites/default/files/user/Team%200Awesome/Deep%20Sheep.zip" target="_blank">.zip</a> on that page contains the source and a Windows installer.  You can also run the source directly in Linux or Windows if you have Panda3D installed.  It seems most distros have it available in their repos, but if not, there are <a href="http://panda3d.org/download.php" target="_blank">packages</a> downloadable at the Panda3D site.  It&#8217;ll run ok on just about anything that isn&#8217;t integrated graphics.   The game isn&#8217;t perfect and certainly isn&#8217;t bug free, but it is a fun light hearted experience and the result of only 48 hours of work.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/videogames/deep-sheep-a-global-game-jam-entry/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RocketPong &#8211; A One Button Game</title>
		<link>http://eclecti.cc/videogames/rocketpong-a-one-button-game</link>
		<comments>http://eclecti.cc/videogames/rocketpong-a-one-button-game#comments</comments>
		<pubDate>Fri, 26 Sep 2008 10:15:06 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Video Games]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=86</guid>
		<description><![CDATA[I couldn&#8217;t sleep, so I decided to write a quick entry for the Game Creation Society&#8216;s One Button Game Compo. It requires Pygame 1.8, which can be installed through a package manager on many distros, or can be downloaded from Pygame. The game is a pong clone with gravity. The one button activates thrust on [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" title="Oodles of One Button Fun" src="http://eclecti.cc/files/2008/09/rocketpong.png" alt="RocketPong" /></p>
<p>I couldn&#8217;t sleep, so I decided to write a quick entry for the <a title="GCS" href="http://gamecreation.org" target="_blank">Game Creation Society</a>&#8216;s <a href="http://www.gamecreation.org/forum/viewtopic.php?f=18&amp;t=61" target="_blank">One Button Game Compo</a>.</p>
<p>It requires Pygame 1.8, which can be installed through a package manager on many distros, or can be downloaded from <a href="http://www.pygame.org/download.shtml" target="_blank">Pygame</a>.</p>
<p>The game is a pong clone with gravity.  The one button activates thrust on your paddle, which happens to look like a rocket.  In theory, there is pixel perfect collision detection, so the angle of the ball against the curve of the rocket should matter.  The opponent rocket is controlled by some really really horrible AI.  The game would be infinitely more fun with two players, but I wasn&#8217;t sure if the one button rule meant per player or total&#8230;</p>
<p><strong>Update:</strong> I uploaded a better version of it with more accurate collision detection and better AI.  There is also a two player mode that is activated by hitting the right arrow key, which is the thrust key for the second player.  This is the final version for the game competition, and very likely the last time I will touch the code.</p>
<p><strong>Download:<br />
<a title="RocketPong" href="http://eclecti.cc/files/2008/09/rocketpong.tar.gz" target="_blank">rocketpong.tar.gz</a><br />
<a title="RocketPong" href="http://eclecti.cc/files/2008/09/rocketpong.zip" target="_blank">rocketpong.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/videogames/rocketpong-a-one-button-game/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Living Pointillism: A pygame webcam script</title>
		<link>http://eclecti.cc/olpc/living-pointillism-a-pygame-webcam-script</link>
		<comments>http://eclecti.cc/olpc/living-pointillism-a-pygame-webcam-script#comments</comments>
		<pubDate>Sun, 22 Jun 2008 06:00:35 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[OLPC]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[gsoc]]></category>
		<category><![CDATA[pointillism]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=58</guid>
		<description><![CDATA[Living Pointillism is a quick little example script I wrote to showcase the camera module I&#8217;m writing for pygame through GSoC.  It places a few dozen points (it automatically changes the number based on the framerate) for every frame of video, so the image is only clear if everything is perfectly still.  This also results [...]]]></description>
			<content:encoded><![CDATA[<p><img title="Apologies to Georges Seurat" src="http://eclecti.cc/files/2008/06/pointillism.png" alt="Living Pointillism" /></p>
<p>Living Pointillism is a quick little example script I wrote to showcase the camera module I&#8217;m writing for pygame through GSoC.  It places a few dozen points (it automatically changes the number based on the framerate) for every frame of video, so the image is only clear if everything is perfectly still.  This also results in some interesting visual effects when things are in motion.  The screenshot above doesn&#8217;t quite capture the essence of it, but I don&#8217;t have the kind of bandwidth here to upload a video.</p>
<p>To use it, you need pygame with the camera module, which is currently only available from my repository: <a href="http://git.n0r.org/?p=pygame-nrp;a=summary">http://git.n0r.org/?p=pygame-nrp;a=summary</a></p>
<p>It runs fairly well on the OLPC XO too, and I&#8217;ll release an Activity for it along with an rpm of my branch of pygame soon.</p>
<p>Download: <a href="http://eclecti.cc/files/2008/06/pointillism.py">Living Pointillism</a></p>
<p><strong>Update:</strong> This is now available packaged as <a href="http://eclecti.cc/olpc/living-pointillism-packaged-as-an-olpc-activity">an OLPC Activity</a>.</p>
<p><strong>Update 2:</strong> Pygame with the camera module should now be downloaded from the <a href="http://www.pygame.org/wiki/cvs">Pygame SVN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/olpc/living-pointillism-a-pygame-webcam-script/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PyEyes: xeyes in Python with Face Tracking</title>
		<link>http://eclecti.cc/olpc/pyeyes-xeyes-in-python-with-face-tracking</link>
		<comments>http://eclecti.cc/olpc/pyeyes-xeyes-in-python-with-face-tracking#comments</comments>
		<pubDate>Sat, 12 Apr 2008 08:07:25 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[OLPC]]></category>
		<category><![CDATA[face tracking]]></category>
		<category><![CDATA[pyeyes]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vision]]></category>
		<category><![CDATA[xeyes]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=38</guid>
		<description><![CDATA[As a crash course in learning the basics of Pygame, I wrote a quick little Activity for the OLPC XO.  It is a clone of xeyes, except instead of following the mouse cursor, it uses the webcam to be creepy and follow your face.  It&#8217;s a bit slow, and kind of messy, but I did [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img title="It sees you..." src="http://eclecti.cc/files/2008/04/pyeyes.jpg" alt="PyEyes" /></p>
<p style="text-align: left;">As a crash course in learning the basics of <a href="http://www.pygame.org/news.html" target="_blank">Pygame</a>, I wrote a quick little Activity for the OLPC XO.  It is a clone of xeyes, except instead of following the mouse cursor, it uses the webcam to be creepy and follow your face.  It&#8217;s a bit slow, and kind of messy, but I did only make it for learning purposes.</p>
<p style="text-align: left;">It uses OpenCV, so you&#8217;re going to need a version of it that works on the XO.  The latest <a href="http://sourceforge.net/cvs/?group_id=22870" target="_blank">source from CVS</a> works, or you can install a patched rpm of it that I hacked together:</p>
<blockquote>
<p style="text-align: left;">sudo rpm -i <a href="http://eclecti.cc/files/opencv-1.0.0-3olpchack.fc7.i386.rpm">http://eclecti.cc/files/opencv-1.0.0-3olpchack.fc7.i386.rpm</a></p>
</blockquote>
<p style="text-align: left;">You&#8217;ll also need the opencv-python package, which is available in the repository.</p>
<blockquote>
<p style="text-align: left;">sudo yum install opencv-python</p>
</blockquote>
<p>You can get the .xo itself here: <a href="http://eclecti.cc/files/PyEyes-1.xo">PyEyes-1.xo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/olpc/pyeyes-xeyes-in-python-with-face-tracking/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
