Monday, January 21, 2008

HTML as a programming language

I read an article a couple days ago about robots that were programmed by genetic algorithms where one of the patterns that evolved was that of a liar. I've been looking for something to try out with genetic algorithms and thought it would be interesting to see if I could create a liar bot as well.
Since I've been reading Programming Collective Intellegence (along with everyone else!) and Dave always telling me this stuff needs to be done as a tree ("LISP, NICK! LISP!") I started thinking down that path.
Then I realized that HTML is a tree, and quickly coded up this useless calculating proof of concept: HTML programming!

<body>
<div class="add">
<div class="power">
<div>x</div>
<div>2</div>
</div>
<div class="multiply">
<div>5</div>
<<div>x</div>
</div>
<div>4</div>
</div>
</body>

This is the "Code". It's a polynomial, x^2+5x+4. And then the "interpreter":

function writeExpression(action, actors) {
//console.debug(action,actors);
if (action == 'add') action = '+';
if (action == 'subtract') action = '-';
if (action == 'multiply') action = '*';
if (action == 'power') action = 'Math.pow(';

var openParen = action.indexOf("(");
if (openParen > -1) {
action += actors.join(",")+")";
return action;
} else {
return actors.join(action);
}
}

function depthFirst(el) {
if (el.childElements().length == 0) return el.innerHTML;
var children = [];
for(var i = 0; i < el.childElements().length; i++) {
children.push(depthFirst(el.childElements()[i]));
}

var expression = writeExpression(el.className, children);
//console.log(expression);
return expression;
}

function parse() {
var code = depthFirst($(document.body));
$(document.body).insert("<br/>"+code);
x = prompt('X = ?');
eval("fun = function(x) {return "+code+";}; alert('f(x) = "+code+"\\nf("+x+") = '+fun(x));");
}

It's just a depth first search that then decodes the class name into an operator and returns the equation for that branch.

Sunday, January 6, 2008

Reflecting off a cd case 2


Reflecting off a cd case 2
Originally uploaded by joecagit

Progress has been made!
Using GPSD's python wrapper I'm connecting to GPSD running on my desktop machine. I also fixed the spacing of the lines on the speed chart and the number of numbered lines on the compass. I also dropped in the current speed value.

The first test revealed how tiny the font at 25 (pixels? points?) is. So I bumped it up to 50 and doubled the draw size of the two gauges. Either by luck or some math that I some how got right, the fonts fix perfectly.

When trying to take this picture I noticed that the display goes away completely when the any part of the light from the GPS is behind it. That means that the HUD will disappear in other car's lights or street lights, etc. I hope that won't be too much of an issue.

Friday, January 4, 2008

Running on N800!

IMG_2250.JPG
IMG_2250.JPG, originally uploaded by joecagit.

Thanks to pygame and anyone who worked on porting it and python to Maemo I have the first steps running on the N800!
Fullscreen - check
Flip Horizontal - check

I also found wiimote.py on the internet and will be trying to integrate a wiimote as an "angle of attack" and G-meter.

It's taking a little bit of time since I have to now learn python to get this all to work. But, hey, one more language to add to my collection.

Tuesday, January 1, 2008

First Prototype HUD GPS Hookup

IMG_2246.JPG
IMG_2246.JPG, originally uploaded by joecagit.

This is the first test of my prototype for a car HUD. What I'm going for is a fighter jet feel in my car. I'm prototyping using Shoes for now to just work out the details quickly. I'm using gpsd with Net::Telnet in Ruby to access the heading (across the top) and speed (down the side).
The image doesn't really make sense since the heading coming over the wire isn't what's showing on the compass. I think I took the picture as one of the bad sentences came across. (Every once in a while it would change to 358ish degrees when it was supposed to be about 2 degrees)
Also the speed coming across is either in knots or meters/second so that's what's showing on the HUD not the 25 mph on the GPS.
I have to still figure out how to get the waypoint information from the GPS to update the hud. That's what the little circle is. Hardcoded to 285 in the picture.