ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 10 Weeks Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 12 May 2017 My Price 9.00

Develop skills in using if statements in C

Objectives:

Develop problem solving skills

Develop skills in using if statements in C

Understand how to interpret the acceleration values in terms of gravity

Understand tolerances and testing in relation to floating point values

Understand testing multiple conditions

Starting Point:

lab5.c

You will need mag function from last week

Read the entire lab manual before you start coding

Process:

Creating a New Folder

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

Getting Ready

Download lab5.c.

Associate an DualShock 4 with the PC as in past labs.

Open the cygwin shell and create a lab5 folder as in the past labs.

You will run your program using:

./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -a -g -b | ./lab5

Hit Control-C to stop the program.

Problem

We will learn how to determine how the DualShock 4 is oriented and how to interpret the acceleration values in more detail. For this problem, we will calculate the magnitude of the acceleration from the DualShock 4. You will read from ds4rd.exe, but this time you will read the inputs over and over inside the “while” loop. Your code should be written in a modular fashion and include 3 or more of your own functions.

When the DualShock 4 is not moving, your program should output a line saying which side of the DualShock 4 is facing up. Consider using the magnitude of the acceleration (-a) for movement detection. You will need a tolerance value for this---experiment to find one that seems reasonable. You will need to use the gyroscope values (-g) to determine the orientation. Again, you may want a separate tolerance value.

For instance, when laying flat and still on the table with buttons up, it should output “TOP”. Flipping the DualShock 4 over, when still, it should output “BOTTOM.” When setting the left side of the DualShock 4 (i.e. side with the black buttons) down and the right side up, your program should output “RIGHT” and when flipped (ie side with the shape buttons down), “LEFT.” When the LED light bar is pointed up, output “FRONT” and similarly when the LED light bar is down it should read “BACK.”

Required Features

Feature 1

Once your code does the above (displays which side is facing up), modify the while loop to stop and end the program when the user clicks the TRIANGLE BUTTON on the DualShock 4.

Feature 2

Modify your code so that the program only outputs a new line when its orientation changes.

Demonstrate your working program (with the required features above) to the undergraduate TA. Ensure the undergraduate TA has entered the appropriate points into the “Lab 05 Demo” column in “My Grades” on Blackboard. This may be done during an undergraduate TA's office hours if you do not complete the program in class. But it must be done before your next lab period.

Development Tips

You will need to frequently compare two real numbers within some tolerance. Write such a function with the following prototype:

int close_to (double tolerance, double point, double value);

It should return true when value is within tolerance of point. For example, if point is 1.0 and tolerance is 0.25, then close_to should return true when value is from 0.75 to 1.25, otherwise, it should return false.

Use close_to to implement your real number comparisons in your code.


HINT: Write close_to first and test it. Then implement the program. You will probably want a much smaller tolerance than this example uses.

This is the given code except for the close_to function i made.

#include <stdio.h>
#include <math.h>

#define TRUE 1

/* 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 main(void) {
int t, b1, b2, b3, b4;
double ax, ay, az, gx, gy, gz;
// gx, gy, gz are to find the orientation

while (TRUE) {
  scanf("%d, %lf, %lf, %lf, %d, %d, %d, %d, %d", &t,& ax, &ay, &az, &b1, &b2, &b3, &b4);

/* CODE SECTION 0
  printf("Echoing output: %d, %lf, %lf, %lf, %d, %d, %d, %d, %d, %dn", t, ax, ay, az, b1, b2, b3, b4);
  

  CODE SECTION 1
  printf("At %d ms, the acceleration's magnitude was: %fn", t, mag(ax, ay, az)); */


   

/* Put your lab 4 functions here, as well as your new function close_to */

/*1st function*/

double mag(double x, double y, double z)
{
double bag = sqrt(x*x + y*y + z*z);

return bag;
}

/* minute function*/

  int minutes(int t)
{
  int minutes = t/60000;

  return minutes;
}

/*seconds function*/

  int seconds(int t)
{
  int sec = t%60000;
  
  sec = sec/1000;
  
  return sec;
}

/*milliseconds function*/

int millis(int t)
{
  int millis = t%60000;
  
  millis = millis%1000;
  
  return millis;
}

/*close to function*/
int close_to(double tolerance, double point, double value){

  if (fabs(point - value)<= tolerance){
   return TRUE;
  }
  else{
   return 0;
  }

}

Answers

(11)
Status NEW Posted 12 May 2017 01:05 AM My Price 9.00

SE -----------185----------- LA-----------B 5-----------

Attachments

file 1507150793-SE 185 LAB 5.doc preview (1861 words )
-----------bjb-----------j h-----------htt-----------Z -----------c.@-----------@@@-----------6@S-----------v0v-----------( @-----------@@@-----------@@@-----------@@@-----------@@@-----------@@@-----------@@@-----------@@@-----------@h ----------- q ----------- LA-----------B R-----------EPO-----------RT ----------- ----------- ----------- LA-----------B 5----------- S-----------ECT-----------ION----------- D ----------- ----------- ----------- ----------- SU-----------BMI-----------TTE-----------D B-----------Y ----------- ----------- ----------- S-----------UBM-----------ISS-----------ION----------- DA-----------TE ----------- -----------Par-----------t 1----------- - -----------Lab----------- Re-----------por-----------t -----------Pro-----------ble-----------m -----------The----------- ob-----------jec-----------tiv-----------e o-----------f t-----------his----------- la-----------b w-----------as -----------to -----------dev-----------elo-----------p o-----------ur -----------ski-----------lls----------- in----------- us-----------ing----------- if----------- st-----------ate-----------men-----------ts,----------- un-----------der-----------sta-----------nd -----------how----------- to----------- in-----------ter-----------pre-----------t t-----------he -----------acc-----------ele-----------rat-----------ion----------- va-----------lue-----------s, -----------and----------- to----------- un-----------der-----------sta-----------nd -----------tol-----------era-----------nce-----------s a-----------nd -----------tes-----------tin-----------g t-----------hem----------- in----------- re-----------lat-----------ion----------- to----------- fl-----------oat-----------ing----------- po-----------int----------- va-----------lue-----------s. -----------It -----------was----------- al-----------so -----------to -----------und-----------ers-----------tan-----------d h-----------ow -----------to -----------tes-----------t m-----------ult-----------ipl-----------e c-----------ond-----------iti-----------ons-----------.
Not Rated(0)