Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
util.h@25:bb5356402687, 2018-11-30 (annotated)
- Committer:
- shimniok
- Date:
- Fri Nov 30 16:11:53 2018 +0000
- Revision:
- 25:bb5356402687
- Parent:
- 18:c2f3df4ef5fe
Initial publish of revised version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | #ifndef __UTIL_H |
shimniok | 0:a6a169de725f | 2 | #define __UTIL_H |
shimniok | 0:a6a169de725f | 3 | |
shimniok | 0:a6a169de725f | 4 | /** Utility routines */ |
shimniok | 0:a6a169de725f | 5 | |
shimniok | 3:42f3821c4e54 | 6 | #define clamp360(x) clamp((x), 0, 360.0, false) |
shimniok | 3:42f3821c4e54 | 7 | #define clamp180(x) clamp((x), -180.0, 180.0, true) |
shimniok | 0:a6a169de725f | 8 | |
shimniok | 0:a6a169de725f | 9 | #ifndef M_PI |
shimniok | 0:a6a169de725f | 10 | #define M_PI 3.14159265358979323846 |
shimniok | 0:a6a169de725f | 11 | #endif |
shimniok | 0:a6a169de725f | 12 | |
shimniok | 3:42f3821c4e54 | 13 | /** |
shimniok | 3:42f3821c4e54 | 14 | * Clamp value between min and max. Specify which of the two are inclusive |
shimniok | 3:42f3821c4e54 | 15 | * @param v is the value to clamp |
shimniok | 3:42f3821c4e54 | 16 | * @param min is the minimum value, inclusive if flip==false, exclusive otherwise |
shimniok | 3:42f3821c4e54 | 17 | * @param max is the maximum value, inclusive if flip==true, exclusive otherwise |
shimniok | 3:42f3821c4e54 | 18 | * @param flip determines whether min or max is inclusive |
shimniok | 3:42f3821c4e54 | 19 | * @return the clamped value |
shimniok | 3:42f3821c4e54 | 20 | */ |
shimniok | 3:42f3821c4e54 | 21 | float clamp(float v, float min, float max, bool flip); |
shimniok | 2:fbc6e3cf3ed8 | 22 | |
shimniok | 0:a6a169de725f | 23 | /** Convert char to integer */ |
shimniok | 0:a6a169de725f | 24 | int ctoi(char c); |
shimniok | 2:fbc6e3cf3ed8 | 25 | |
shimniok | 0:a6a169de725f | 26 | /** Convert string to floating point */ |
shimniok | 0:a6a169de725f | 27 | double cvstof(char *s); |
shimniok | 2:fbc6e3cf3ed8 | 28 | |
shimniok | 18:c2f3df4ef5fe | 29 | /** Convert unsigned long to string |
shimniok | 18:c2f3df4ef5fe | 30 | * |
shimniok | 18:c2f3df4ef5fe | 31 | * @param n is the unsigned long to convert |
shimniok | 18:c2f3df4ef5fe | 32 | * @returns char * to static char array |
shimniok | 18:c2f3df4ef5fe | 33 | */ |
shimniok | 18:c2f3df4ef5fe | 34 | char *cvntos(unsigned long n); |
shimniok | 18:c2f3df4ef5fe | 35 | |
shimniok | 18:c2f3df4ef5fe | 36 | /** Convert signed long to string |
shimniok | 18:c2f3df4ef5fe | 37 | * |
shimniok | 18:c2f3df4ef5fe | 38 | * @param n is the signed long to convert |
shimniok | 18:c2f3df4ef5fe | 39 | * @returns char * to static char array |
shimniok | 18:c2f3df4ef5fe | 40 | */ |
shimniok | 18:c2f3df4ef5fe | 41 | char *cvitos(long n); |
shimniok | 18:c2f3df4ef5fe | 42 | |
shimniok | 18:c2f3df4ef5fe | 43 | /** Convert float/double to string |
shimniok | 18:c2f3df4ef5fe | 44 | * |
shimniok | 18:c2f3df4ef5fe | 45 | * @param number is the floating point number to convert |
shimniok | 18:c2f3df4ef5fe | 46 | * @param digits is the number of digits after the decimal point |
shimniok | 18:c2f3df4ef5fe | 47 | * @return char * to static char array |
shimniok | 18:c2f3df4ef5fe | 48 | */ |
shimniok | 18:c2f3df4ef5fe | 49 | char *cvftos(double number, int digits); |
shimniok | 18:c2f3df4ef5fe | 50 | |
shimniok | 0:a6a169de725f | 51 | /** Tokenize a string |
shimniok | 0:a6a169de725f | 52 | * @param s is the string to tokenize |
shimniok | 0:a6a169de725f | 53 | * @param max is the maximum number of characters |
shimniok | 0:a6a169de725f | 54 | * @param delim is the character delimiter on which to tokenize |
shimniok | 0:a6a169de725f | 55 | * @returns t is the pointer to the next token |
shimniok | 0:a6a169de725f | 56 | */ |
shimniok | 0:a6a169de725f | 57 | char *split(char *s, char *t, int max, char delim); |
shimniok | 0:a6a169de725f | 58 | |
shimniok | 18:c2f3df4ef5fe | 59 | #endif |