Thursday, December 15, 2011

One Dimensional Pedal Poetry

The preliminary proof-of-concept run is now published:



So far, you can only control one dimension: rotational speed controls the speed at which you fly through Dasher. As a result, the text is a bit wonky, but fun nonetheless!


The resulting text from that run:

Like to ME,' said not officiate".This corporates mcliest called but fromulous mention of the horse then with has becauses, and see, Shallades, was 

Which I'm pretty sure comes straight from Finnegan's Wake.

Wednesday, December 14, 2011

The Final Countdown

Did I mention I can control the mouse position with the reed switch now? Yep. Using the Java robot class, I can position the mouse on the screen based on the incoming RPMs from the rotating reed switch (I'll edit a screen cap in in a bit). Right now it's ugly -- I need to work a smoothing function in there, but I'm happy that it works at all.

And have I mentioned exactly what's going to come of this? Meet Pedal Poetry, where predictive text meets stream of consciousness, and the need for speed meets the need to read. How fast can you pedal and still produce sensible language?

From Wikimedia Commons
Pedaling controls your position on the x axis, which controls the speed at which you fly through an alphabetical landscape that adapts to your words. Two buttons control movement on the y axis, which controls which box you ultimately fly through. You can stop, but you can't backspace! ...because I have no way of detecting which direction you're pedaling in.

There are only a few aspects left to hammer out:
  • Button control: I've got the button board set up, looking like a lofi NES controller or something, and I've got the Arduino to relay button presses to the computer, but I haven't done anything with them yet.
  • Smoothing: Right now, RPM changes translate to jolty changes in the mouse position. I'll be setting up a control loop to smooth things out
  • Reassembling the bike: It's been much easier to prototype while the rotation mechanism is on my desk rather than in the bike. So far I've been "pedaling" by spinning the switch by hand. I'll need to reassemble the bike and figure out a decent way to mount everything on it safely.
  • Putting it all together: The batch file that runs the input/mouse movement program will also need to load Dasher in fullscreen mode. And then it's time to pedal bikes like Percy Bysshe.
I'll be posting progress updates throughout the day, so keep an eye out. Today is the last day of finals, but I'll probably keep tweaking things long afterward. It's not over yet!

Monday, December 5, 2011

Success and Anxiety

Oh joy of joys! I just tested the reed switch with the Arduino, and it works! I was pretty nervous about that one, since I hadn't had any luck with the multimeter, and I wasn't entirely sure what I would do if the reed switch was out of commission. Observe:

The magnet is far from the reed switch, and the circuit is broken.  Light off.

The magnet is close to the reed switch, and the circuit is complete. Light on (the lower light).
I wrote a simple Arduino sketch that checks for a transition in the reed switch. If the switch goes from off to on, it sends a single bit to the serial port. Otherwise, it does nothing. The RXTX package (see my last post) is event-driven, meaning it is not constantly polling for input and instead only does something when it receives data. I took this one step further and decided to send data only once per rotation, giving the program basically the lowest possible overhead: one bit per rotation. Next I'll be adapting my Robot and serial test classes (did I forget to mention those?) to take in that serial data and move the mouse cursor accordingly. 

The only thing I'm really afraid of right now is reassembling the bike itself. It's got a pretty complicated internal structure; obviously they didn't intend for any tampering. When I disassembled the bike, I carefully arranged the pieces in a protective case so that I would remember which went where. And then my cat, the adorable little agent of chaos, knocked the case onto the floor, jumbling the pieces within. Wish me luck! At the very least, I'll have a working example of a rotating reed switch controlling mouse cursor position within Dasher, and a broken bike.
Keaton the Cat, proponent of entropy and avid consumer of the arts.

Thursday, December 1, 2011

Total Eclipse of the Smart

I've been writing Java since high school, but I've never personally used Eclipse before this project -- only in passing, to help a friend through CS 1301, in a simple setting and already properly configured. I do think the "spellcheck" feature is nifty, but for certain applications I find its interface to be cumbersome. I'm using it now a) spellcheck, like I said, and b) because I know that the UGA CS department uses it, and in case I ever need to teach/grade a course that uses Eclipse, I'd like to be familiar with it.

There are only two main libraries available for serial communication in Java -- The Java Communiations API Extension, which is apparently not well documented or supported, and RXTX, which is used by Arduino and is included in the folders included with the Arduino IDE. I opted to use the latter, since I already had copies on my harddrive and the Arduino website features a nice tutorial on interfacing with the Arduino and RXTX. Perfect! The tutorial goes into extensive detail on usage: The rxtxSerial.dll needs to be included in the PATH, and the RXTXcomm.jar needs to be included in the CLASSPATH.

The latter is not always so easy with Eclipse. JAR files, folders, and projects are all added to the CLASSPATH seperately, and there are seperate CLASSPATH setups for building and running. This is all detailed (for a slightly old but still followable version) here, but following these instructions wasn't enough for my purposes. The author of these instructions had similar qualms:
It seems to me Add Variables, Add Libraries, and Add JARS all add collections of classpath elements that are defined inside Eclipse, but I don't know their differences. When I specify classpath in any IDE, I like to explicitly spell out Jar files and directories, without using any IDE-specific artifacts. I suppose the whole purpose of having them is to reuse them in other projects, but I find it's pretty unrealistic due to various jar version differences.

I don't care about the difference between a jar file and a directory, both of them are just an element in the classpath. I like the fact that NetBeans combine them into one single Add JAR/Folder button.
I actually had no luck until I broke down and just made a batch file to run the SerialTest program (similar to that found in the Use Sample Code section of the interfacing tutorial, except I put the dll in my main jdk folder, and the jars in my source folder), and I think that's how I'll keep it. Instant success, after hours wasted trying to interface with Eclipse when I already had working code. So if I do ever end up teaching a Java course, I think I'd give the following advice: Sure, use Eclipse for the simple stuff, and use it as a write-time error checker to save time on compiling, but for anything complicated, don't let your code be a slave to your IDE; just use the command line.