Category Archives: My Projects

Robot Motors Ordered

Windshield Wiper Motor, Retarget For Evil RoboticsWell, in an effort to push my as-yet unstarted robotics project forward, I decided to begin as I always do: by spending money! I ordered two windshield wiper motors from American Science and Surplus which I hope will do for powering my little robotic minion around. I’ll have to do an evaluation of their power before I set too many more design parameters, but they should be good enough to push a fairly good sized little bot around.

Now, I need to line up some 12v batteries and a charger, dust off my ammeter, and think about a test rig.

Addendum: I found this page which details a lot of the tests you can do on motors to help establish your robots overall performance characteristics. Good stuff.

Pyramids, In Stereo

Historic Photo of Giza PyramidsI must admit to a certain fascination with ancient Egypt, so it was kind of cool to note that the Library of Congress has a number of nice photographs in their collection for download, including stereo pictures like this one. A dab of the Gimp, and you can repair some of the minor tears and clean up the background so it looks nice on your webpage. Fun stuff. The Gimp is worth learning.

Fun with SLUGs

Linksys NSLU2Well, I couldn’t resist. I went ahead and bought one of the aforementioned Linksys NSLU2 boxes (colloquially referred to as a slug) and began tinkering. It’s a fun little box, and along with the help of guys on the irc channel #nslu2-linux I’ve got it running with a 20gb drive attached. In fact, I even moved one of my web pages over to it to show how it can serve files (yes, I know, many of the links there will be broken, it was a proof of concept thing).

The machine has a 266mhz Intel XScale processor, which is a variant of the ARM chip. Many similar speed chips are used in middle of the road PDAs right now, and using such a chip to run gcc is kind of hilarious. It takes quite a while for things to compile, but nevertheless I’ve managed to get vim, tcsh and a couple of other fairly hefty programs to compile and run. I’ll go on about why I think this is cool in an upcoming podcast.

Cheap Hardware Projects

If anyone has been following this blog for any period of time, you know I’m a bit of a gizmo freak. It’s not that I have the latest and greatest cell phone or PDA. Actually, I’m pretty much a cheapskate, and I don’t like tossing huge sums of money just following the latest trendy thing. I do, however, like to find bargain equipment that I can use to do something interesting (in other words, hacking gadgets). A couple of possible future projects have crossed my Inbox this week, and I thought I’d write them down here so I can remember them, and also pass them on to you.

Slashdot ran an article on a New $149 NetBSD Single Board Computer Port. The TS-7200 is an ARM processor based board which draws about two watts. It has 10/100 Ethernet, a CompactFlash slot, 32M of SDRAM and runs at 200Mhz. Cute, small, and low power, the perfect sort of thing to run a small embedded webserver. You could hook some external drives via the USB port.

In the comments, a reader mentioned the Linksys NSLU2 network storage device. It’s a tiny little computer designed to convert USB drives into network storage. It has two USB2 ports and an Ethernet port. The idea is simple: plug in the drives, configure the device via its embedded webserver and voila! You have shared network storage. It costs a low $80, and most importantly, runs Linux and is hackable. Check out nslu2-linux.org for more information. As an example, the polkadot ninja runs the thttpd daemon on one of these little boxes. Cool!

Buffalo Technologies has a cute gadget called the Kuro Box which is a power PC box with space for an internal hard drive. It costs about $160, a bit more than the NSLU2, but since you can mount an ordinary drive internally, the overall cost should be comparable.

Three neat boxes, all capable of running a webserver.

I wonder if you could actually run WordPress on them…

Fickle Operating System of the Day

Powered by FreeBSD!After a bit of frustration with the sound quality on Linux, I decided to go back to ground I’m more familiar with me: I installed FreeBSD 5.3 onto the laptop. Curiously enough, FreeBSD has a project similar to the aforementioned ndiswrapper: called Project Evil. Surprisingly (somewhat) to me, it appears to work as well. I’m typing this on the newly installed FreeBSD as we speak. Curiously enough, I am having some difficulty with the sound using FreeBSD as well, but I have yet to do real tests. I’ll keep you all posted on how it works out.

Fighting Referer Spam

