Updated references from MPU6050 to BNO080

Dependencies:   QEI2 PID Watchdog VL53L1X_Filter BNOWrapper ros_lib_kinetic

Dependents:   Version1-8

Committer:
t1jain
Date:
Wed Aug 07 19:01:17 2019 +0000
Revision:
42:62c49ad06707
Parent:
35:5a2fed4c2e9f
Changed references from MPU6050 to BNO080

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JesiMiranda 35:5a2fed4c2e9f 1
JesiMiranda 35:5a2fed4c2e9f 2 #include "Statistics.h"
JesiMiranda 35:5a2fed4c2e9f 3 #include "mbed.h"
JesiMiranda 35:5a2fed4c2e9f 4
JesiMiranda 35:5a2fed4c2e9f 5 /**************************************************************************
JesiMiranda 35:5a2fed4c2e9f 6 * This function initializes the private members of the class Statistics *
JesiMiranda 35:5a2fed4c2e9f 7 **************************************************************************/
JesiMiranda 35:5a2fed4c2e9f 8 Statistics::Statistics(int* Input, double dataLengthIn, int firstDataPointIn){
JesiMiranda 35:5a2fed4c2e9f 9 data = Input;
JesiMiranda 35:5a2fed4c2e9f 10 dataLength = dataLengthIn;
JesiMiranda 35:5a2fed4c2e9f 11 firstDataPoint = firstDataPointIn;
JesiMiranda 35:5a2fed4c2e9f 12 }
JesiMiranda 35:5a2fed4c2e9f 13
JesiMiranda 35:5a2fed4c2e9f 14 /**************************************************************************
JesiMiranda 35:5a2fed4c2e9f 15 * This function returns the mean(average) of an array. *
JesiMiranda 35:5a2fed4c2e9f 16 **************************************************************************/
JesiMiranda 35:5a2fed4c2e9f 17 double Statistics::mean(){
JesiMiranda 35:5a2fed4c2e9f 18 double sum;
JesiMiranda 35:5a2fed4c2e9f 19 for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i)
JesiMiranda 35:5a2fed4c2e9f 20 {
JesiMiranda 35:5a2fed4c2e9f 21 sum += data[i];
JesiMiranda 35:5a2fed4c2e9f 22 }
JesiMiranda 35:5a2fed4c2e9f 23 //printf("sum %f, data length %f\r\n", sum, dataLength);
JesiMiranda 35:5a2fed4c2e9f 24 wait(.001);
JesiMiranda 35:5a2fed4c2e9f 25 double average = sum/dataLength;
JesiMiranda 35:5a2fed4c2e9f 26 return average;
JesiMiranda 35:5a2fed4c2e9f 27 }
JesiMiranda 35:5a2fed4c2e9f 28
JesiMiranda 35:5a2fed4c2e9f 29 /**************************************************************************
JesiMiranda 35:5a2fed4c2e9f 30 * This function returns the standard deviation of an array. This is *
JesiMiranda 35:5a2fed4c2e9f 31 * used to determine whether the data is valid or not. *
JesiMiranda 35:5a2fed4c2e9f 32 **************************************************************************/
JesiMiranda 35:5a2fed4c2e9f 33 double Statistics::stdev(){
JesiMiranda 35:5a2fed4c2e9f 34 double sum = 0.0, mean, standardDeviation = 0.0;
JesiMiranda 35:5a2fed4c2e9f 35 //printf("The length of the array is %d\n", dataLength);
JesiMiranda 35:5a2fed4c2e9f 36 //double num = (pow(2.0,2.0));
JesiMiranda 35:5a2fed4c2e9f 37 //printf("2^2 is %f\n", num);
JesiMiranda 35:5a2fed4c2e9f 38 //int i;
JesiMiranda 35:5a2fed4c2e9f 39
JesiMiranda 35:5a2fed4c2e9f 40 for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i)
JesiMiranda 35:5a2fed4c2e9f 41 {
JesiMiranda 35:5a2fed4c2e9f 42 sum += data[i];
JesiMiranda 35:5a2fed4c2e9f 43 //printf("%d\n", data[i]);
JesiMiranda 35:5a2fed4c2e9f 44 }
JesiMiranda 35:5a2fed4c2e9f 45
JesiMiranda 35:5a2fed4c2e9f 46 mean = sum/dataLength;
JesiMiranda 35:5a2fed4c2e9f 47
JesiMiranda 35:5a2fed4c2e9f 48 for(int i = firstDataPoint; i < (firstDataPoint + dataLength); ++i) {
JesiMiranda 35:5a2fed4c2e9f 49 //standardDeviation += pow(data[i] - mean, 2);
JesiMiranda 35:5a2fed4c2e9f 50 standardDeviation += (data[i] - mean)*(data[i] - mean);
JesiMiranda 35:5a2fed4c2e9f 51 }
JesiMiranda 35:5a2fed4c2e9f 52
JesiMiranda 35:5a2fed4c2e9f 53 return sqrt(standardDeviation / dataLength);
JesiMiranda 35:5a2fed4c2e9f 54 }