Time for the code... The software portion of this robot was fairly straight forward compared to the electrical and hardware designs. I had several previous robots and experiences to pull from when writing the code. As a result the code is very clean and well documented. There are two languages required to understand the code: JAVA and C (AVR Libc to be precise).
JAVA:
I used JAVA to create a user interface which would take keyboard input and translate it into serial commands. The UI is very simple. It uses a KeyListener (which is added to all visible components of the UI) to pick up key strokes from the user. When a key is "typed" a string of characters is sent via GiovynetSerialPort1.3 to the XBee Module attached to the PC. The XBee acts a transparent serial cable with the XBee on the robot as the other end of the cable. Any serial data coming from the robot is displayed in the text area...
JAVA:
I used JAVA to create a user interface which would take keyboard input and translate it into serial commands. The UI is very simple. It uses a KeyListener (which is added to all visible components of the UI) to pick up key strokes from the user. When a key is "typed" a string of characters is sent via GiovynetSerialPort1.3 to the XBee Module attached to the PC. The XBee acts a transparent serial cable with the XBee on the robot as the other end of the cable. Any serial data coming from the robot is displayed in the text area...
I used Giovynet's serial port library for two reasons; first, Sun (JAVA) no longer supports serial ports and second, I've used this library before. This library's documentation leaves something to be desired...but I managed to get enough of it working for now.
As far as design of the UI and JAVA control code goes I almost always follow the MVC software design model for this type of software. In this case their is no "model" but there is a clearly defined (by name even) 'control' and 'view' portion.
One notable UI feature is the serial dialog (below) which was created solely to make the initial configuration of a serial connection easier. This and a handy Thread for receiving serial input into the PC are included in SerialTools.jar (w/ source code).
As far as design of the UI and JAVA control code goes I almost always follow the MVC software design model for this type of software. In this case their is no "model" but there is a clearly defined (by name even) 'control' and 'view' portion.
One notable UI feature is the serial dialog (below) which was created solely to make the initial configuration of a serial connection easier. This and a handy Thread for receiving serial input into the PC are included in SerialTools.jar (w/ source code).
I didn't comment the JAVA code very well, most of it is simple enough to read through with need for comments.
C (AVR Libc):
The micro-controller (an ATMega32) was programmed in a version of C specifically designed for AVR micro-controllers. The program written for the micro-controller is commented very heavily so I wont go into much detail on that. Possibly the most important feature of the program is a 2 second watchdog timer that disables the robot if the connection to the PC is lost (for two seconds). This is one of the first things I programmed and tested...safety first!
The micro-controller program was used to control the following:
C (AVR Libc):
The micro-controller (an ATMega32) was programmed in a version of C specifically designed for AVR micro-controllers. The program written for the micro-controller is commented very heavily so I wont go into much detail on that. Possibly the most important feature of the program is a 2 second watchdog timer that disables the robot if the connection to the PC is lost (for two seconds). This is one of the first things I programmed and tested...safety first!
The micro-controller program was used to control the following:
- Serial Communication w/ PC (command parsing).
- 2 9A motor controllers (A total of 4 digital inputs, 4 digital outputs, and two PWM channels).
- 3 (up to 8) IR sensors for line following. (I fried all my sensors but the code was done).
- 1 Digital output for the weapon's motor's controller.
Files:
- RoboController.jar (archive w/ source not runnable) contains the JAVA code for the controller UI and key-stroke processing.
- SerialTools.jar (archive w/ source not runnable) contains SerialConnDialog and ReceiveThread.
- AVR C-Code.zip (for ATMega32) contains code for the robot's micro-controller.
I need the GiovynetSerialPort1.3 please send to cannavaro@isch.edu.cu or alexeirojas87@gmail.com
ReplyDeletethanks