Starting Point:

Here is the lab and my code is at the bottom, it is not running properly so if you could help out that would be awesome!

Starting Point:

You will want the mag function and close_to function from previous labs to save yourself time and effort.

Process:

Creating a New Folder

Create a new folder named lab6 in your se185labs folder on the U: drive. You will want to copy over ds4rd.exe to the lab6 folder.

Problem

Understanding freefall is the basis of practical applications such as landing rovers on Mars (http://www.youtube.com/watch?v=B6PUdWKWiBM&feature=related) as well as fun projects such as Eggdrop competitions (http://www.youtube.com/watch?v=ADBTHpk0L8g).

Freefall in a vacuum

(http://sciencealert.com.au/features/20140311-26449.html)

This week, we will develop an application that we will call DS4Drop to detect free fall and narrate the action. In this week’s lab, you drop the DualShock 4 into your partner’s hands (about 1 meter). During next week’s lab, we will use a specially padded, wireless DualShock 4 and drop it off of the 3rd floor balcony in Coover. FOR SAFETY (YOURS AND THE DS4), DO THIS NEXT WEEK ONLY UNDER SUPERVISION OF AN UNDERGRADUATE TA.

Sample Output

Your code’s output should look like the following.

Ok, I’m now receiving data.

I’m Waiting …………..

Help me! I’m falling!!!!!!!!!!!!!

Ouch! I fell 1.633 meters in 0.577 seconds.

After your code has read its first line of data, it should output “Ok, I’m now receiving data.” This is so that we can tell that it receiving data from the ds4rd.exe.

Each period on the “I’m Waiting” Line should correspond to some number of input lines from ds4rd.exe. Try 10 or so to see what works well. The exclamation points on the falling line should work similarly. (Note: You may want to use a counter and mod (%) for this. Challenge version, 20 bonus points: output them approximately every k milliseconds.) Whatever you do, be sure to use constants defined at the beginning of the program to specify how many lines or seconds equate to one period or punctuation mark.

Development Tips

Several loops in this program read and throw away data from the DualShock 4 until some condition is met. Do one loop and see if it works, then add another feature and see if it works. Don’t try to write it all at once!

Feel free to use any functions from past assignments.   Mag and close_to are probably good ones to reuse.

The tee command can be used to capture the data your program sees.

./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -a | tee output.csv | ./DS4Drop

will write the output of ds4rd.exe to output.csv and pass it to DS4Drop.

Capturing data to a file by

./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -a   > output.csv

will allow you to then click on output.csv and look at your data in excel. This can be helpful in planning your solution.

Questions and Experiments

Do the same drop 5 times in the classroom and record the distances. How consistent are your results? What could cause any variation?

How far is it from the third floor railing to the bottom floor according to your code, using the sample data? The sample data is from a previous drop from the third floor. Test your code by running:

./DS4Drop < lab6_sampledata2013_1.csv

In your report, include a graph of the magnitude of the acceleration as a function of time and label where the freefall is happening, where it hits the ground, and your tolerances. Explain and justify any tolerances you are using.

Demo your source code to an undergraduate TA using our 3 story drop data set and have them enter your demo score into the “Lab 06 Demo” column in Blackboard. Be sure your comment your code and functions that you write.

Equations:

x1 = x0 + vt + (1/2) gt2 where v is the initial velocity (0) and t is the fall time. x0 is the location before and x1 is the location after the fall.

g = 9.8 m/sec^2

#include <stdio.h> #include <math.h> #define TRUE 1 #define G 9.8 /* Put your lab 4 functions prototypes here, as well as the prototype for lab 5 */ double mag(double ax, double ay, double az); int minutes(int t); int sec(int t); int millis(int t); int close_to(double tolerance, double point, double value); int last = 0; double calc_distance_fallen(int fall_time); int main(void) {     int t, start_fall, end_fall, delta_time;     double ax, ay, az, magnitude, distance_fallen;         double is_falling_mag = 0.4;     double done_falling_mag = 1.25;         int has_printed_waiting_message = 0;     printf(“Ok, I’m now receiving data.n”);     while (TRUE) {         scanf(“%d, %lf, %lf, %lf”, &t, &ax, &ay, &az);         magnitude = mag(ax, ay, az);         if(! has_printed_waiting_message) {             printf(“I’m Waiting ………n”);             has_printed_waiting_message = 1;         }         if(magnitude <= is_falling_mag)         {             start_fall = t;             printf(”    Help me! I’m falling!!!!!!!!n”);                         while(TRUE) {                 scanf(“%d, %lf, %lf, %lf”, &t, &ax, &ay, &az);                 magnitude = mag(ax, ay, az);                 if(magnitude >= done_falling_mag) {                     end_fall = t;                     delta_time = end_fall start_fall;                                         break;                 }             }             break;         } //CODE SECTION 0         //printf(“Echoing output: %d, %lf, %lf, %lfn”, t, ax, ay, az);             //CODE SECTION 1         //printf(“At %d ms, the acceleration’s magnitude was: %fn”, t, mag(ax, ay, az));                 //printf(“%d %fnn”, t, mag(ax, ay, az));     }         distance_fallen = calc_distance_fallen(delta_time);     printf(”        Ouch! I have fell %lf meters in %lf seconds.”, distance_fallen, (double)delta_time / 1000);} /* Put your lab 4 functions here, as well as your new function close_to */ /*1st function*/ double mag(double x, double y, double z){     return sqrt(x*x + y*y + z*z);;}             /*close to function*/     int close_to(double tolerance, double point, double value){              if (fabs(point value) <= tolerance){             return TRUE;         }         else{             return 0;         }     }     /*distance function*/     double calc_distance_fallen(int fall_time){              double distance = ((0.5)*(G)*(fall_time * fall_time))/1000000;                 return distance;     }