In the last couple of days, I’ve been targetted by referer spam bots. These dorks access pages on a weblog repeatedly in an attempt to get their referer tag listed on your home page. I’ve been trying to figure out how to combat this behavior, and can see two different ways of dealing with it:

  • Ping the referer back, and make sure it does link to my site. Probably slow and not scaleable, particularly in the situation I have with asymmetric bandwidth.
  • Blacklist sites which generate bursts of referer traffic. If we get lots of referers to a particular url in a short period of time, put them in a database of blacklisted sites and keep them from ever appearing in the referer list.

The second seems easy, but I must admit: the query to find such lists seems difficult to write. I’ll continue to think it over, but does anyone have any suggestions?

More DSP tinkering…

Well, today I wasn’t feeling especially well, but I did manage to get a tiny bit of tinkering done. My idea was to implement the framework necessary for playing with a vocoder as a first step toward creating some more robotic voice filters and experimenting with pitch shifting.

I noticed that the Fast Fourier Transform library I have used in the past, fftw has undergone a major upgrade since the last time I tinkered with this stuff, so I spent some time reading the documentation. As a side benefit I noticed that the GNU C compiler has extensions for handling complex arithmetic. Interesting.

I also dug around to find a library that allowed me to read and write WAV format sound files, and I settled on libsndfile. It allows a certain amount of data type transparency: you can read WAV files and get the data returned as shorts, floats or doubles. That simplifies things a bit.

So after tinkering for an hour, I have a simple framework in place that:

  • opens a WAV file for reading
  • creates a similar format WAV file for output
  • reads in frames of 512 samples, which are overlapped by 25%
  • the resulting buffers are windowed
  • an FFT is performed on the data
  • all the good stuff will happen, then…
  • an inverse FFT will be performed on the frequency bins
  • each output buffer will be written to the output WAV file

So far, it just acts as an identity filter: the output WAV is pretty much a copy of the input, but all the databuffering and the like seems to work just fine. When I have a moment or two of clear thought, I’ll get to work on the good stuff.

Addendum: You can find the original Bell Labs paper describing the phase vocoder here.

Fast Generation of Sine Waves

Every once in a while, I want to generate some pure sine waves for audio purposes, and I have to go digging around to find this simple technique, so I thought I would write it down here. Suppose that you are trying to generate a 440Hz (middle A, if memory serves) sine wave sampled at 44.1Khz. The expensive way would look like this:

double t = 0.0 ; /* time begins at zero */
double omega = 0.0 ; /* angle is zero */
double dt = 1.0 / 44100 ; /* each sample advances time by dt */
double domega = dt * 440.0 * 2.0 * M_PI ; /* the angle advances by domega */

for (;;) {
    output(sin(omega))
    t += dt ;
    omega += domega ;
}

(Yes, yes, astute readers will note that t isn’t needed. So sue me.) This requires a single call to sin for each sample. On my little Via box, a call to sin takes about .584 microseconds, so you can generate over 1.7 million samples per second with this technique. Not bad, but we can do better. Much better.

The key is to remember this recurrence relationship:

(Formula courtesy of Don Cross)

You can compute samples of simple sine waves very fast using this technique, since it takes only a multiply and a subtract per sample. On my machine, that turns down to about 7 nanoseconds per sample. That is a speedup of over 84x.

Unnecessary? Perhaps, but it is still cool.

Why am I looking at this? Stay tuned.

Fun with Cellular Automata

A Family of Cellular AutomataAs part of my dose of IT Conversations recently, I listened to this interview with Stephen Wolfram, author of the book A New Kind of Science. Wolfram is an odd duck, but I found his talk to be suprisingly good, and he raised an interesting question: do random programs do anything interesting?

He decided to try to analyze some very simple programs to see if they did indeed have interesting behavior. Instead of choosing complex machines like a Pentium, he instead used a 1D cellular automaton. If you haven’t heard of these before: here is how they work:

  • The world consists of a linear array of cells. In this example, the cells form a ring, so every cell has two neighbors, and there are no funny boundary conditions.
  • Each cell can be either on or or off.
  • Time proceeds by steps. All cells are updated simultaneously.
  • To compute the next value of a cell, the contents of it and its two neighbors are used to look up the next value in a rule table. For instance, a given rule might map the pattern ON-OFF-ON to ON.
  • We graph the evolution of the “world” by displaying each successive generation as we go down the page.

