Dependencies: ADXL345 USBDevice filter mbed
Fork of df-2013-minihack-slingshot-complete by
Diff: main.cpp
- Revision:
- 2:563ce68ef360
- Parent:
- 1:9d7278f20f77
- Child:
- 3:62b70ec1c2b1
--- a/main.cpp Fri Nov 01 17:30:19 2013 +0000 +++ b/main.cpp Fri Nov 01 17:39:31 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 } // @@ -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);