|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Java ME A Waba-Powered Palm Pilot Robot
A Waba-Powered Palm Pilot Robot
By: James Caple
Dec. 1, 2001 12:00 AM
Back when Java was called Oak, it was thought that this new language would be ideal for developing embedded applications, such as those that would run on set-top boxes. The developers of this new language were well ahead of their time. Java's momentum began to build not from its large set-top developer community but from developers wishing to enhance their Web sites using Java applets. Thank goodness that was short-lived! Java then became popular in server-side applications, but it has only recently begun to gain popularity in the embedded devices it was originally intended for. Java is now running on, and in, everything from big SMP servers to portable devices, such as PDAs, phones, and even smart cards. Like many Java enthusiasts, I'm interested in exploring the capabilities of Java programs on small-footprint devices, especially my own Palm Pilot. Sometimes the best way to learn more about a new technology, or to develop a new skill, is to just mess around with stuff. Some refer to this as hacking (not to be confused with cracking, which is breaking into computer systems illegally). Not too long ago I discovered plans for a Palm Pilot Robot at Carnegie Mellon University's School of Computer Science. I downloaded the plans, bought all the necessary parts (except for the Palm Pilot, which I already had), and started putting it together. After I got the robot assembled and sandwiched together, I immediately wanted to see if I could control it with a Java program. I learned a great deal while hacking a few Java programs to control various parts of the Palm Pilot Robot Kit (PPRK) hardware, and much of what I learned can be applied directly to embedded applications. For example, I decided to construct a simple framework that attempts to make programming robot software, for robots similar to the PPRK, much easier. This article discusses the lessons learned in writing Java software to make this robot come alive - well, sort of alive. Java programs running on your favorite handheld device can serve as the brains for your robot creation.
Waba
I didn't do extensive research on what VM I wanted to use and run on my PPRK. I had some experience with Waba already and have found it easy to understand, download, and install. The fact that it's distributed under the GPL is also in its favor. Furthermore, the SuperWaba newsgroup is very active - and developers, such as Guihlerme Campos Hazan (lead SuperWaba developer), are friendly and quick to answer newbie developer's questions. These types of development communities make it easier to get up to speed on new and emerging technologies. After assembling my PPRK (see Resources section) and choosing a VM for my Palm V that could run Java-like programs, I was ready to start writing some Java code.
It's All About the Serial Port
As an aside, if you decide to buy the PPRK kit from Acroname, which I recommend, this modified HotSync cable is provided for you in the kit. (Note: You can download a PDF version of the SV203 manual from www.pontech.com to learn more about the SV203 design and protocol specifications.) Understanding how to first send commands from your PC to your SV203 board using a serial cable (at your local Radio Shack) and a terminal emulation program is important. I have documented some notes and procedures on how to do this, as well as notes for debugging your PPRK hardware and software, at www.trexlabs.com/pprk. Communicating with the SV203 is quite simple. You need to tell the board what servo motor you wish to control and in what direction and speed you wish to move it. You do this by generating a string of ASCII characters that represent a command and the device number you wish to control, terminating the string with a "\r". For example, the command SV1 M55 turns servo 1 counterclockwise (counterclockwise movement is any number between 0 and 127, and clockwise movement is any number between 128 and 255. Also note that the motors turn slower the farther away from 0 up to 127 you get, and faster the farther from 128 up to 255 you get). Once you establish a connection between your SV203 and your PC's terminal emulation program (on Linux I use minicom), you can type the command above, hit return (enter), and servo motor 1 should begin a clockwise rotation. To stop the motor, enter the command SV1 M0 and hit return (enter). The PPRK has three motors, so you can control all three by making the appropriate substitutions in the command sent to the SV203 board. Now all you need to figure out is how to write these same commands to the serial port in our Waba program. Waba makes this easy to do. As mentioned earlier, Waba has a class in the waba.io package called SerialPort, which you'll use to open a connection to the SV203 controller board serial port. This class can be constructed in two ways: SerialPort(int port_number, int baud_rate)The first constructor constructs the SerialPort object using 8 bits, no parity, and 1 stop bit as the default, so you can use the following to establish a serial connection with the SV203 controller board: SerialPort sp = new SerialPort(0, 9600);Now, you need to populate an array of bytes containing the appropriate commands, and then write that array to the serial port. If you want to write the commands SV1M55, you can accomplish it like so: byte[] buff = new byte[7];Now you're ready to write this array of bytes to the serial port object instance, sp, which was created earlier. The following code snippet uses our SerialPort instance to write the 7- byte array that contains the command to the Palm's serial port and out to the SV203 board: sp.writeBytes(buff, 0, 7)After your Waba application has sent this command in the manner described previously, your servo motor 1 on your PPRK should begin spinning lazily along in a counterclockwise direction. Again, you can stop it by issuing the SV1 M0 command in a similar manner.
Give the Gift of Sight
byte buff[] = new byte[4];You then send the 4-byte command using the SerialPort instance created earlier. You need to be aware of one subtle nuance before doing this. Your Waba program can write and read to the serial port faster than the information can be processed by the SV203 board, so you need to give the board time to digest its contents when reading data back from the board. The SV203 User's Manual suggests a sleep time of approximately 3 milliseconds, but give it a little more just to be sure. You can do this with Waba using the waba.sys.Vm.sleep() static method. The parameters to this method indicate the number of milliseconds the VM should sleep. sp.writeBytes(buff, 0, 4);You should expect the SV203 board to send some information back at this point, hopefully in the form of 4 bytes. These 4 bytes will contain a single-digit, two-digit, or three-digit number followed by a \r. Note: The largest value you should get back from the SV203 is 255 and the smallest is 0. Here's one way you can read the results and set the value in a waba.ui.Label object: Label lblIRVal = new Label("");The Waba Open Robot Framework (WORF) It's a useful exercise to take the code written thus far to create an API Framework that would allow other hackers to quickly and easily develop software for their own robot creations. The idea behind the Waba Open Robot Framework is to create Java components for each major hardware component composing the PPRK, while at the same time trying to keep it flexible and extensible enough to accommodate other robot configurations. WORF is an open source project and is governed under the terms of the LGPL. You can grab a snapshot of WORF from http://worf.sourceforge.net. One of the truly neat things about Waba is the availability of the Waba VM on several different embedded platforms, such as Palm, iPaq, Apple's Newton, and even DOS. While I have not tested the portability of WORF across these platforms, it's certainly conceivable that robots can be built using any of these devices and powered with Waba programs built on top of WORF. The PPRK consists of three servo motors, three GP2D12 infrared sensors, and a Pontech SV203 Controller Board to coordinate and control these devices. WORF, therefore, consists of Java components for each, and provides a burgeoning API set for easily sending messages to the SV203 board on behalf of a given component. The utils package provides miscellaneous support functions (see Figure 1). With WORF, developers of embedded robot software applications can focus more on the creative aspects of what they want their robot to do and less on the details of how to communicate with this specific type of hardware. This is accomplished by encapsulating the details of sending the specific commands described earlier to the SV203 board and making this functionality available vis-á-vis an easy-to-use set of APIs.
SV203 Component
Servo Component
IR Component
Utilities
Putting It All Together
Well, at the risk of using a cliché, you're truly limited only by your imagination, creativity, and attention span to your project. My first idea was an attempt to make my PPRK do a Mexican Hat Dance by writing a short program using WORF. Listing 1 is the complete source code for my WORF Mexican Hat Dance application, which you can run on your own PPRK (see Figure 2). This is a simple demonstration of how easy it is to write a small robot program for your PPRK using WORF. The WORFHatDance application (see Resources) causes the robot to alternately turn right and left at different stages of the musical ditty it plays when you tap the Push Me button displayed on your Palm (see Figure 3). The static waba.fx.Sound.tone() method tells your Waba application to play a tone at the given frequency for the given duration. The tones specified in Listing 1 play some semblance of the Mexican Hat Dance, even if it is a little off key at times. I'm sure many reading this article are asking themselves, "What's the real value in building a PPRK and writing software for it? Could I enter my PPRK in the BattleBots competition? More important, how can I make money with it?" The real value in these types of exercises, however, is fun and education. Granted, the PPRK, as it is, probably couldn't easily be modified to do your laundry or sweep your floor, and wouldn't last two seconds in the BattleBots arena. The servo motors aren't strong and the GP2D12 IR sensors are somewhat delicate. But I have to admit to a certain childlike fascination in writing a few lines of code capable of controlling hardware external to my Palm device. The PPRK provides a good platform for investigating possibilities in controlling and interacting with robotic hardware from a small footprint device, such as a Palm or iPaq. As far as I'm concerned, building robots and controlling them with my Java programs is just good fun! The money will come, hopefully, from the knowledge you gain from basic projects such as this, strengthening your skills in embedded device programming, and contributing code - and lessons you've learned - to the Java development community at large. Resources
LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
BREAKING JAVA NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||