-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathugh
More file actions
128 lines (92 loc) · 3.06 KB
/
Copy pathugh
File metadata and controls
128 lines (92 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <Wire.h>
#include <MPU6050.h>
float accel = 0.0;
MPU6050 mpu;
void setup()
{
Serial.begin(9600);
// Initialize MPU6050
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
delay(500);
}
checkSettings();
Serial.println("Fall Detection Software On!");
}
void checkSettings()
{
switch(mpu.getClockSource())
{
case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break;
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break;
case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break;
case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break;
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break;
}
switch(mpu.getRange())
{
case MPU6050_RANGE_16G: Serial.println("+/- 16 g"); break;
case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;
case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;
case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;
}
}
/*
Serial.print(" * Accelerometer offsets: ");
Serial.print(mpu.getAccelOffsetX());
Serial.print(" / ");
Serial.print(mpu.getAccelOffsetY());
Serial.print(" / ");
Serial.println(mpu.getAccelOffsetZ());
Serial.println();
*/
void loop()
{
Vector rawGyro = mpu.readRawGyro();
Vector normGyro = mpu.readNormalizeGyro();
// Gyroscope Data
//Serial.print(" Xraw = ");
//Serial.print(rawGyro.XAxis);
//Serial.print(" Yraw = ");
//Serial.print(rawGyro.YAxis);
//Serial.print(" Zraw = ");
//Serial.println(rawGyro.ZAxis);
// Serial.print(" Gyro Xnorm = ");
//Serial.print(normGyro.XAxis);
//Serial.print(" Gyro Ynorm = ");
//Serial.print(normGyro.YAxis);
//Serial.print(" Gyro Znorm = ");
//Serial.println(normGyro.ZAxis);
// Accelerometer Data
Vector rawAccel = mpu.readRawAccel();
Vector normAccel = mpu.readNormalizeAccel();
// Serial.print(" Xraw = ");
//Serial.print(rawAccel.XAxis);
float xnorm = normAccel.XAxis;
//Serial.print(" Yraw = ");
// Serial.print(rawAccel.YAxis);
float ynorm = normAccel.YAxis;
//Serial.print(" Zraw = ");
// Serial.println(rawAccel.ZAxis);
float znorm = normAccel.ZAxis;
//Serial.print(" Acc Xnorm = ");
//Serial.print(normAccel.XAxis);
// Serial.print(" Acc Ynorm = ");
//Serial.print(normAccel.YAxis);
// Serial.print(" Acc Znorm = ");
// Serial.println(normAccel.ZAxis);
accel = sqrt(xnorm* xnorm + ynorm * ynorm + znorm*znorm);
Serial.print("Z-norm: ");
Serial.println(znorm);
Serial.println("Accel: ");
Serial.println(accel);
//Serial.println(accel);
if (znorm <-1)
{
Serial.println("Fall detected. Predicited Severity: HIGH RISK");
delay(10000);
}
delay(10);
}