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:
2:fbc6e3cf3ed8
Parent:
0:a6a169de725f
Child:
3:42f3821c4e54
--- a/util.cpp	Tue May 28 13:58:35 2013 +0000
+++ b/util.cpp	Thu Jun 06 13:40:23 2013 +0000
@@ -1,3 +1,14 @@
+/** 
+ * Clamp a value (angle) between min (non-inclusive) and max (inclusive)
+ * e.g. clamp(v, 0, 360) or clamp(v, -180, 180)
+ */
+float clamp(float v, float min, float max) 
+{
+    float mod = (max - min);
+    if (v >= max) float -= mod;
+    if (v < min) float += mod;
+}
+
 // convert character to an int
 //
 int ctoi(char c)