<?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>dddanmar.net</title>
	<atom:link href="http://www.dddanmar.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dddanmar.net</link>
	<description>(╯°□°）╯︵ ┻━┻</description>
	<lastBuildDate>Wed, 28 Mar 2012 05:25:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Russian Roulette &#8211; Unix Console</title>
		<link>http://www.dddanmar.net/russian-roulette-unix-console</link>
		<comments>http://www.dddanmar.net/russian-roulette-unix-console#comments</comments>
		<pubDate>Wed, 28 Mar 2012 05:25:57 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=79</guid>
		<description><![CDATA[From /. [ $[ $RANDOM % 6 ] == 0 ] &#038;&#038; rm -rf / &#124;&#124; echo "You live" &#8230;brilliant. (do I have to say don&#8217;t run it?)]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://ask.slashdot.org/comments.pl?sid=1019609&#038;cid=25652759">/.</a></p>
<pre>[ $[ $RANDOM % 6 ] == 0 ] &#038;&#038; rm -rf / || echo "You live"</pre>
<p>&#8230;brilliant.<br />
(do I have to say don&#8217;t run it?)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/russian-roulette-unix-console/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSV &#8211; Finding a needle in a haystack</title>
		<link>http://www.dddanmar.net/csv-finding-a-needle-in-a-haystack</link>
		<comments>http://www.dddanmar.net/csv-finding-a-needle-in-a-haystack#comments</comments>
		<pubDate>Mon, 12 Mar 2012 22:06:27 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=76</guid>
		<description><![CDATA[I had two CSV files that did not match each other&#8217;s structure. I needed to find out of email addresses listed in CSV-A.csv were present in CSV-B.csv. Therefore, it was difficult to just do a normal diff on the two files Python + CSV module to the rescue, nice and simple. CSV-A.csv email@address.com, Bob, Test [...]]]></description>
			<content:encoded><![CDATA[<p>I had two CSV files that did not match each other&#8217;s structure. I needed to find out of email addresses listed in CSV-A.csv were present in CSV-B.csv.</p>
<p>Therefore, it was difficult to just do a normal diff on the two files</p>
<p>Python + CSV module to the rescue, nice and simple.</p>
<p><span id="more-76"></span></p>
<p>CSV-A.csv</p>
<pre>email@address.com, Bob, Test
email2@address.com, Michael, Test
email3@address.com, Steve, Test</pre>
<p>CSV-B.csv</p>
<pre>Bob, email@address.com
Steve, email3@address.com</pre>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #dc143c;color: #8FB394;">csv</span>
count = <span style="color: #ff4500;color: #DDD;">0</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">with</span> <span style="color: #008000;color: #577A61;">open</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'CSV-A.csv'</span>, <span style="color: #483d8b;color: #666666;">'rb'</span><span style="color: #FFF;color: #CCC;">&#41;</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">as</span> f:
    reader = <span style="color: #dc143c;color: #8FB394;">csv</span>.<span style="color: white;">reader</span><span style="color: #FFF;color: #CCC;">&#40;</span>f, delimiter=<span style="color: #483d8b;color: #666666;">','</span><span style="color: #FFF;color: #CCC;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">for</span> row <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> reader:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">for</span> line <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> <span style="color: #008000;color: #577A61;">open</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">&quot;CSV-B.csv&quot;</span><span style="color: #FFF;color: #CCC;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> row<span style="color: #FFF;color: #CCC;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #FFF;color: #CCC;">&#93;</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> line:
                <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> row<span style="color: #FFF;color: #CCC;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #FFF;color: #CCC;">&#93;</span>
                count = count + <span style="color: #ff4500;color: #DDD;">1</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> count</pre></div></div>

<p>Output:</p>
<pre>
email@address.com
email3@address.com
2
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/csv-finding-a-needle-in-a-haystack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reddit API + Python + YouTube = YoutubedYourComment</title>
		<link>http://www.dddanmar.net/reddit-api-python-youtube-youtubedyourcomment</link>
		<comments>http://www.dddanmar.net/reddit-api-python-youtube-youtubedyourcomment#comments</comments>
		<pubDate>Thu, 16 Feb 2012 21:23:43 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=72</guid>
		<description><![CDATA[I wanted to play with Reddit&#8217;s API with Python last night. Trying to come up with an idea of a bot, I decided to make something that picks a random comment from the top x threads in x subreddit, search the first 50 characters in YouTube, and reply back with a link to a related [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to play with Reddit&#8217;s API with Python last night.</p>
<p>Trying to come up with an idea of a bot, I decided to make something that picks a random comment from the top x threads in x subreddit, search the first 50 characters in YouTube, and reply back with a link to a related video.</p>
<p>Except, it&#8217;s not always related&#8230;</p>
<p><span id="more-72"></span></p>
<p>For this you need both the reddit python wrapper and the gdata wrapper.</p>
<p>Install with PIP</p>
<p>pip install reddit</p>
<p>pip install gdata</p>
<p><a href="http://dddanmar.net/youtubedyourcomment.py">Raw text version here.</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> reddit
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> gdata
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> gdata.<span style="color: white;">youtube</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> gdata.<span style="color: white;">youtube</span>.<span style="color: white;">service</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> <span style="color: #dc143c;color: #8FB394;">random</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> choice
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #dc143c;color: #8FB394;">time</span>
&nbsp;
done=<span style="color: #008000;color: #577A61;">False</span>
video = <span style="color: #483d8b;color: #666666;">&quot;&quot;</span>
vidurl = <span style="color: #483d8b;color: #666666;">&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> SearchAndPrint<span style="color: #FFF;color: #CCC;">&#40;</span>search_terms<span style="color: #FFF;color: #CCC;">&#41;</span>:
   yt_service = gdata.<span style="color: white;">youtube</span>.<span style="color: white;">service</span>.<span style="color: white;">YouTubeService</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
   query = gdata.<span style="color: white;">youtube</span>.<span style="color: white;">service</span>.<span style="color: white;">YouTubeVideoQuery</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
   query.<span style="color: white;">vq</span> = search_terms
   query.<span style="color: white;">orderby</span> = <span style="color: #483d8b;color: #666666;">'relevance'</span>
   query.<span style="color: white;">racy</span> = <span style="color: #483d8b;color: #666666;">'include'</span>
   feed = yt_service.<span style="color: white;">YouTubeQuery</span><span style="color: #FFF;color: #CCC;">&#40;</span>query<span style="color: #FFF;color: #CCC;">&#41;</span>
   PrintVideoFeed<span style="color: #FFF;color: #CCC;">&#40;</span>feed<span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> PrintVideoFeed<span style="color: #FFF;color: #CCC;">&#40;</span>feed<span style="color: #FFF;color: #CCC;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;color: #B83A24;">try</span>:
      PrintEntryDetails<span style="color: #FFF;color: #CCC;">&#40;</span>feed.<span style="color: white;">entry</span><span style="color: #FFF;color: #CCC;">&#91;</span><span style="color: #ff4500;color: #DDD;">0</span><span style="color: #FFF;color: #CCC;">&#93;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;color: #B83A24;">except</span> <span style="color: #008000;color: #577A61;">Exception</span>, e:
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Error'</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>e<span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> PrintEntryDetails<span style="color: #FFF;color: #CCC;">&#40;</span>entry<span style="color: #FFF;color: #CCC;">&#41;</span>:
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> video
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> vidurl
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'TITLE:		 %s'</span> <span style="color: #66cc66;color: #CCC;">%</span> entry.<span style="color: white;">media</span>.<span style="color: white;">title</span>.<span style="color: white;">text</span>
   video = entry.<span style="color: white;">media</span>.<span style="color: white;">title</span>.<span style="color: white;">text</span>
   vidurl = entry.<span style="color: white;">media</span>.<span style="color: white;">player</span>.<span style="color: white;">url</span>
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'URL:		 %s'</span> <span style="color: #66cc66;color: #CCC;">%</span> entry.<span style="color: white;">media</span>.<span style="color: white;">player</span>.<span style="color: white;">url</span>
&nbsp;
r = reddit.<span style="color: white;">Reddit</span><span style="color: #FFF;color: #CCC;">&#40;</span>user_agent=<span style="color: #483d8b;color: #666666;">'YoutubedYourCommentScript'</span><span style="color: #FFF;color: #CCC;">&#41;</span>
r.<span style="color: white;">login</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'USER'</span>,<span style="color: #483d8b;color: #666666;">'PASS'</span><span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
submissions = r.<span style="color: white;">get_subreddit</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'pics'</span><span style="color: #FFF;color: #CCC;">&#41;</span>.<span style="color: white;">get_top</span><span style="color: #FFF;color: #CCC;">&#40;</span>limit=<span style="color: #ff4500;color: #DDD;">20</span><span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">while</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">not</span> done:
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">try</span>:
      submission = submissions.<span style="color: white;">next</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
      comments = submission.<span style="color: white;">comments</span>
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'---------------------------------------------------------------------'</span>
&nbsp;
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">try</span>:
         comment = choice<span style="color: #FFF;color: #CCC;">&#40;</span>comments<span style="color: #FFF;color: #CCC;">&#41;</span>
         <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">&quot;COMMENT:	      	&quot;</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>comment<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #FFF;color: #CCC;">&#91;</span>:<span style="color: #ff4500;color: #DDD;">50</span><span style="color: #FFF;color: #CCC;">&#93;</span>
         SearchAndPrint<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>comment<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #FFF;color: #CCC;">&#91;</span>:<span style="color: #ff4500;color: #DDD;">50</span><span style="color: #FFF;color: #CCC;">&#93;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
         <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> <span style="color: #008000;color: #577A61;">len</span><span style="color: #FFF;color: #CCC;">&#40;</span>video<span style="color: #FFF;color: #CCC;">&#41;</span> == <span style="color: #ff4500;color: #DDD;">0</span>:
            <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'No Vid Data, skipping.'</span>
         <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
            <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">&quot;SLEEP FOR 60s	Comment to post: &quot;</span> + <span style="color: #483d8b;color: #666666;">'['</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>video<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">']('</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>vidurl<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">')'</span>
            <span style="color: #dc143c;color: #8FB394;">time</span>.<span style="color: white;">sleep</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #ff4500;color: #DDD;">60</span><span style="color: #FFF;color: #CCC;">&#41;</span>
            comment.<span style="color: white;">reply</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'['</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>video<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">']('</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>vidurl<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">')'</span><span style="color: #FFF;color: #CCC;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'POSTED'</span>
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">except</span> <span style="color: #008000;color: #577A61;">Exception</span>, e:
         <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'ERROR		'</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>e<span style="color: #FFF;color: #CCC;">&#41;</span>
         video = <span style="color: #483d8b;color: #666666;">&quot;&quot;</span>
         vidurl = <span style="color: #483d8b;color: #666666;">&quot;&quot;</span>
&nbsp;
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'---------------------------------------------------------------------'</span>
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">&quot;SLEEP FOR  5M&quot;</span>
&nbsp;
      <span style="color: #dc143c;color: #8FB394;">time</span>.<span style="color: white;">sleep</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #ff4500;color: #DDD;">300</span><span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;color: #B83A24;">except</span> <span style="color: #008000;color: #577A61;">Exception</span>, e:
      <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">&quot;Error&quot;</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>e<span style="color: #FFF;color: #CCC;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/reddit-api-python-youtube-youtubedyourcomment/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk + PHP &#8211; Originating a Call</title>
		<link>http://www.dddanmar.net/astrisk-php-originating-a-call</link>
		<comments>http://www.dddanmar.net/astrisk-php-originating-a-call#comments</comments>
		<pubDate>Thu, 09 Feb 2012 10:21:16 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=57</guid>
		<description><![CDATA[Asterisk is a VoIP SIP Phone server that is open source, extendable and highly configurable. One of the greatest services is the simple AMI (Asterisk Management Interface). Open a network socket to port 5038, send a few string instructions and you can make any SIP extension dial any number, internally or via the outbound trunks. [...]]]></description>
			<content:encoded><![CDATA[<p>Asterisk is a VoIP SIP Phone server that is open source, extendable and highly configurable.</p>
<p>One of the greatest services is the simple AMI (Asterisk Management Interface). Open a network socket to port 5038, send a few string instructions and you can make any SIP extension dial any number, internally or via the outbound trunks.</p>
<p>This is easy business in something along the lines of PHP or Python. I&#8217;ve got some PHP code after the jump.</p>
<p><span id="more-57"></span></p>
<p>Take a look through the <a href="http://www.voip-info.org/wiki/view/Asterisk+manager+API">voip-info.org wiki article</a> on the interface.</p>
<p>Most of the documentation was fairly clear, however I ran into some issues not knowing my Context, or the correct Channel.</p>
<p>So, here&#8217;s a two part PHP script that takes generates a form and sends incoming POST variables, from and tocall.</p>
<p>It opens a socket to the VoIP server and sends 12 lines of commands. This creates a call to the users entered extension which once is picked up, dials the desired number. The form is intended for a popout, and could be implemented into a local web application.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;color: #FCFFBA;">&nbsp;</pre></div></div>

<p>For bonus points, here&#8217;s quick form to take input from a directory listing, and request the users extension before dialling.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;color: #FCFFBA;">&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
var from = new String('blank');
var tocall = new String(&quot;<span style="color: #000; font-weight: bold;color: #577A61;">&lt;?php</span> <span style="color: #b1b100;color: #B83A24;">echo</span> <span style="color: #000088;">$_GET</span><span style="color: #FFF;color: #CCC;">&#91;</span><span style="color: #0000ff;">'tocall'</span><span style="color: #FFF;color: #CCC;">&#93;</span><span style="color: #339933;color: #CCC;">;</span><span style="color: #FF font-weight: bold;">?&gt;</span>&quot;);
&nbsp;
function show_prompt()
{
from=prompt(&quot;Please enter your extension&quot;);
if (from!=null &amp;#038;&amp; from!=&quot;&quot;)
  {
  ajaxrequest('asteriskconnect.php', 'context');
  }
}
// ]]&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
function get_XmlHttp() {
  var xmlHttp = null;
&nbsp;
  if(window.XMLHttpRequest) {           // for Forefox, IE7+, Opera, Safari, ...
    xmlHttp = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {       // for Internet Explorer 5 or 6
    xmlHttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
  }
&nbsp;
  return xmlHttp;
}
&nbsp;
// sends data to a php file, via POST, and displays the received answer
function ajaxrequest(php_file, tagID) {
  var request =  get_XmlHttp();         // call the function for the XMLHttpRequest instance
&nbsp;
  var  the_data = 'from='+from+'&amp;#038;tocall='+tocall;
&nbsp;
  request.open(&quot;POST&quot;, php_file, true);
  request.setRequestHeader(&quot;Content-type&quot;, &quot;application/x-www-form-urlencoded&quot;);
  request.send(the_data);
&nbsp;
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      document.getElementById(tagID).innerHTML = request.responseText;
    }
  }
}
// ]]&gt;&lt;/script&gt;</pre></div></div>

<div id="context">Creating connection.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/astrisk-php-originating-a-call/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IR Helicopter + Arduino + Python</title>
		<link>http://www.dddanmar.net/ir-helicopter-arduino-python</link>
		<comments>http://www.dddanmar.net/ir-helicopter-arduino-python#comments</comments>
		<pubDate>Tue, 10 Jan 2012 01:59:50 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Helicopter]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=44</guid>
		<description><![CDATA[For my birthday in November, my girlfriend bought me one of those small IR helicopters, akin to http://www.chinatopwin.com/3-channel-ir-helicopter-with-gyro-1589.html A little information about these types of helicopters. They generally run on one of three different channels (a/b/c), and contain a flybar for stability. The control is done via an Infrared Transmitter controller, which contains thrust, elevator [...]]]></description>
			<content:encoded><![CDATA[<p>For my birthday in November, my girlfriend bought me one of those small IR helicopters, akin to<br />
<a href="http://www.chinatopwin.com/3-channel-ir-helicopter-with-gyro-1589.html" target="_blank"> http://www.chinatopwin.com/3-channel-ir-helicopter-with-gyro-1589.html</a></p>
<p>A little information about these types of helicopters. They generally run on one of three different channels (a/b/c), and contain a flybar for stability. The control is done via an Infrared Transmitter controller, which contains thrust, elevator (forward/back), yaw and yaw adjustment.</p>
<p>A hardware and software how-to after the jump.<br />
<span id="more-44"></span><br />
I&#8217;ve completed some RC hobby Arduino hacks before, though all have involved dismantling the RC controller to use transistors as switches to complete the circuit. While this has worked well in the past, I did not want to break the heli&#8217;s original functionality.</p>
<p>Now, the Arduino has the ability to pulse an IR LED the same way as a normal LED. The major issue here is working out the pulses on the IR codes. For a little more information, LadyAda has a great tutorial here: <a href="http://www.ladyada.net/learn/sensors/ir.html" target="_blank">http://www.ladyada.net/learn/sensors/ir.html</a> . I have utilized this in the past before for a standard TV remote control, however the helicopter protocol proved to be streaming data which ended up in me getting lost every two minutes.</p>
<p>So, I put it aside for a few months. I was researching another project and came accross this: <a href="http://www.open.com.au/mikem/arduino/IRrc/" target="_blank">http://www.open.com.au/mikem/arduino/IRrc/</a> &#8211; the IRrc library for Arduino, by MikeM. As a coincidence, I&#8217;ve learnt he lives just down the road from me too!</p>
<p>The IRrc library handles the translation from a simple Arduino command to the IR pulses required to stream data to the helicopter.</p>
<p>To get the IR signal out, it is best to use a transistor as an amplifier, and three IR leds. The circuit can be viewed on MikeM&#8217;s website here : <a href="http://www.open.com.au/mikem/arduino/IRrc/LED-Output.pdf" target="_blank">http://www.open.com.au/mikem/arduino/IRrc/LED-Output.pdf</a></p>
<p>Reading the examples and documentation, the library is quiet easy to configure. My heli runs on Channel C. To set this, the library needs to be modified slightly.</p>
<p>File (on OSX): /Applications/Arduino.app/Contents/Resources/Java/libraries/IRrc/IRheli.cpp<br />
Line to update:<br />
<code> _channel = IR_HELI_CHANNEL_C;</code></p>
<p>While the library has been written, it&#8217;s example programs are either a) Arduino sketches that read from a USB host shield (which I don&#8217;t have) or b) a Perl script that reads input from a USB gamepad (of which I also don&#8217;t have, or understand Perl in the slightest).</p>
<p>Not fazed, uploaded the HeliDemo.pde file that is included with the library, opened up a serial terminal and sent the data &#8217;255 255 255 255 :&#8217; &#8211; aka all motors full strength. It flew up to the roof, promptly fell and hit my girlfriend in the face. So, on to debugging and writing a better script.</p>
<p>The following uses Python, pySerial and TKInter. pySerial needs to be installed on OSX, however TKInter comes by default.</p>
<p>To control, arrow keys left and right are yaw, up and down is thrust, w and d is elevator, enter stops all yaw elevator and hovers at the current height, l makes the heli automatically start with 70 thrust and no direction, and p stops all motors. With this key configuration, it is also possible to use a Wii remote + <a href="http://sourceforge.net/projects/darwiin-remote/" target="_blank">DarwiinRemote</a> to control the heli.</p>
<p>The full Python file (with correct indentation) can be downloaded here: <a href="http://dddanmar.net/python-heli.py" target="_blank">http://dddanmar.net/python-heli.py</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> serial<span style="color: #66cc66;color: #CCC;">;</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">from</span> <span style="color: #dc143c;color: #8FB394;">Tkinter</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #66cc66;color: #CCC;">*</span>
&nbsp;
master = Tk<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
thrust = <span style="color: #ff4500;color: #DDD;">0</span>
direction = <span style="color: #ff4500;color: #DDD;">127</span>
elevator = <span style="color: #ff4500;color: #DDD;">127</span>
trim = <span style="color: #ff4500;color: #DDD;">100</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Thrust = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>thrust<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Direction = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>direction<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Elevator = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>elevator<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Trim = '</span>  + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>trim<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> thrust10<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> thrust==<span style="color: #ff4500;color: #DDD;">255</span>:
        thrust = <span style="color: #ff4500;color: #DDD;">255</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
        thrust = thrust + <span style="color: #ff4500;color: #DDD;">5</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> thrustdown10<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> thrust==<span style="color: #ff4500;color: #DDD;">0</span>:
         thrust = <span style="color: #ff4500;color: #DDD;">0</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
         thrust = thrust - <span style="color: #ff4500;color: #DDD;">5</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> hover<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    direction = <span style="color: #ff4500;color: #DDD;">127</span><span style="color: #66cc66;color: #CCC;">;</span>
    elevator = <span style="color: #ff4500;color: #DDD;">127</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> down<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write('0 127 127 127 :');</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'DIWN'</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> plusdirection<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> direction==<span style="color: #ff4500;color: #DDD;">255</span>:
        direction = <span style="color: #ff4500;color: #DDD;">255</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
        direction = direction + <span style="color: #ff4500;color: #DDD;">5</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span> 
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> minusdirection<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> direction==<span style="color: #ff4500;color: #DDD;">0</span>:
        direction = <span style="color: #ff4500;color: #DDD;">0</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
        direction = direction - <span style="color: #ff4500;color: #DDD;">5</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> elevatorplus<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> elevator==<span style="color: #ff4500;color: #DDD;">255</span>:
        elevator = <span style="color: #ff4500;color: #DDD;">255</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
        elevator = elevator + <span style="color: #ff4500;color: #DDD;">5</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator)  + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> elevatorminus<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> elevator==<span style="color: #ff4500;color: #DDD;">0</span>:
        elevator = <span style="color: #ff4500;color: #DDD;">0</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">else</span>:
        elevator = elevator - <span style="color: #ff4500;color: #DDD;">5</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' ' + str(direction) + ' ' + str(elevator) + ' ' + str(trim) + ' :')</span>
    printstat<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> stopall<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    thrust = <span style="color: #ff4500;color: #DDD;">0</span><span style="color: #66cc66;color: #CCC;">;</span>
    direction = <span style="color: #ff4500;color: #DDD;">127</span><span style="color: #66cc66;color: #CCC;">;</span>
    elevator = <span style="color: #ff4500;color: #DDD;">127</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write('0 127 127 127 :');</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'All Stopped'</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> liftoff<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    thrust = <span style="color: #ff4500;color: #DDD;">70</span><span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;">#ser.write(str(thrust) + ' 127 127 127 :');</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;">#ser = serial.Serial('/dev/tty.usbserial-A400fYYU', 9600);    </span>
&nbsp;
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">''</span>, thrust10<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'p'</span>, down<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">''</span>, thrustdown10<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">''</span>, minusdirection<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">''</span>, plusdirection<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'w'</span>, elevatorplus<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'d'</span>, elevatorminus<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">''</span>, hover<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'p'</span>, stopall<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
master.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'l'</span>, liftoff<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
mainloop<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span></pre></div></div>

<p>
<hr />More bonus points, this uses tkinter to monitor the mouse location in a box. Be careful, not much error correction here so it may fly off into a wall.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #dc143c;color: #8FB394;">Tkinter</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">as</span> tk
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> serial
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;"># y = height</span>
<span style="color: #808080; font-style: italic;color: #CDC;"># x = turn</span>
trim = <span style="color: #ff4500;color: #DDD;">127</span>
thrust = <span style="color: #ff4500;color: #DDD;">0</span>
direction = <span style="color: #ff4500;color: #DDD;">127</span>
elevator = <span style="color: #ff4500;color: #DDD;">127</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> writetoserial<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> thrust == -<span style="color: #ff4500;color: #DDD;">1</span>:
            thrust = <span style="color: #ff4500;color: #DDD;">0</span><span style="color: #66cc66;color: #CCC;">;</span>
	ser.<span style="color: white;">write</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>thrust<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>direction<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>elevator<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>trim<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' :'</span><span style="color: #FFF;color: #CCC;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> printvar<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #66cc66;color: #CCC;">*</span>ignore<span style="color: #FFF;color: #CCC;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
	<span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
	<span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
	<span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
	<span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Thrust = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>thrust<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Direction = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>direction<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Elevator = '</span> + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>elevator<span style="color: #FFF;color: #CCC;">&#41;</span> + <span style="color: #483d8b;color: #666666;">' | Trim = '</span>  + <span style="color: #008000;color: #577A61;">str</span><span style="color: #FFF;color: #CCC;">&#40;</span>trim<span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> showxy<span style="color: #FFF;color: #CCC;">&#40;</span>event<span style="color: #FFF;color: #CCC;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> thrust<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> direction<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> elevator<span style="color: #66cc66;color: #CCC;">;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">global</span> trim<span style="color: #66cc66;color: #CCC;">;</span>
    xm, ym = event.<span style="color: white;">x</span>, event.<span style="color: white;">y</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># show cordinates in title</span>
    direction = xm / <span style="color: #ff4500;color: #DDD;">3</span> <span style="color: #66cc66;color: #CCC;">;</span>
    thrust = ym / <span style="color: #ff4500;color: #DDD;">3</span><span style="color: #66cc66;color: #CCC;">;</span>
    writetoserial<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
    printvar<span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
ser = serial.<span style="color: white;">Serial</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">'/dev/tty.usbmodemfa141'</span>, <span style="color: #ff4500;color: #DDD;">9600</span><span style="color: #FFF;color: #CCC;">&#41;</span><span style="color: #66cc66;color: #CCC;">;</span>
root = tk.<span style="color: white;">Tk</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
frame = tk.<span style="color: white;">Frame</span><span style="color: #FFF;color: #CCC;">&#40;</span>root, bg= <span style="color: #483d8b;color: #666666;">'yellow'</span>, width=<span style="color: #ff4500;color: #DDD;">765</span>, height=<span style="color: #ff4500;color: #DDD;">765</span><span style="color: #FFF;color: #CCC;">&#41;</span>
frame.<span style="color: white;">bind</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #483d8b;color: #666666;">&quot;&quot;</span>, showxy<span style="color: #FFF;color: #CCC;">&#41;</span>
frame.<span style="color: white;">pack</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span>
&nbsp;
root.<span style="color: white;">mainloop</span><span style="color: #FFF;color: #CCC;">&#40;</span><span style="color: #FFF;color: #CCC;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/ir-helicopter-arduino-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling OpenCV on OSX 10.7 Lion</title>
		<link>http://www.dddanmar.net/compiling-opencv-on-osx</link>
		<comments>http://www.dddanmar.net/compiling-opencv-on-osx#comments</comments>
		<pubDate>Fri, 06 Jan 2012 02:13:49 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=35</guid>
		<description><![CDATA[edit: The below turned out to not be very helpful &#8211; after many issues with the correct version of Python vs other compilation issues, I&#8217;ve gone back to trying to use the precompiled frameworks for OSX. It is available here: http://wiki.nuigroup.com/Installing_OpenCV_on_Mac_OS_X I&#8217;ve been compiling OpenCV today for some face tracking software builds and ran into [...]]]></description>
			<content:encoded><![CDATA[<p>edit: The below turned out to not be very helpful &#8211; after many issues with the correct version of Python vs other compilation issues, I&#8217;ve gone back to trying to use the precompiled frameworks for OSX. It is available here: http://wiki.nuigroup.com/Installing_OpenCV_on_Mac_OS_X</p>
<p>I&#8217;ve been compiling OpenCV today for some face tracking software builds and ran into a few problems getting it to compile.</p>
<p>Required:</p>
<ul>
<li>XCode installed</li>
<li>MacPorts installed</li>
</ul>
<div>First, cmake must be installed</div>
<p><span id="more-35"></span><br />
<code>sudo port install cmake</code></p>
<div>And a few libraries that are required</div>
<div></div>
<div><code>sudo port install ilmbase +universal<br />
port provides /opt/local/lib/libIlmImf.dylib<br />
sudo port install zlib +universal<br />
sudo port install openexr +universal</code></p>
<div>And now, grab from SVN, configure, compile and install</div>
<p><code>svn co https://code.ros.org/svn/opencv/trunk/opencv<br />
cd opencv<br />
mkdir build<br />
cd build<br />
cmake -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C/CXX_FLAGS=-m32 -D WITH_FFMPEG=OFF -D BUILD_EXAMPLES=ON -D BUILD_LATEX_DOCS=ON ..<br />
make -j2<br />
sudo make install</code></p>
<div>Cross some fingers and</div>
<pre></pre>
<p><code>cd ../samples/python/ python camera.py</code></p>
<pre></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/compiling-opencv-on-osx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Christmas goodies!</title>
		<link>http://www.dddanmar.net/christmas-goodies</link>
		<comments>http://www.dddanmar.net/christmas-goodies#comments</comments>
		<pubDate>Mon, 26 Dec 2011 08:33:44 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Toys Christmas]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/christmas-goodies</guid>
		<description><![CDATA[Ah! Christmas has come and gone once more. I&#8217;m still recovering from the food intake, though no hangover for boxing day which is a great thing. Two items from the Christmas goodies I&#8217;m looking forward to : a) BigTrak Jr &#8211; it&#8217;s a small tank from the 80s that you can use a keypad on [...]]]></description>
			<content:encoded><![CDATA[<p>Ah! Christmas has come and gone once more. I&#8217;m still recovering from the food intake, though no hangover for boxing day which is a great thing.</p>
<p>Two items from the Christmas goodies I&#8217;m looking forward to : </p>
<p>a) BigTrak Jr &#8211; it&#8217;s a small tank from the  80s that you can use a keypad on its back to program movements and tank fire. It comes with a 3.5 audio jack that is used for accessories that trigger 5v when the tank is fired. I&#8217;m thinking an arduino powered accessory for the top, or carefully putting a micro in the device in parallel so it can run off normal controller or be swapped to remote control via a cheap radio link. </p>
<p>b) a mini cooper rc car &#8211; this is just begging to have the controller messed with. It&#8217;s a nice simple job of some transistors to act as relays and boxing it back up again.</p>
<p>Just wish I had gotten myself a new soldering iron.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/christmas-goodies/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://www.dddanmar.net/32</link>
		<comments>http://www.dddanmar.net/32#comments</comments>
		<pubDate>Mon, 19 Dec 2011 01:53:19 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=32</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://dddanmar.net/wp-uploads/2011/12/bdRpc.jpg" alt="BdRpc" title="bdRpc.jpg" border="0" width="448" height="600" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/32/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Website back up, WordPress comes back from the grave</title>
		<link>http://www.dddanmar.net/website-back-up-wordpress-comes-back-from-the-grave</link>
		<comments>http://www.dddanmar.net/website-back-up-wordpress-comes-back-from-the-grave#comments</comments>
		<pubDate>Mon, 19 Dec 2011 01:29:49 +0000</pubDate>
		<dc:creator>dddanmar</dc:creator>
				<category><![CDATA[Website]]></category>
		<category><![CDATA[dddanmar.net]]></category>
		<category><![CDATA[habari]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.dddanmar.net/?p=5</guid>
		<description><![CDATA[WordPress is back up and running again. While Habari (http://www.habariproject.org) is a quiet well rounded piece of blogging software, and I&#8217;ve finally managed to get my head around blog theme templates, it is simply missing extra functionality that still only exists in WordPress. Now, to get an idea of the installation. Server: Ubuntu 11.10 Host: [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is back up and running again.</p>
<p>While Habari (http://www.habariproject.org) is a quiet well rounded piece of blogging software, and I&#8217;ve finally managed to get my head around blog theme templates, it is simply missing extra functionality that still only exists in WordPress.</p>
<p>Now, to get an idea of the installation.</p>
<p><strong>Server:</strong> Ubuntu 11.10<br />
<strong>Host:</strong> Linode</p>
<p>After backing up all of the required data, I deleted the last Ubuntu virtual disk and started again from scratch.<br />
<span id="more-5"></span><br />
Apart from the standard server installation, the following commands were run:</p>
<p><code>apt-get update<br />
aptitude safe-upgrade<br />
tasksel<br />
*Select LAMP Server*<br />
</code></p>
<p>After the installation of Apache, MySQL and PHP has completed, Virtual Servers need to be created. Both dddanmar.net and fffreak.net are hosted from the same platform:</p>
<p><code> rm /etc/apache2/sites-available/00-default<br />
vi /etc/apache2/sites-available/00-VHOSTS<br />
DocumentRoot /var/www/dddanmar.net<br />
ServerName dddanmar.net<br />
ServerAlias *.dddanmar.net<br />
DocumentRoot /var/www/fffreak.net<br />
ServerName fffreak.net<br />
ServerAlias *.fffreak.net</code></p>
<p><code></code><br />
Once that&#8217;s done, enable the new site<br />
<code><br />
a2ensite 00-VHOSTS<br />
service apache2 reload<br />
</code></p>
<p>Now, Apache will warn that the two /var/www folders do not exist. Installing WordPress and creating some symlinks solves this problem:</p>
<p><code>apt-get install wordpress<br />
sudo ln -s /usr/share/wordpress /var/www/dddanmar.net<br />
sudo ln -s /usr/share/wordpress /var/www/fffreak.net</code></p>
<p>Now, if you visit either domain WordPress complains about a lack of configuration files. Let&#8217;s start the WordPress configure script that comes from Ubuntu&#8217;s APT repos:</p>
<p><code>sudo bash /usr/share/doc/wordpress/examples/setup-mysql -n fffreaknet fffreak.net<br />
sudo bash /usr/share/doc/wordpress/examples/setup-mysql -n dddanmarnet dddanmar.net</code></p>
<p>Now, the sites are available. Make the next step quickly or someone else may configure your blog! If you have done this for multiple VHOSTS, make sure you visit the other blogs and set them up to.</p>
<p>The WordPress demo site loads, so lets get some themes. I quickly jumped on to http://wordpress.org/extend and found some new themes:</p>
<p><code>wget http://wordpress.org/extend/themes/download/simpleblocks.1.0.1.zip<br />
unzip simpleblocks.1.0.1.zip<br />
wget http://wordpress.org/extend/themes/download/cammino.2.0.0.zip<br />
unzip cammino.2.0.0.zip </code></p>
<p>Activate the themes for each site and presto, done!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dddanmar.net/website-back-up-wordpress-comes-back-from-the-grave/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

