DreamForce 2013 Mini-Hack Challenge Project

Dependencies:   ADXL345 USBDevice mbed filter

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Fri Nov 01 17:39:12 2013 +0000
Parent:
2:e1c07ecec050
Commit message:
updated

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Nov 01 17:29:59 2013 +0000
+++ b/main.cpp	Fri Nov 01 17:39:12 2013 +0000
@@ -43,7 +43,7 @@
 
 // DreamForce2013 TUNABLES END
 
-// Sling Tunables Start - be careful changing these
+// Sling Tunables Start - !!! be careful changing these !!!
 
 // stretch start threshold
 float stretch_start_threshold = 0.4;
@@ -73,9 +73,8 @@
 AnalogIn stretch_sensor(p15);
 BusOut leds(LED1, LED2, LED3, LED4);
 
-// Potentiometers
+// Potentiometer
 AnalogIn pot_1(p19);
-//AnalogIn pot_2(p20);
 
 // keep track of mouse position
 int current_x = 0;
@@ -98,20 +97,12 @@
     return degrees;
 }
 
-//  return an average of two degrees
-float compute_average(float deg1, float deg2) {
-    return (float)((deg1+deg2)/2);
-}
-
-//
-// DreamForce 2013 Challenge: 
 //  get_potentiometer_value() reads the potentiometer, filters its value and remaps it to [0, 100.0]
-//
 float get_potentiometer_value(AnalogIn pot) {
     float f = pot;
-    f = prefilter.process(f);
-    f = (f * 100);   // [ 0, 100]
-    return postfilter.process(f);
+    f = prefilter.process(f);       // pre-filter
+    f = (f * 100);                  // remap: [ 0, 100]
+    return postfilter.process(f);   // post-filter after remap
 }
 
 //
@@ -133,10 +124,10 @@
     // DEBUG - may need this to calibrate pot values below
     //std::printf("Raw pot value=%.1f\r\n",val_pot);
     
-    // Potentiometer range: you need to uncomment the debug statement above and determine the following values
-    float median_pot = 0;
-    float min_pot = 0;
-    float max_pot = 0;
+    // Potentiometer range: INCOMPLETE: you need to uncomment the print statement above and determine median_pot, min_pot, max_pot
+    float median_pot = 0.0;
+    float min_pot = 0.0;
+    float max_pot = 0.0;
     float incr_pot = (max_pot*10) - (min_pot*10);       // how many .1 increments we have in the interval [min, max]
     
     // Mapped degree range: approx [min_sling_angle, max_sling_angle] degrees so convert to
@@ -163,8 +154,8 @@
 
 // adjust the final angle (theta) taking into account the relative angle between the sling body and the sling band.
 float adjust_for_sling_angle(float slingshot_body_angle) {    
-    // get the sling angle through approximation with the potentiometer, averaged from both potentiometers
-    float sling_angle_degrees = compute_average(potentiometer_value_to_degrees(get_potentiometer_value(pot_1)),potentiometer_value_to_degrees(get_potentiometer_value(pot_1)));
+    // get the sling angle through approximation with the potentiometer
+    float sling_angle_degrees = potentiometer_value_to_degrees(get_potentiometer_value(pot_1));
     
     // the sling angle is in degrees - so lets convert the body angle to degrees as well
     float modified_angle_degrees = radians_to_degrees(slingshot_body_angle);