-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thrust_Measurements.ino
162 lines (127 loc) · 2.99 KB
/
Thrust_Measurements.ino
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <HX711.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;
const int CS = 10;
HX711 scale;
double mtime;
double force;
double dt;
double dp;
double impulse;
double last;
double ig;
File dataFile;
void setup() {
Serial.begin(57600);
int done = 0; // Global
Serial.println("First column - time elasped.");
delay(500);
Serial.println("Second column - thrust measured in N");
delay(500);
Serial.println("Third Column - Total Impulse");
delay(500);
Serial.println("Press G and Enter to continue");
Serial.println("...");
delay(100);
Serial.println("...");
delay(100);
Serial.println("...");
delay(100);
Serial.println("...");
delay(100);
while(done == 0)
{
while (Serial.available() > 0)
{
if (Serial.read() == 'G')
{
done = 1;
}
}
}
while(Serial.available() > 0)
{
byte dummyread = Serial.read();
}
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
double taret = 80;
scale.tare(taret);
scale.set_scale(8.60f);
mtime = micros()/1000000.f;
force = scale.get_units()*0.009806f;
dt = 1/80.f;
dp = force*dt;
impulse = impulse + dp;
last = mtime;
ig = mtime + 10.f;
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
Serial.print("Initializing SD card...");
Serial.println("\n");
if (!SD.begin(CS))
{
Serial.println("\n");
Serial.println("initialization failed!");
Serial.println("\n");
while (1);
}
Serial.print("Time");
Serial.print("\t");
Serial.print("Thrust(N)");
Serial.print("\t");
Serial.print("Total-Impulse");
Serial.println("\n");
dataFile = SD.open("THRUST.csv" , FILE_WRITE);
if (dataFile) {
Serial.print("Writing to THRUST.csv...");
Serial.println("\n");
dataFile.println("THRUST MEASUREMENT ");
dataFile.print("\n");
dataFile.print("Time");
dataFile.print("\t");
dataFile.print("Thrust(N)");
dataFile.print("\t");
dataFile.print("Total-Impulse");
dataFile.print("\n");
dataFile.close();
} else {
Serial.println("error opening file");
Serial.println("\n");
}
}
void loop() {
mtime = micros()/1000000.f;
force = scale.get_units()*0.009806f;
dt = mtime-last;
dp = force*dt;
impulse = impulse + dp;
last = mtime;
Serial.println(mtime,10);
Serial.print("\t");
Serial.print(force,10);
Serial.print("\t");
Serial.print(impulse,10);
dataFile = SD.open("THRUST.csv" , FILE_WRITE);
if (dataFile)
{
dataFile.print(mtime);
dataFile.print("\t");
dataFile.print(force);
dataFile.print("\t");
dataFile.print(impulse);
dataFile.close();
}
else
Serial.println("error opening file");
//sd card data logging
if (ig <= mtime && ig + 2 >= mtime){
digitalWrite(10, HIGH);
}
else{
digitalWrite(10, LOW);
}
}