TRC Library for FRC (2011) 2011
TRC Library Code Project

C:/Users/Michael/Frc/2011/code/trclib/common.h

Go to the documentation of this file.
00001 #if 0
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #endif
00014 
00015 #ifndef _COMMON_H
00016 #define _COMMON_H
00017 
00018 //
00019 // Constants.
00020 //
00021 #define PI                      3.141592653589793
00022 #define FEET_PER_METER          3.280839895
00023 #define METERS_PER_FOOT         (1.0/FEET_PER_METER)
00024 #define GRAVITY_CONSTANT        9.80665 // meter/sq(sec)
00025 #define GYRO_SENSITIVITY_2009   0.0125  // volts/degree/sec
00026 #define GYRO_SENSITIVITY_2010   0.007   // volts/degree/sec
00027 
00028 //
00029 // Macros.
00030 //
00031 #define __in
00032 #define __out
00033 #define __inout
00034 
00035 #define ARRAYSIZE(a)            (sizeof(a)/sizeof(a[0]))
00036 #define SAFE_DELETE(p)          if (p != NULL) \
00037                                 { \
00038                                     delete p; \
00039                                     p = NULL; \
00040                                 }
00041 #define MAGNITUDE(x,y)          sqrt(pow(x, 2) + pow(y, 2))
00042 #define RADIANS_TO_DEGREES(n)   ((n)*180.0/PI)
00043 // Forward is 0-radian
00044 #define DIR_RADIANS(x,y)        (((x == 0.0) && (y == 0.0))? 0.0: atan2(x, y))
00045 #define DIR_DEGREES(x,y)        RADIANS_TO_DEGREES(DIR_RADIANS(x, y))
00046 
00047 #define GetMsecTime()           (GetFPGATime()/1000)
00048 
00049 //
00050 // The BOUND macro limits the value (n) within the bounds between the given
00051 // low (l) and high (h).
00052 //
00053 #define BOUND(n,l,h)            (((n) < (l))? (l): ((n) > (h))? (h): (n))
00054 
00055 //
00056 // The NORMALIZE macro transforms a value (n) in the range between (sl) and
00057 // (sh) to the range between (tl) and (th).
00058 //
00059 #define NORMALIZE(n,sl,sh,tl,th) (((n) - (sl))*((th) - (tl))/((sh) - (sl)) + (tl))
00060 #define NORMALIZE_DRIVE(n,m)    NORMALIZE(n, -1.0, 1.0, -(m), (m))
00061 
00062 //
00063 // This macro ignores input value (n) that is within the DEADBAND_THRESHOLD.
00064 // This is necessary because analog joysticks do not always centered at zero.
00065 // So if the joystick is at the rest position, we will consider it zero even
00066 // though the value is non-zero but within DEADBAND_THRESHOLD.
00067 //
00068 #define ABS(n)                  (((n) < 0)? -(n): (n))
00069 #define DEADBAND(n,t)           ((ABS(n) > (t))? (n): 0)
00070 
00071 //
00072 // This macro limits the input value (n) to the range between -128 and 127.
00073 // This is useful when calculations on the input value may bring the result
00074 // outside of the valid range. This macro will make sure the result is within
00075 // bounds.
00076 //
00077 #define BOUND_INPUT(n)          BOUND(n, -1.0, 1.0)
00078 
00079 #endif  //ifndef _COMMON_H
 All Classes Files Functions Variables Defines