Sunday, January 15, 2006

Emily's Sample Code: long due explanation

I apologize that I haven’t had the chance to explain to all of you together what I did with the code in December to make it drive in a simple pattern in autonomous. I walked Sophia through the code that you should find in your email now; it’s a zipped file called ‘EM_011506_2006AUTO.zip’. First things first – copy this file onto the computer NOT ON THE DESKTOP, but in the C:\FRC2006.

When you open up the .mcp project file, you should see something like this on the left of your screen that shows you all the .h and .c files in your project. Try to compile it (CTRL+F10) – it should succeed.

Sorry it’s taken me so long. I had to take the autonomous code that I wrote for the 2005 RC and re-integrate it into the 2006 default code and that took me a little bit of time. If you’re not already aware of it, the 2005 RC uses the PIC18F8520 microprocessor and the 2006 RC uses the PIC18F8722. That’s why things aren’t going to be as straight forward as I hoped.


Here’s the gist of what’s going on with the autonomous / timer etc.

1. Open up interrupts.c. Look at how there are two functions that look awfully familiar: InterruptVectorLow and InterruptHandlerLow. Yes, I swiped and deleted them from user_routines_fast.c and put them in interrupts.c to keep all the interrupts stuff in one place.

2. I set up a GLOBAL second timer in interrupt.c according to the instructions in this white paper: http://www.ifirobotics.com/white-papers.shtml. This GLOBAL TIMER starts counting in seconds the MOMENT you start the robot. This is the BIG CLOCK I always look at when I’m trying to write code for time intervals within the existence of the robot being powered on.

3. Open up user_routines_fast.c and look at the function ‘User_Autonomous_Code’. That’s where I have a clock within a clock. Remember that in the background I have this GLOBAL CLOCK running in interrupts.c. So now, for autonomous, I have a mini clock that starts when I trick the robot into autonomous mode (with the plug that goes onto the operator interface). I mark when I jump into autonomous with a variable called ‘clockstart’. Do you see it? Then whenever I check the global clock, I store that value into ‘clock’. So now I can figure out how long I’ve been in autonomous mode for – with the variable deltaclock = clock – clockstart.

Does that make sense?

Here’s an example of how things could pan out:

I turn my robot on and the global clock starts running.

5 seconds into it, I trick the robot into autonomous. At this point: Clockstart = 5.

I check my clock every time I go into the loop, updating the variable ‘clock’ as necessary. Two seconds later, my variable clock = 7. Thus, at this point in time, deltaclock = clock – clockstart = 7 – 5 = 2 seconds, which is how long I’ve been in autonomous mode. Now I can do things like tell the robot to move forward for 2 seconds in autonomous mode and then move backwards for 2 seconds after that.

Hope this is good food for thought!

- Emily

0 Comments:

Post a Comment

<< Home