03 January 2009

Eat the Dogfood

I try to practice what I preach, eat my own dogfood so to speak. In my rambling "Help Yourself", I wrote that you should regularly do stuff to sharpen your geek-foo. It's already 3 days into a new year and I haven't yet chanted a resolution (why mess with perfection?) or set new personal goals. I'm over due.

Comic #498AnotherRandomDay.com

Ok, so here we go. This year, my goals are:
  • Learn a new language. This is do-able. I added Groovy last year. This year will be either Erlang or Python. Probably Python or more likely Jython. When learning a new language, it doesn't count unless you do something with it. So this goal includes learning and then coming up with a project to implement.
  • Fly my r/c airplane. I bought a Firebird Phantom plane and was ready to fly. My wife accidentally broke it before I got the chance. I will fix and fly it this year. Then I'll return to Chris Anderson's DIY UAV website and start dreaming again.
  • Attend seminars. This is tough because my town is lacking in the free stuff. I'm going to keep an eye out for anything interesting in Indianapolis or even Chicago or Detroit. Here a local one that I will attend in April "Managing Like a Prince: What Machiavelli Teaches Us".
  • Re-read Charles Petzold's Code: The Hidden Language of Computer Hardware and Software. I'm kinda cheating on this goal because I've already started this (but not until yesterday so I'm still counting it for this year). This is a great book that I read a few summers ago and ended up just skimming thru the later chapters. This time, I'm reading it all.
  • Do a 7 in Seven and blog each one. 7 in Seven is an audacious scheme by the ITP Resident Researchers to do seven creative projects in seven days. My projects will be code and hardware related involving a bot or something similar. Yeah, I'm already doing that stuff but this time I'll have a deadline for each one.
  • Volunteer. I will participate in a city trash cleanup or house painting or leaf raking or ... I'll keep my eye out for opportunities posted on bulletin boards and will help where I can. My time is limited with a non-stop job and a busy family but I can't use those as excuses. I'm also very fortunate with a decent income and my health. I need to help others more.
  • Lose 10 pounds. This is the 3rd year in a row with this goal. 3 years ago, I actually gained a few, 2 years ago I stayed the same, last year I lost 5 pounds. This year, I'm doing it. I run a lot. I just eat more than I should. Check out the great recipes I have bookmarked on Delicious. yum. None are low-fat or diet. This will be my toughest goal.
I have other things in mind but these are the ones I'm committing to. I regularly read a few books (mostly fiction) each week so adding "read more" isn't a goal, it's a fact. I'd really like to take a few college course this year but that's not practical because of my insane work schedule. I just can't commit to a semester long obligation.

I'd love to hear your geek goals. What will you be doing to Help Yourself?

GPS and Twitter

Early last year I created a twitter account. Not really sure why I did. I guess no one wants to be left behind in the micro blogging world. Other than announcing that I wrote another entry on this blog, I never did anything with twitter.

Later, I stumbled on JTwitter which is a small Java library to the Twitter API. It lets you set/get your Twitter status, manage your network of friends, message friends, etc. I goofed with it for a few minutes. Example usage:
// Make a Twitter object
Twitter twitter = new Twitter("my-name","my-password");
// Print Daniel Winterstein's status
System.out.println(twitter.getStatus("winterstein"));
// Set my status
twitter.updateStatus("Messing about in Java");
Interesting. But I have no app in mind for Twitter, so JTwitter was bookmarked on Delicious for later. Today I saw on Make a cool project where a washing machine sends a message to Twitter when it's done. Pretty neat but if I hacked into my wife's LG, I'd be dead meat.

Because of Arduinos and Xbees, I've been spending lots of time on ladyada's site either buying stuff at adafruit or trying to get smarter by lurking in the forums. Ladyada seems to be alright but she has weird hair. She's pretty quick on answering forum questions and builds decent stuff. I really like her Xbee Adapter Kit.

Chris Anderson is an editor for Wired magazine. He also has a website for DIY UAVs at http://diydrones.com. Last year, I spent lots of time at his site 'cause that's something else that I want to build some day. After I read that Washing Machine Twitter thing, I read a blurb about Chris' new business model for an open source robotics startup. He says:

I'm ok with that business model but the reason I'm spinning this long story is that Chris spilled those beans via Twitter. Oh, I didn't know he had a Twitter account. I wonder what else he writes about? He writes about life and stuff. I wonder who he follows on twitter? He's the editor for Wired mag, probably follows some interesting people, huh? Sure enough, Tim O'Reilly, Phillip Torrone (Make mag), Brad Stone (NY Times), Steven Levy (found Einstein's brain, wrote Hackers, etc), and others. And Ladyada.

