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

Revision:
3:42f3821c4e54
Parent:
2:fbc6e3cf3ed8
Child:
18:c2f3df4ef5fe
--- a/util.h	Thu Jun 06 13:40:23 2013 +0000
+++ b/util.h	Fri Jun 07 14:45:46 2013 +0000
@@ -3,17 +3,22 @@
 
 /** Utility routines */
 
-#define clamp360(x) \
-                while ((x) >= 360.0) (x) -= 360.0; \
-                while ((x) < 0) (x) += 360.0;
-#define clamp180(x) ((x) - floor((x)/360.0) * 360.0 - 180.0);
+#define clamp360(x) clamp((x), 0, 360.0, false)
+#define clamp180(x) clamp((x), -180.0, 180.0, true)
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
-/** Clamp value between min (non-inclusive) and max (inclusive) */
-float clamp(float v, float min, float max);
+/**
+ * Clamp value between min and max. Specify which of the two are inclusive
+ * @param v is the value to clamp
+ * @param min is the minimum value, inclusive if flip==false, exclusive otherwise
+ * @param max is the maximum value, inclusive if flip==true, exclusive otherwise
+ * @param flip determines whether min or max is inclusive
+ * @return the clamped value
+ */
+float clamp(float v, float min, float max, bool flip);
 
 /** Convert char to integer */
 int ctoi(char c);