Skip to content

Commit

Permalink
Update bbn_wave_freq_m5atomS3.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Sep 10, 2024
1 parent 0197963 commit edebd88
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bbn_wave_freq_m5atomS3/bbn_wave_freq_m5atomS3.ino
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void startCalibration(void) {

int produce_serial_data = 1;

float t = 0.0;
float heave_avg = 0.0;
float wave_length = 0.0;
float heave_trochoid = 0.0;
Expand Down Expand Up @@ -175,8 +176,9 @@ void repeatMe() {
accel_rotated.y = rotated_a[1];
accel_rotated.z = rotated_a[2];

float a = (accel_rotated.z - 1.0); // acceleration in fractions of g
//float a = - 0.25 * PI * PI * sin(2 * PI * state.t * 0.25) / g_std; // dummy test data (amplitude of heave = 1m, 4sec - period)
//float a = (accel_rotated.z - 1.0); // acceleration in fractions of g
float a = - 0.25 * PI * PI * sin(2 * PI * t * 0.25) / g_std; // dummy test data (amplitude of heave = 1m, 4sec - period)
float h = 0.25 * PI * PI / (2 * PI * 0.25) / (2 * PI * 0.25) * sin(2 * PI * t * 0.25);

float speed_prev = waveState.vert_speed;
kalman_wave_step(&waveState, a * g_std, delta_t);
Expand All @@ -185,8 +187,8 @@ void repeatMe() {
float speed = waveState.vert_speed;

float y = heave;
aranovskiy_update(&params, &state, y, delta_t);
double freq = state.f;
//aranovskiy_update(&params, &state, y, delta_t);
double freq = 1.0; //state.f;

if (first) {
kalman_smoother_set_initial(&kalman_freq, freq);
Expand Down Expand Up @@ -230,17 +232,18 @@ void repeatMe() {
if (produce_serial_data) {
Serial.printf("heave_cm:%.4f", heave * 100);
Serial.printf(",heave_trochoid:%.4f", heave_trochoid * 100);
Serial.printf(",h_cm:%.4f", h * 100);
Serial.printf(",height_cm:%.4f", wave_height * 100);
//Serial.printf(",max_cm:%.4f", min_max_h.max.value * 100);
//Serial.printf(",min_cm:%.4f", min_max_h.min.value * 100);
//Serial.printf(",heave_avg_cm:%.4f", heave_avg * 100);
Serial.printf(",freq_adj:%.4f", freq_adj * 100);
Serial.printf(",freq_troch:%.4f", wave_freq_trochoid * 100);
Serial.printf(",freq_troch_adj:%.4f", wave_freq_trochoid_adj * 100);
Serial.printf(",period_decisec:%.4f", period * 10);
Serial.printf(",period_troch_decisec:%.4f", period_trochoid * 10);
//Serial.printf(",freq_adj:%.4f", freq_adj * 100);
//Serial.printf(",freq_troch:%.4f", wave_freq_trochoid * 100);
//Serial.printf(",freq_troch_adj:%.4f", wave_freq_trochoid_adj * 100);
//Serial.printf(",period_decisec:%.4f", period * 10);
//Serial.printf(",period_troch_decisec:%.4f", period_trochoid * 10);
//Serial.printf(",accel abs:%0.4f", g_std * sqrt(accel.x * accel.x + accel.y * accel.y + accel.z * accel.z));
Serial.printf(",accel bias:%0.4f", accel_bias);
//Serial.printf(",accel bias:%0.4f", accel_bias);
Serial.println();
}
else {
Expand All @@ -264,6 +267,7 @@ void repeatMe() {
got_samples = 0;
}
}
t = t + delta_t;
}
else {
AtomS3.update();
Expand Down

0 comments on commit edebd88

Please sign in to comment.