Ladyada's twitter status hadn't been updated in quite awhile but it was filled with entries such as:
That looked interesting as I recognized the entries as GPS strings. The National Marine Electronics Association (NMEA) has developed a specification that defines a GPS interface for the various hardware devices. NMEA also has its own version of essential GPS pvt (position, velocity, time) data. It is called RMC, the Recommended Minimum. These strings are prefaced with $GPRMC. Read all about it here.

Adafruit has a Botanicalls Twitter kit that allows plants to ask for human help via a Twitter message like "water me please" and "you over watered me". But plants don't have GPS, so I'm guessing that ladayada was messing with her Arduino GPS Shield and was logging position updates to Twitter.

I wonder where that pvt data points to? Using JTwitter, I grabbed ladayada's last status:


// Make a Twitter object
Twitter twitter = new Twitter("twitter-username","twitter-password");
// Print the lady's status
System.out.println(twitter.getStatus("ladyada"));
As expected, out pops:

$GPRMC,045519.000,A,4042.5917,N,0 7400.5417,W,0.68,290.51,160808,,* 17


In that string, the latitude is 4042.5917N. The longitude is 7400.5417W. Where is the hell is that?

Another Google search led me to a an interesting article on Sun's website, Working with Bluetooth and GPS. I grabbed the source code and parsed ladayada's string:


gps.datatypes.Record record = new gps.datatypes.Record();
System.out.println("recordtype="+
gps.parser.Parser.parse(twitter.getStatus("ladyada").getText(), record));
System.out.println("recordlat="+record.lattitude);
System.out.println("recordlon="+record.longitude);


And out pops:

recordlat=40.70986
recordlon=-74.009026

Ok, that's more like it. Somewhere in the good 'ol USA, NorthEast area. Stuff it into Google maps and sure enough, ladyada was stomping around in New York City.


What can I do with this new knowledge? I still have no app in mind but I have a few more tools to think about. And stick 'em in the shed for later use. That old shed is getting pretty full of tools for later. I better start oiling 'em before they all get rusty.

The src that I ref'd above needed some tweaking to convert the lat/lon strings to decimal degrees. I found another spot for the same code but was slightly diff in the parsing for GPRMC: Simple J2ME NMEA parser. Neither Parser was just what I needed, so I combined the two into the method below. This code is owned by Dominik Schmidt, I just modified it some.

/**
* NMEA-0183 Parser. Parses data sent by GPS receiver. As data is being
* transfered via XML to server, parsing consists in most cases of separating
* fields.
*
* @author Dominik Schmidt
*
* Copyright (C) 2006 Media Informatics Group (http://www.mimuc.de),
* University of Munich, Contact person: Enrico Rukzio
* (Enrico.Rukzio@ifi.lmu.de)
**/
public static int parse(String s, Record record)
throws UnsupportedTypeException, ParseException {

// Tokenizer to separate tokens
Tokenizer tokenizer = new Tokenizer(s);

// Type of record
int type;

try {
String token = tokenizer.next();

if (token.equals("$GPRMC")) {
type = TYPE_GPRMC;

token = tokenizer.next();
record.dateTimeOfFix = token.substring(0, 2) + ":"
+ token.substring(2, 4) + ":" + token.substring(4, 6);

record.warning = tokenizer.next().equals(Record.WARNING);

// orig version just stored lat/lon strings

// record.lattitude = tokenizer.next();
// record.lattitudeDirection = tokenizer.next();

// record.longitude = tokenizer.next();
// record.longitudeDirection = tokenizer.next();

// I used a pieces from second src to convert lat/long to decimal degrees

// Latitude
String raw_lat = tokenizer.next();
String lat_deg = raw_lat.substring(0, 2);
String lat_min1 = raw_lat.substring(2, 4);
String lat_min2 = raw_lat.substring(5);
String lat_min3 = "0." + lat_min1 + lat_min2;
float lat_dec = Float.parseFloat(lat_min3)/.6f;
float lat_val = Float.parseFloat(lat_deg) + lat_dec;

// Latitude direction
record.lattitudeDirection = tokenizer.next();

if(record.lattitudeDirection.equals("N")){
// do nothing
} else {
lat_val = lat_val * -1;
}

record.lattitude = lat_val + "";

// Longitude
String raw_lon = tokenizer.next();
String lon_deg = raw_lon.substring(0, 3);
String lon_min1 = raw_lon.substring(3, 5);
String lon_min2 = raw_lon.substring(6);
String lon_min3 = "0." + lon_min1 + lon_min2;
float lon_dec = Float.parseFloat(lon_min3)/.6f;
float lon_val = Float.parseFloat(lon_deg) + lon_dec;

// Longitude direction
record.longitudeDirection = tokenizer.next();

if(record.longitudeDirection.equals("E")){
// do nothing
} else {
lon_val = lon_val * -1;
}

record.longitude = lon_val + "";

record.groundSpeed = tokenizer.next();
record.courseMadeGood = tokenizer.next();

token = tokenizer.next();

record.dateTimeOfFix += "/" + token.substring(0, 2) + "."
+ token.substring(2, 4) + "." + token.substring(4, 6);

record.magneticVariation = tokenizer.next();

} else if (token.equals("$GPGGA")) {
type = TYPE_GPGGA;

// Time of fix
tokenizer.next();

// Lattitude
tokenizer.next();

// Lattitude direction
tokenizer.next();

// Longitude
tokenizer.next();

// Longitude direction
tokenizer.next();
record.quality = tokenizer.next();
record.satelliteCount = tokenizer.next();

// Ignore rest
}

// Type is not supported.
else {
throw new UnsupportedTypeException("Type " + token
+ " is not supported.");
}
}

// Parsing exception.
catch (NoSuchElementException e) {
throw new ParseException("Unexpected end of input.");
}
return type;
}

