![]() |
|
My other sites |
|
|
|
|||
| [Home] [Projects] [Hardware] [Software] [Books] [Links] [Downloads] | |||
|
|
|||
|
|
|||
This oUserClass is written for the latest V6.0 version of the OOPic compiler. If you need one for the 5.0 version, you can find it here.
The full source code for each of these samples is available on the [downloads] page. Make sure you pair it with the correct oUserClass program.
As always, the first thing I do is define some additional constants. I'll use these for setting the wheel speeds. You can set your own values if you want.
// Create motion constants (based on specific Bot)
Const FAST_FORWARD = 10;
Const SLOW_FORWARD = 1;
Const FAST_REVERSE = -10;
With the OOPic compiler, the way you use an oUserClass is to declare an object and pass it the file name of the program that contains the UserClass. In this case the Class file is called: PBot_MkIII_1.0_VC6.osc The new 6.0 compiler allows you to use a relative path, so I just keep the Class file in the same folder as the sample programs. Here is what the code looks like to reference the user-class. Keep in mind I'm using the C syntax.
// Create instance of MkIII Object.
To use this class I simply need to reference the members and functions by prefixing
their names with "BOT.".
So what ARE the Members (variables) and Functions? Well to make it easy to
figure out, I have a header section in the class file that explains the various
items
that are available to be used.
Tip: A "Header" is a long comment at the top of a
program that explains the overall program to a potential user. I use this area
to list the Members and Functions available in a user class.
Here's the relevant section of the UserClass header:
// Boolean flags indicate when each sensor is detecting its target.
OK, so now we know what's available to be used, let's get down to the business of a basic Sumo program.. Here's what a Sumo has to do:
That's pretty straight forward, especially with my MkIII User class. The UserClass has already set up a timer that we can use, so I'll wait for it to reach one second (to give me time to place the 'Bot on the ring), then I'll calibrate the line sensor and enable the diagnostic LEDs, so I can see what the 'Bot can see. After that I'll wait for the last second to elapse and then enter an endless loop running my Sumo strategy.
The Strategy is the key part of the program, and you'll see it can be pretty basic. Before I start programming, I set up a list of decisions that the 'Bot has to make, and then I assign them priorities (1 being the highest). My program then has a bunch of If and Else If statements that test each of the conditions in priority order. If the highest priority test fails, then the program drops down to the next priority. Only ONE set of actions is taken each loop.
Before you look at the code, here's the list of actions in priority order:
Tip: Always list the priorities in the program header, so you can tell your different strategies apart later on.
Finally here's guts of the code: the Main( ) function.... notice that the If conditions all reference members of the User Class simply by prefixing their name with "BOT."
// Main programThere are several other sample programs on the [downloads] page, and they're all fully commented, so why not download thems and see what other strategies you can discover for making your Sumo just a bit smarter than the next guy's.
Web content is copyright © PhilBot.com
2005, Deep Creek Lake, MD.
Contact: Phil Malone 301.387.2331, webmaster
@
PhilBot.com