LineORE MK2A C18

Robot Description



 * Uses Microchip PIC18F25K22, supported with Microchip C18, JALV2 and the free Amicus18 basic compiler
 * 8 line sensors on the front, covering 98.6mm side to side
 * Dual 1A h-bridges
 * 2 user LEDs, a speaker and a user programmable button
 * IR LED power control
 * on-board USB port for communications and 1S LiPo battery charging
 * an expansion header with single digital I/O, intended for RF debug link
 * a second expansion header with 1 digital I/O and 1 analog/digital I/O
 * roughly 10cm x 10cm size

Hardware Design Files
PIC Schematic in PDF PIC Eagle Schematic PIC Eagle Board

Support Documentation and Software
Example C code and libraries for MPLAB and C18 are provided below, as well as documentation for the libraries.

Software Documentation rev 1.1 .DOC Software Documentation rev 1.1 .PDF MPLAB Project and LineORE source libraries r1.0 DS30Loader ORE Bootloader Application r1.1

Installing the IDE and C18 compiler
The first step is to download and install MPLAB and then download and install the C18 Compiler. This will get the development environment up and running on your PC. The links above are for the windows version of MPLAB and C18. Microchip has a new environment under development called MPLAB X which runs on Linux and OSX. It is possible to use this new environment to develop on the LineORE robots, but we will not discuss that here yet.

Getting LineORE Library
The next step is to download the source library for this design. This library contains a MPLAB C18 project which contains all the base level functions of the robot that are required (A/D readings, motor control, etc...). Because the base level software is already written, the user can begin coding the higher level functions of the robot immediately. Extract the archive to somewhere convenient (C:\work\xxx or something along those lines). The Sonic.mcp file is the project file that MPLAB will load. This tells MPLAB which files are associated with the project. The .c and .h files are the source code that will be compiled for the robot.

Preparing DS30 Bootloader GUI
Next we need to download and install the bootloader GUI software. The robot that you have already has the DS30 bootloader programmed into it. As of the writing of this wiki, the latest version of DS30loader is 2.03 and support for our processor, the 18F25K22, is limited. As such, there is a custom version of the DS30loader that you can download here instead. Extract this archive to somewhere convenient also (C:\work\bootloader\... or similar). Inside this archive are several files as well as source code for the DS30loader. The files that we are interested in are "/bin/ds30 Loader GUI.exe" and "ds30loader-25k22-NoPLL-384k.HEX". You will run ds30 Loader GUI.exe to start the bootloader once we have robot code to program to the robot. The bootloader on the chip (ds30loader-25k22-NoPLL-384k.HEX) runs at a baud rate of 38400. This document will contain more info on the bootloader GUI later.

Compiling the code
You can now start MPLAB. From the project menu, choose 'Load..." and choose the Sonic.mcp file that we extract. You can arrange the source code and project windows to your liking. Double-clicking the linefollower.c file in the project window will open that source code. Here we can see the example line follower code that is going to run on our robot. Scroll down to the "void demoLineFollower(void)" line. This is the procedure that will be called after the robot has booted up and is ready to run.

This function is sample code for a simple line follower. It is just using the middle 2 line sensors (LF_CENTRE and RF_CENTRE) to trace the line. When both sensors are detecting the line, the line follower will drive forward at a rate of 70 (xxxxxMotorTargetSpeed = 70;). Speeds are based on 0 being stopped and 255 being full speed. 70 is roughly 27% of full motor speed. When only one or the other line sensor is detecting the line, the robot will try to get back on the line by speeding up the relevant motor to 150. Doing that will rotate the robot towards the line. Once both sensors are back on the line, the robot will go back to driving straight forward. If both sensors are not detecting the line, the robot is lost and will simply keep doing whatever it was doing last (likely turning). This is the code that you can build on to make your robot smarter and faster.

For now, lets compile the code. Pressing F10 (or clicking the Make or Build All buttons at the top of the screen) will compile the code. Assuming that there are no errors, the compiler will chug away and finally end with "BUILD SUCCEEDED". It will have created a "Sonic.hex" file in the same directory where our source code is. This is the file that we will use to load onto the robot.

--Albert dH 17:52, 10 June 2011 (PDT)

I just performed the above stuff and have some hints to share:
 * You may have to tell MPLAB 8 to compile for the 18f25k22 (hint "BOREN" not found) ,
 * you may have to delete the absolute paths to the p18f25k22.h file if you are not using v3.37.01 of mplabc18.

Connecting to the robot
Plug the robot into a USB cable connected to your PC. If this is the first time you've plugged it in, the computer will have to install a device driver for the USB->serial port contained on the robot. This driver is built into Windows but will take a minute or two for the process to complete. If for some reason the driver is not found, you can download the drivers from the FTDI website (version 2.08.08 is the latest version at the time of this document). Whenever your robot is plugged into the PC, it will charge the batteries. The charge status is displayed by the LED at the back of the robot : when the robot is charging, the LED will be lit. When charging is complete, the LED will turn off. There is no need to wait for the charging to complete before we play with the robot, but it is a good idea to ensure that the robot battery doesn't drain too low during normal use. Running the battery below 3.0V (4.2V is fully charged, 3.7V is nominal voltage) can damage the battery. If during the charging process you notice the battery becoming puffy or becoming hot, disconnect the USB cable and then disconnect the battery from your robot. This indicates that a battery has been damaged and needs to be replaced. Discard the battery in a safe location.

Using The Bootloader
You can now run the "ds30 Loader Gui.exe" file from our bootloader/bin directory. Once it starts, select the COM port that your robot has been detected on. Select the 18F25K22 device and 38400 as your baud rate. Choose the Sonic.hex file that we just compiled, and then press the Download button. Turn on your robot at this point (or if it was already on, press the reset button briefly). The hex file will program into your robot. If the ds30 GUI shows an error or times out, press and hold the reset button on the robot, press the ds30 abort button and then the download button again; and then release the robot reset button.

Time to run the robot!
Once the download is complete, your robot will boot up. When the robot boots, it waits for 2 seconds (this is the bootloader delay) and then begins to execute the line follower code that we just compiled. You can turn the robot off now, disconnect it from USB and place it on a white surface with a black line (black electricians tape makes great black lines). Turn the robot on and it will start to follow the line.

Line Follower Hints
At this point you need to start adding code to make it smarter. Good luck! Head to Line Follower Hints for general hints on writing code and debugging the line follower. Feel free to add your own!