01 January 2009

Lego NXT in the Stocking

A while back, I wrote that I needed something cool to bring out the geek in my 10 year old son. He was hoping that Santa would bring one of the Tamiya robocraft kits. I think Santa did a little better than that when he stuffed a Lego Mindstorm NXT into the stocking. These have been out for a few years so I know this isn't news to anyone but these things are cool.

He's a young geek but mostly interested in gaming. This toy has him building things and then spending time working thru the programming. As an aging programmer, this brings joy to my heart. My son has interest in geek. Instead of wanting to be a taxi driver, he may actually want to someday be an Engineer (?). Wow, that would cool.

The basic NXT kit ($230 @ Amazon) has plenty of parts to make some pretty decent starter bots. His first project was to build a Tribot that took less than 30 minutes. You can do basic programming right on the controller. He needed zero help to create a quick file that ran the bot straight until its touch sensor was pressed, backed up, spun around, and then zoomed the other direction. This is almost exactly what I've been trying to do the past few months with a gumstix, then an Orangutan, then Arduinos and Xbees. I think he won the bot war.

We're going to build a few more of the basic models that are described in the kit and then we'll move on to LEGO MINDSTORMS NXT One-Kit Wonders: Ten Inventions to Spark Your Imagination. I spent some time looking for a decent NXT book. One that didn't require additional parts and had interesting projects. This one seemed to fit the need. The book descriptions says:

... packed with new and exciting techniques, advice, and robots that guarantee awesome results. And best of all, you'll only need one NXT Retail kit to build all ten of them! LEGO MINDSTORMS NXT One-Kit Wonders will make it simple for you to construct even the most complex of these ten robots, all while you learn the ins and outs of the NXT kit. You'll learn to build and program:
  • PunchBot, a robot that you program using old-fashioned punchcards
  • M, a robot that sorts your M&M candies by color
  • NXT Dragster, a super-fast racecar that will take you all the way to the drag strip
  • BobBot, a versatile skid-steer loader, equipped with a ball grabber or demolition claw
  • RoboLock, a security system for your robots
  • The Hand, a robotic replacement hand to protect you from those dangerous cleanup jobs, like picking up your brother's gym socks
  • SPC, a robotic vehicle that can park itself between two objects using front-wheel drive
  • The Bike, a two-wheeled robot that can balance and steer
We have the NXT software (NI LabVIEW) loaded onto a Windows Vista laptop. I run Ubuntu on my laptop but his is still on Windows since most of his games are also on Windows. When the time comes, these look to be a few good leads:

31 December 2008

Xbee Shield Kit Schematic V2.0

I've been getting a lot of Google hits on the blog looking for the Arduino Xbee Shield Kit V2.0 schematic. I had a hard time finding V2.0 also 'cause NKC Electronics seems to only have V1.0 posted. NKC's Support Forum link is also 404'd. I emailed them in October about the bad link but when I checked a few bits ago, it was still a dead end.

I ended up getting my V2.0 schematic copy (that's only a partial shot over on the left) from NKC support via an email exchange and have uploaded the pdf to: http://www.mediafire.com/?zjtykjtohji

Let me know if the link doesn't work for you. Or leave a comment if it does. Tell me what you're using the shield for. Or look around at the rest of the blog. It's free ...