| gCommon.tea | Index |
Overview
The gCommon.tea file is a common header/source file used by all TEAware programs. It contains macros and subroutines used by the primitive and monitor processes. It also includes all header files used by the TEAware along with some additional constant declarations. A TEAware program need only include the gCommon.tea file to ensure linkage with all necessary header files and common routines.
Macros
Many of the common functions may be defined as macros. When applicable, they are more efficient than subroutines. Macros use a small set of general subroutines but apply specific constants to get the desired result. Routines and macros implemented in this file have a gc_ prefix in their name. Macros with a const_ identifier in their name perform operations with constant values instead of variables. They are more efficient than equivalent routines that use stack-based variables. A listing of all the macros with a description of their functions is given below.
| Macro | Description |
|---|---|
| gc_const_sleep(i) | Tells controller to sleep for a duration equal to 2-byte constant i. |
| gc_const_wrpadb(x, i) | Writes byte constant i to scratchpad location x. |
| gc_const_wrpads(x, i) | Writes 2-byte constant i to scratchpad locations x, x+1. |
| gc_const_wrctr(x, i) | Writes 2-byte constant i to 2-byte counter x. |
| gc_const_wrLED(i) | Triggers reflex that turns user LED on (i=1) or off (i=0). |
| gc_aClrEnc32 | Clears left and right 32-bit encoders. |
| gc_aClrStatus | Clears aGARCIA_MOTO_PADS_STATUS control RAM. |
| gc_aMonDisable | Writes 0 to aGARCIA_MOTO_PADB_MONENABLE control RAM. |
| gc_aMonEnable | Writes 1 to aGARCIA_MOTO_PADB_MONENABLE control RAM. |
| gc_aGetStatus | Returns value of aGARCIA_MOTO_PADS_STATUS control RAM. |
| gc_aMonEnabled | Returns value of aGARCIA_MOTO_PADB_MONENABLE control RAM. |
| gc_write_padb(x, i) | Writes byte variable i to scratchpad location x. |
| gc_write_pads(x, i) | Writes 2-byte variable i to scratchpad locations x, x+1. |
| gc_read_padb(x) | Returns byte value at scratchpad location x. |
| gc_read_pads(x) | Returns 2-byte value at scratchpad locations x, x+1. |
| gc_write_ctr(x, i) | Writes 2-byte variable i to 2-byte counter x. |
| gc_read_ctr(x) | Returns 2-byte value stored in 2-byte counter x. |
| gc_write_ctr_mo(x, i) | Writes 2-byte variable i from GP module to 2-byte counter x in Moto module. |
| gc_write_ctr_gp(x, i) | Writes 2-byte variable i from Moto module to 2-byte counter x in GP module. |
| gc_write_padb_mo(x, i) | Writes byte variable i from GP module to scratchpad location x in Moto module. |
| gc_write_padb_gp(x, i) | Writes byte variable i from Moto module to scratchpad location x in GP module. |
| gc_range(x) | Macro for reading IR ranger. (Macro can be changed to call an averaging function if desired.) |
Constants
Some constants specific to TEAware are defined in the gCommon.tea file. These constants are values required by low-level operations and do not need to be exposed in the aGarciaDefs.tea file.
| Constant | Description |
|---|---|
| MOVE_DONE_NORM | (Obsolete.) Indicated normal ramp completion. |
| MOVE_DONE_KILL | (Obsolete.) Indicated aborted ramp completion. |
| VEL_NORM | Default velocity for all primitives. Units are encoder ticks per PID interval. |
| ACCT_NORM | Default acceleration step time for ramps. Units are milliseconds. |
| ACCT_WHUG | Default acceleration step time for damping velocity mode when executing wall hug primitive. Units are milliseconds. |
| FRTHR_NORM | Default front sensor threshold for all primitives. |
| STALLMASK | Constant for default size of stall sensing queue. Number of low bits set determines size of queue. |
| STALL_XSLOPE | Line slope constant used in stall sensing initialization routine for calculating no-load PWM output. |
| STALL_XCONST | Line intercept constant used in stall sensing initialization routine for calculating no-load PWM output. |
| STALL_ERR | Default stall error threshold. Units are encoder ticks per PID interval. |
| STALL_ERR_DOCK | Default stall error threshold for docking. Units are encoder ticks per PID interval. |
| STALL_ERR_DOCK | Default stall error threshold for wall-hugging. Units are encoder ticks per PID interval. |
| STALL_LOAD | Default scaling factor for calculating PWM output for normal load conditions. |
| STALL_LOAD_DOCK | Default scaling factor for calculating PWM output for docking load conditions. |
Subroutines
Many of the primitives perform similar operations for initializing ramps, monitoring ramp progress, and performing controlled stops. The subroutines in the gCommon.tea file provide most of the functionality needed by the primitives.
| Subroutine | Description |
|---|---|
| int gc_ravg(char rx) | Returns average of 3 readings from A2D input rx. |
| void gc_set_stall_params(int v, int sthr, int fac) | Initializes stall parameters for a target velocity v, stall threshold s, and stall scaling factor fac. |
| void gc_init_vdamp(int nACCT) | Initializes damped velocity mode and sets acceleration step time to nACCT. |
| void gc_init_ramp(int nACCT) | Initializes dual ramp motion and sets acceleration step time to nACCT. |
| int gc_vdamp_check() | Returns 0 when both damped velocities have reached 0. |
| void gc_stop_vdamp() | Stop a motion using damped velocity mode. Returns when velocities are zero. |
| void gc_stop_hard() | Immediately set wheels to zero velocity. |
| void gc_stop_soft(char disable) | Gradually drive wheels to zero velocity. |
| void gc_ramp_loop(char side) | Monitor ramp in progress for non-zero status or ramp completion. |
| void gc_perform_dual_ramp() | Launch ramp motions for both channels in Moto and run loop to check for ramp completion. |
| void gc_network_cmd_ci(char cModule, char cCmd, char cIndex, int arg) | Send command cCmd with parameters cIndex and arg to cModule. |
| void gc_network_cmd_cc(char cModule, char cCmd, char cIndex, char arg) | Send command cCmd with parameters cIndex and cArg to cModule. |