Skip to content

Commit 79094dc

Browse files
discard the first samples out of the accelerometer
1 parent 0b9fde5 commit 79094dc

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

firmware/WatsonIoT/src/main.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,18 @@ void StartADXL355() {
198198
Serial.println("Initializing sensor");
199199
adxl355.initializeSensor(range, odr_lpf, debug);
200200
Serial.println("Calibrating sensor");
201-
adxl355.calibrateSensor(5, debug);
201+
adxl355.calibrateSensor(20, debug); // This has been increased to make traces start closer to zero
202202
Serial.println("ADXL355 Accelerometer activated");
203+
204+
bool bDiscardInitialADXLreadings = true ;
205+
while( bDiscardInitialADXLreadings ) {
206+
adxstatus = adxl355.getStatus();
207+
if (adxstatus & Adxl355::STATUS_VALUES::FIFO_FULL) {
208+
adxl355.readFifoEntries( (long *)fifoOut ) ;
209+
bDiscardInitialADXLreadings = false;
210+
}
211+
}
212+
Serial.println("ADXL355 Accelerometer first samples discarded");
203213
}
204214
else {
205215
Serial.println("Unable to get accelerometer");
@@ -866,35 +876,29 @@ void loop() {
866876
// Do some STA / LTA math here...
867877
// ...
868878
if( StaLtaQue.isFull() ) {
869-
//// find offset
879+
/////////////////// find offset ////////////////
870880
int queCount = StaLtaQue.getCount( );
871-
// But why are the first two z samples bad ?
872-
// Start from 2 to compensate
873-
for (int idx = 2; idx < queCount; idx++) {
881+
882+
for (int idx = 0; idx < queCount; idx++) {
874883
AccelReading AccelRecord;
875884
if( StaLtaQue.peekIdx( &AccelRecord, idx) ) {
876885
sample[0] = AccelRecord.x;
877886
sample[1] = AccelRecord.y;
878887
sample[2] = AccelRecord.z;
879-
// But why are the first two z samples bad ?
880-
// Serial.printf(".sample[2] = %f ", sample[2]);
881888
for (int j = 0; j < 3; j++) {
882889
sampleSUM[j] += sample[j];
883890
}
884891
}
885892
}
886-
// Serial.printf(".offset = ");
887893
for (int j = 0; j < 3; j++) {
888894
offset[j] = sampleSUM[j] / (QUE_len-2);
889-
// Serial.printf( " %f ", offset[j]);
890895
}
891-
// Serial.printf("\n");
892-
893-
//// find lta
896+
897+
/////////////////// find lta /////////////////
894898
sampleSUM[0] = 0;
895899
sampleSUM[1] = 0;
896900
sampleSUM[2] = 0;
897-
for (int idx = 2; idx < LTA_len; idx++) {
901+
for (int idx = 0; idx < LTA_len; idx++) {
898902
AccelReading AccelRecord;
899903
if( StaLtaQue.peekIdx( &AccelRecord, idx) ) {
900904
sampleABS[0] = abs( AccelRecord.x - offset[0] );
@@ -905,13 +909,11 @@ void loop() {
905909
}
906910
}
907911
}
908-
// Serial.printf(".sum32abs = ");
909912
for (int j = 0; j < 3; j++) {
910913
ltav[j] = sampleSUM[j] / (LTA_len-2);
911-
// Serial.printf( " %f ", sampleSUM[j]);
912914
}
913-
914-
//// find sta
915+
916+
//////////////////// find sta ///////////////////////
915917
sampleSUM[0] = 0;
916918
sampleSUM[1] = 0;
917919
sampleSUM[2] = 0;
@@ -932,12 +934,13 @@ void loop() {
932934
if ( bPossibleEarthQuake==false ) {
933935
if ( stalta[j] >= thresh ) {
934936
// Whoa - STA/LTA algorithm detected some anomalous shaking
935-
Serial.printf("%f = %f / %f (%i) s0\n", stalta[j], stav[j], ltav[j], j );
937+
Serial.printf("STA/LTA = %f = %f / %f (%i)\n", stalta[j], stav[j], ltav[j], j );
938+
bPossibleEarthQuake = true ;
936939
}
937940
}
938941
}
939942

940-
//// find sta / lta for the other 31 samples but without doing the summing again
943+
//// find STA/LTA for the other 31 samples but without doing the summing again
941944

942945
for (int idx = LTA_len+1; idx < QUE_len; idx++) {
943946
AccelReading AccelRecord;
@@ -966,7 +969,7 @@ void loop() {
966969
if ( bPossibleEarthQuake==false ) {
967970
if ( stalta[j] >= thresh ) {
968971
// Whoa - STA/LTA algorithm detected some anomalous shaking
969-
Serial.printf("%f = %f / %f (%i)\n", stalta[j], stav[j], ltav[j], j );
972+
Serial.printf("STA/LTA = %f = %f / %f (%i)\n", stalta[j], stav[j], ltav[j], j );
970973
bPossibleEarthQuake = true ;
971974
}
972975
}

0 commit comments

Comments
 (0)