Skip to content

Commit 894a740

Browse files
authored
Merge pull request #3 from ayushc121/patch-1
Tried updating main to run main.cpp on a set of simulated inputs that we pull from a matlab run
2 parents f309b41 + 0746c9c commit 894a740

File tree

1 file changed

+75
-12
lines changed

1 file changed

+75
-12
lines changed

cpp/src/main.cpp

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,86 @@
11
#include <Arduino.h>
22
#include "matlab_funcs.hpp"
3+
#include "sample_data.hpp" // contains x_est_arr, z_arr, covar_arr, dT_arr, GND_arr, exp_x_est_arr
34

45
void setup() {
5-
Serial.begin(115200);
6-
Serial.println("Connected - starting benchmark");
6+
Serial.begin(115200);
7+
Serial.println("Connected - starting astra sim");
78

8-
Vector13 x_est;
9-
t_constantsASTRA constantsASTRA;
10-
Vector15 z;
11-
double dT;
12-
double GND;
9+
t_constantsASTRA constantsASTRA;
10+
11+
/* NOT SURE IF THIS IS NECESSARY OR DONE CORRECTLY??
12+
constantsASTRA.m = 1.0;
13+
constantsASTRA.l = 1.0;
14+
constantsASTRA.g = 9.81;
15+
constantsASTRA.rTB = 0.1;
16+
constantsASTRA.j = Matrix3_3::Identity();
17+
constantsASTRA.T = 1.0;
18+
constantsASTRA.mag << 0, 0, 1;
19+
*/
20+
21+
// Covariance matrix (estimated) (makes more sense to use a per-step Q but I'm not sure how to find that...)
22+
Matrix12_12 Q_matrix = Matrix12_12::Zero();
23+
// Quaternion noise
24+
Q_matrix(0,0) = 1e-6;
25+
Q_matrix(1,1) = 1e-6;
26+
Q_matrix(2,2) = 1e-6;
27+
28+
// Position noise
29+
Q_matrix(3,3) = 1e-4;
30+
Q_matrix(4,4) = 1e-4;
31+
Q_matrix(5,5) = 1e-4;
32+
33+
// Velocity noise
34+
Q_matrix(6,6) = 1e-3;
35+
Q_matrix(7,7) = 1e-3;
36+
Q_matrix(8,8) = 1e-3;
37+
38+
// Gyro bias noise
39+
Q_matrix(9,9) = 1e-8;
40+
Q_matrix(10,10) = 1e-8;
41+
Q_matrix(11,11) = 1e-8;
42+
43+
long long start_t = millis();
1344

14-
Matrix12_12 P = 1 * Matrix12_12::Identity();
45+
bool new_imu_packet; //NOT SURE HOW TO INITIALIZE THESE...
46+
bool new_gps_packet;
47+
Matrix12_12 P = 1 * Matrix12_12::Identity();
1548

16-
bool new_imu_packet;
17-
bool new_gps_packet;
1849

19-
EstimateStateFCN(x_est, constantsASTRA, z, dT, GND, P, new_imu_packet, new_gps_packet);
50+
// Loop over all timesteps
51+
for (int idx = 0; idx < MAX_IDX; idx++) {
52+
53+
// Construct Eigen vectors directly from arrays
54+
Vector12 x_est(x_est_arr[idx]);
55+
Vector15 z(z_arr[idx]);
56+
Vector3 covar_vec(covar_arr[idx]);
57+
58+
double dT_val = dT_arr[idx];
59+
double GND_val = GND_arr[idx];
60+
61+
Vector12 ret_state = EstimateStateFCN(x_est, constantsASTRA, z, covar_vec, dT_val, Q_matrix, GND_val, P, new_imu_packet, new_gps_packet);
62+
63+
// comparison with expected output
64+
for (int i = 0; i < 12; i++) {
65+
if (abs(ret_state(i) - exp_x_est_arr[idx][i]) > 0.0002) {
66+
Serial.print("Mismatch at idx: ");
67+
Serial.print(idx);
68+
Serial.print(" element: ");
69+
Serial.print(i);
70+
Serial.print(" expected: ");
71+
Serial.print(exp_x_est_arr[idx][i], 6);
72+
Serial.print(" got: ");
73+
Serial.println(ret_state(i), 6);
74+
}
75+
}
76+
}
77+
78+
long long end_t = millis();
79+
80+
Serial.print("Finished astra sim in ");
81+
Serial.print(end_t - start_t);
82+
Serial.println(" ms.");
2083
}
2184

2285
void loop() {
23-
}
86+
}

0 commit comments

Comments
 (0)