The TeleCam
A while back, Phil and I took his LEGO Mindstorms kit and constructed ourselves a camera mount for my camera. Below is our solution and some sample code that we used to get it running. I called it the "TeleCam".
For anyone interested in Mindstorms (or LEGO in general), I highly recommend visiting the LUGNET web site: http://www.lugnet.com/ (specifically, the robotics section).
The TeleCam has long since been retired, so I'm afraid a live demo no longer exists.
Hardware
We used the standard Mindstorms kit, with one motor used to control camera pan and the other for tilt. The motor controlling panning is basically geared down a lot, and ends up spinning the tilt assembly in its entirety. Doing it the other way around (tilting the pan assembly) would result in crooked pictures. This works nicely.
I kinda wanted to put some more detailed directions on how to build one of these things, but I didn't really have the time to do up a bunch of schematics.
Software
I toyed with legOS for a while, but its infrared message-passing support didn't seem to work very well, so I opted to revert back to the standard firmware and use NQC. It's not quite as powerful, but then again this isn't exactly a complicated setup.
The software is really rather simple. Since we have the IR tower on a different machine than the one handling the CGI, we had to work out a way to communicate between the two. Basically I wrote a simple UDP client that takes directional messages ("u" = up, for example) and sends the corresponding numeric messages to the program running on the RCX, which causes the camera to twitch in the appropriate direction. There's also commands like "R" to "re-set" the camera's position back to what the daemon thinks is "neutral", and an "M" command which tells the daemon to "mark" the current camera's position is "neutral". It's not perfect, and in practice requires re-marking the neutral position once a day or two (since the torque of the camera's cabling makes it harder to move in one direction than the other when the camera gets at an extreme), but it works for us, for now. If we had some rotational sensors we might be able to get more precise control over where the camera is aiming and how to aim it back...
Here's the software we're currently using. Be advised that this is meant for the experienced Perl and NQC coder, not for someone just starting out with Mindstorms. The code is simple, but I would really like to avoid stupid questions. The NQC code compiles and loads into the default RCX firmware fine, and the daemon sends messages fine. All of the software below is GPL'd. You'll need NQC to compile the NQC program and send messages to/from the NQC program on the RCX.
- telecam.nqc
-
The NQC code for the RCX. Accepts numeric NQC-style IR messages and twitches the camera up/down/left/right based on those values. Check the source code for things like motor timings and which numbers correspond to which directions. The timings at least will certainly need to be customized for your setup.
- telecamd
-
This is the Perl "daemon" program that listens for UDP messages and sends the appropriate numeric NQC message to the RCX. It'll probably be easier to edit the UP/DOWN/LEFT/RIGHT constants in here than adjusting which numbers control which motor in the NQC source. Listens by default on port 1502. Change this if you like. You may also want the RedHat 6.1 init.d script that I'm using to start it.
- telecam.pl
-
A command-line "client" for sending UDP messages to the daemon. Very rudimentary. Just sends a UDP message out of the first argument either once, or if you specify a second argument, that many times. E.g. "telecam.pl u 5" would move the camera up 5 notches. This works with the CGI program below.
- telecam-cgi.pl
-
A CGI program that simply calls the telecam.pl with the requested arguments. Refer to your CGI by linking:
http://example.com/cgi-bin/telecam-cgi.pl?uThis would move the camera up a notch. The arguments are simply passed as-is to the telecam.pl client, with a few restrictions (see the source).
(Brain-dead browsers will ask you to save the above .pl files, despite the fact that they're clearly labeled by the server as text/plain. Here are a couple of alternate links: telecam.pl.txt telecam-cgi.pl.txt)
Questions? Comments
You can e-mail me at david@fastolfe.net.