There are 256 possible rulesets (since there are 8 patterns, and each pattern can be mapped to two outputs, there are 2^8 possible rulesets), so I wrote a simple program to run each ruleset on a world consisting of 128 cells evolved for 128 generations. I then cut those all together to make the quilt pattern you see on the right.

Rule #30What’s surprising is that there are some really fairly complicated patterns. For instance, the pattern on the right is generated by rule 30. It displays some rather chaotic structures, even from these almost trivial rules. Wolfram suggests that very simple interactions in nature generate either very simple behavior, or behavior which is essentially equivalent to universal computation. I’m not sure whether this is idea is novel, useful or just a crackpot theory, but it was fun to kill 10 minutes writing up the simple program.

Volcano Movie

Volcano Cam!A while ago, I wrote a simple script to fetch pictures from one of the Mount St. Helens volcano cams. I only ran it for a short time, but I collected an afternoon’s worth of images and just now got arround to assembling them into a short MPEG movie.

The script was remarkably easy to write, using code from Mark Pilgrim’s Dive Into Python book. He has some code (downloadable from the website, as is the book itself) which is called openAnything which was incredibly useful, as is the discussion in the book. I urge anyone who is making programs which interface with HTTP servers to read the chapter on Web services. Great stuff.

Podcasting Video

During my last audio podcast, I promised that I was going to make a short video showing how I record my audiopodcast sessions, and here is the resulting video, encoded in as a Windows Media file. It runs for 6:42, and is about 10Mbytes in size. (Normally, I would use a more standard format like MPEG2, MPEG4 or DivX, but the Windows Media Encoder that I used encodes to this format by default, and heck, this is for people running Windows…)

This short video shows how I load my bumper music, run Audacity, and how I adjust the various Audio Properties to achieve the enormously high sound quality (not to mention the wry humor and sparkling wit) that have been the trademarks of BrainWagon Radio for nearly three weeks. Enjoy! If you have any questions or suggestions, try dropping me an email. Thanks.

DVD Experiments, with a recipe…

Well, I’ve burned a few DVD blanks today just to see what I can do. For source material, I decided to go to the feature film section of archive.org. They have a bunch of films available in MPEG2 format, all fairly good quality and ready for download with minimal transcoding. For my experiments, I chose Max Fleischer’s Gulliver’s Travels, first released in 1939. I didn’t have a copy in my collection, and I thought it would make a good addition.

The first thing I found was that these films aren’t quite ready for inclusion on DVD: they lack space to insert a VOBU, whatever the heck that is. But a few minutes with some commonly available utilities will change that. I ran:

mpgdemux -b gulliver gullivers_travels.mpeg
mplex -f 8 -o gulliver.mpg gulliver-0.m2v gulliver-0.mp2

These commands split the original mpeg2 into sound and video, and then remultiplex them for DVDs. Then all I had to do was use dvdauthor to build a directory that contained the final DVD image and built a table of contents.

dvdauthor -o gulliver_dvd -a en gulliver.mpg
dvdauthor -o gulliver_dvd -T

This creates a new directory called gulliver_dvd, and copies in the resulting mpeg as a VOB file. I then use growisofs to burn the directory onto a DVD blank:

growisofs -Z /dev/cd0c -dvd-video gulliver_dvd

And voila! It works. Well, almost. I’ve had difficulty using DVD-R media in my HP laptop, but DVD+RW media seems to work just fine, and is eraseable to boot. You need to format DVD+RW media first, using the command:

dvd+rw-format /dev/cd0c

Then you can use it with the growisofs command above. I haven’t tried DVD+R media yet, but I suspect it will work just fine in my laptop. Both kinds of media work in the Sylvania TV+DVD player I have upstairs, but neither appears to work properly in my ancient Apex 500 DVD player I have downstairs. I’m not sure what the deal is, it just might be too old to be really compatible.

New Gadget — A DVD Burner

DVDWell, I finally caved in. DVD burners and blanks are now cheap enough that burning CD-Rs seemed like a waste of time, so I went ahead and picked up an inexpensive Toshiba model while at Fry’s yesterday. A quick bit of surgery and it was neatly installed in my server box, and I then set out to back up my entire website onto a DVD. Strangely enough, I’ve now got about 2.2gb of data stuffed away in my /usr/local/www directory, so saving it on CDs was becoming painful and required some thought. Most of the storage is actually in the form of a couple of thousand digital pictures that I’ve taken in the past year or so: now that I have them backed up, I can work on beginning to clean them and retaining only the ones that I think are useful.

