| Garcia TEA Programming Tutorial Last Modified: 2006-11-10 | | |
| Acroname Robotics | PDF webpage version | ||
| Introduction A Garcia robot has two BrainStem controllers which are programmable in TEA, a subset of the C programming language. An off-the-shelf Garcia robot has free space for a user to run custom TEA programs. This tutorial discusses the process of writing TEA code to perform a task without using any additional computing hardware. The Concepts In normal operation, a Garcia robot runs TEA programs to monitor its state and execute primitives that define simple actions. These TEA programs make up a standard set of "TEAware" which comes pre-installed on each robot. The TEAware takes up a sizable chunk of the robot's onboard memory, but there is a 16K program slot reserved for the default demo program. This program slot may also store a user's application. This programmable capability makes it possible to perform interesting tasks without any additional computing hardware. To get an idea of what the Garcia can do by itself, play with the robot while it's running the built-in demo program. This program performs a variety of tasks, but takes up less than 25% of the available demo program memory. Source Code For this tutorial, we'll make the robot perform a simple task: move back and forth between two walls. With such a behavior, the robot could act as a sentry in a hallway. To perform the motions, the robot can use move and pivot primitives.
Normally, a host computer would issue calls to primitives to perform a task. Using special function calls, a TEA program running within the robot can launch primitives and handle IO functions. First, take a look at a program that will perform the back-and-forth action: /* filename: gDemo1.tea (moto,11) */
/* basic demo program */
#include "gCommon.tea"
#include "gMulti.tea"
void back_and_forth()
{
int error;
while (1)
{
error = gMulti_Move(0x0000, aGARCIA_TICKS_PER_FOOT * 10);
error = gMulti_Pivot(aGARCIA_TICKS_PER_360DEGREES/2);
error = gMulti_Move(0x0000, aGARCIA_TICKS_PER_FOOT * 10);
error = gMulti_Pivot(-aGARCIA_TICKS_PER_360DEGREES/2);
}
}
void main()
{
/* turn on user LED */
gc_const_wrLED(1);
/* this is a TEA application calling TEA primitives */
/* downward-looking edge check is enabled */
/* stall check is enabled */
gc_const_wrpadb(aGARCIA_MOTO_PADB_EXEFLAGS,
aGARCIA_EXECTRL_USER |
aGARCIA_EXECTRL_EDGECHK |
aGARCIA_EXECTRL_STALLCHK);
/* courtesy delay */
gc_const_sleep(20000);
/* endless loop */
back_and_forth();
}
The two include statements at the top of the file include all the libraries needed for a TEA application to run on the Garcia. The gCommon.tea library has a variety of include statements, defined values, macros, and subroutines used by all the TEAware. The gMulti.tea library has wrapper routines that launch primitives. A user's application will always need these two include statements. There is one other essential line of code in the program. The gc_const_wrpadb subroutine call sets the aGARCIA_EXECTRL_USER flag. This flag enables internal primitive calls. If this flag is not set, the user's application will not be notified when a primitive has completed execution and the robot will sit and do nothing. The other two flags enable checks of the downward-looking edge detectors and checks of stalls in the motors. The back_and_forth routine is an endless loop that calls the gMulti_Move and gMulti_Pivot routines. These routines return error values that tell why the action terminated. Error codes are provided in the aGarciaDefs.tea file. A user could perform additional logic based on the error code to handle specific errors. In this example, the error value is ignored. In normal operation, this program will simply make the robot stop when it sees a wall, then turn and go the other way. A gc_const_wrLED statement turns on the user LED as in the default demo program. A gc_const_sleep statement provides a "courtesy delay" to allow the user time to move away from the robot before it starts rolling. That's about it for the program. The monitors and primitives do most of the work so the size of this program once compiled is less than 200 bytes! Loading the Program The default demo program is stored as a compiled executable within the dump file provided in the Garcia software. Performing a braindump or "Upgrade" with the GarciaTool application installs the latest TEAware. The program in this example must be stored in the demo program slot, so it will overwrite the default demo. At present, the following steps are the easiest way to install a program that overwrites the demo code. (You can always do a braindump to refresh the TEAware.)
Running the Program Point the robot at a wall in a hallway. While holding the user button (on the back of the robot head) down, turn on the robot. This will run any program loaded in the demo program file slot. When the program starts running, the yellow light on the robot's head will turn on. Then 2 seconds later, the robot will start going back and forth. All robots differ slightly in their dimensions so the value for a 180 degree turn may not be exact. Fine-tuning the turn values may be necessary. If the 180 degree value is off a bit, the robot will gradually drift down the hallway while going back and forth. The positive and negative turns help straighten out the robot's path during every other straight move. Going Further This example shows how to write a simple TEA program that runs on the Garcia robot. Take a look at the gDemo.tea source file supplied in the aGarcia folder. It demonstrates many more techniques and library calls for TEA applications running on the Garcia robot. As an exercise, try using the gMulti_Hug call instead of the gMulti_Move call to make the robot move back and forth along a wall in a room. Revision History:
|
| ||||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved. |