The Autonomous Drifter: Software

Program Download:

Main C File
auto_drift.c
auto_drift.vbs
good_terminal.exe

The Software
           The software portion of this project has two parts. The first part is the PIC C code that controls the transmitter system. The second part is the autonomous windows host script which sends serial commands automatically.

The PIC Code
           Using the USART (Serial Communication) on the PIC is surprisingly straight forward and dare I say easy...if you succumb to using the C18 library file -- usart.h. It's there, so use it. For the PIC code I used this library and a few other simple if/else if statements to create the proper output for the serial input. Check the code for specifics, I'll just go over the serial communication part here:

----- Begin Code -----
#include <p18f452.h>
#include <usart.h>
void main(void)
{
char result;
// configure USART
	OpenUSART( USART_TX_INT_OFF &
	USART_RX_INT_OFF &
	USART_ASYNCH_MODE &
	USART_EIGHT_BIT &
	USART_CONT_RX &
	USART_BRGH_LOW,
	64 );
	while(1) //Evaluate Serial Input Forever
	{
	result = getcUSART();
    if(result == 'w')
      PORTD = 0x01;//Go Forward
    else if(result == 'a')
      PORTD = 0x02;//Go Left
    else if(result == 'd')
      PORTD = 0x03;//Go Right
    ...etc..
	}
CloseUSART();
}
----- End Code -----


           Please note the code above is just a similar example of how the serial port works and is related to this project. Don't confuse it with the actual code for the project (available for download above).
           One very important thing about the serial communication with the pic is the timing. Inorder to operate at the speed you want (2400bps, 4800bps, etc..) you need to choose the correct BRGH Low/High & Value. Check the PIC datasheet for more info. This project uses a Low BRGH at 64 which translates to 2400bps.


The Autonomous Script
           Using a very simple and easy to modify built in windows scripting language we automate the rc car. To make a script, open notepad, put in the code then save the file as: "my_script.vbs" including the quotes. Double click it to run it, your anti-virus might give you an error about running malicious scripts, just ignore it. Here is an example script:

----- Begin Code -----
'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")
    'Wait 2 Seconds
WScript.Sleep(2000)
    'Go Forward For 1 Second
WshShell.SendKeys "w"
WScript.Sleep(1000)
    'Go Backwards For 1 Second
WshShell.SendKeys "s"
WScript.Sleep(1000)
    'Go Forward & Left For 1 Second
WshShell.SendKeys "a"
WScript.Sleep(1000)
    'Go Backward & Right For 1 Second
WshShell.SendKeys "c"
WScript.Sleep(1000)
----- End Code -----

           The script is pretty straight forward. It sends key strokes at certain intervals that you get to define. You will have to open your serial sending program, hyperterminal or I used 'Good Terminal' for sending serial data. You'll see how it works in the next section!



;