I got this thing mostly as a backup device, but will probably also work on using it to develop a couple of short video DVDs. I’ve used tools like mjpegtools and vcdimager to generate VCD images before, apparently now the application of choice is dvdauthor, which can be used to stitch together dvd images and growisofs: a front end to mkisofs which is smart enough to also burn DVDs. I’ll have to give it a try, as soon as I can think of something fun to do with it.

Musings re: iPod and Audioblogging

iPod ProgrammingWell, my week long vacation is slowly slipping away, and it appears that I’ll do relatively little programming during the 11 consecutive days that I have off. Still, I’ve worked my way through a couple of niggly tasks that have been nagging me for a long time, so my time isn’t entirely wasted.

Today I spent about half an hour investigating the possibility of trying to write my own version of Adam Curry’s iBlogger script. The idea is to check RSS feeds for enclosures (which are a particular chunk of XML used to indicate large media payloads), download them automatically, and then automatically add them to your iTunes playlist so that the next time you sync your trusty white companion, you get all the downloaded mp3 files available for your next convenient listening opportunity. That doesn’t sound too hard, and in fact, the first two bits are remarkably easy. In just a couple of minutes, I wrote an eight line Python script that used Mark Pilgrim’s feedparser library to open Adam’s feed, find all the enclosures, then use wget to grab the named mp3 file. It wouldn’t be hard to not use wget: I just like it’s automatic bandwidth limiting capability, which keeps downloads from swamping my wimpy cable modem.

As I said, a piece of cake.

Well, except for getting it to talk to iTunes. If I was on a Macintosh, it would be relatively simple to use Applescript to do it, but I use Windows XP on my laptop and FreeBSD and Linux on my two desktop machines. I normally synch my iPod using iTunes on my laptop, but frankly, I wasn’t averse to trying other ideas, so I downloaded gnupod, a set of perl scripts that can talk to my iPod and installed them on fishtank, my trusty FreeBSD box. I then plugged in my iPod and….

Promptly got screen fulls of fwohci: phy intr messages from FreeBSD. Frown.

Then, I remembered that I had never actually tried hooking a firewire device to this box, and I had some difficulty installing the confusing header blocks to the front mounted panel I added to my box. Instead of supplying a nice solid 2×6 block header, they had 11 separate little pins that each had to be wired to the right location. Bleh. I didn’t feel like sorting this out, so I found the normal rear panel header, shut down my computer, disconnected the front panel, hooked up the rear panels and thirty seconds later rebooted.

Voila! The machine responded with the expected:

da0 at sbp0 bus 0 target 0 lun 0
da0:  Removable Simplified Direct Access SCSI-2 device
da0: 50.000MB/s transfers, Tagged Queueing Enabled
da0: 19073MB (39063024 512 byte sectors: 255H 63S/T 2431C)

A simple addition to /etc/fstab, and I mounted the disk and could begin to search around. I could even use mplayer to play some of the audio files that I found nestled in the subdirectories.

Okay, so next I installed gnupod and followed their instructions. But this too failed. When I attempted to run gnupod_INIT.pl, it complained about a compilation error. Harumph. Then I remembered that the version of perl installed in /usr/bin by FreeBSD is actually an early version of perl5. The version installed by the ports is more recent. Could this be the problem? A bit of scurrying around, and I managed to get the port installed and set it as the default.

And voila! It worked. I could use the gnupod_addsong.pl to add .mp3 files, and then run mktunes.pl to update the database, unmounted the disk, used camcontrol eject da0 and I had a bunch of new mp3 files on my iPod.

This isn’t probably the ideal solution for anyone, even me, but it is a solution that I can understand. I’ve also downloaded Apple’s SDK information about using COM objects to program iTunes, but I must admit that I’ve never done anything like that before, so it’s probably more work than I would like at the moment. An afternoon’s work with Python and gnupod will probably get me to a fairly painless solution. I should have some time tomorrow to goof around. Stay tuned.