1- #include " controller .h"
1+ #include " controller_and_estimator .h"
22#include " matlab_funcs.h"
33
4- namespace Controller {
4+ namespace ControllerAndEstimator {
55constantsASTRA_t constantsASTRA;
66Matrix18_18 P;
77Matrix9_9 Flight_P;
8- Vector13 x_est;
8+ Vector19 x_est;
99Vector3 lastEMA;
1010Matrix9_4 dnf_X;
1111Matrix9_4 dnf_Y;
@@ -14,17 +14,13 @@ bool last_GND;
1414
1515unsigned long last_call_time; // ms
1616
17- void begin () {
18- reset_controller_state ();
19- }
20-
21- void reset_controller_state () {
17+ void init_controller_and_estimator_constants () {
2218 constantsASTRA.g = 9.8015 ;
2319 constantsASTRA.m = 1.2490 ;
2420 constantsASTRA.mag << -0.4512 , 0 , 0.8924 ;
25- constantsASTRA.Q << 2.500083e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //
26- 0 , 2.500083e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //
27- 0 , 0 , 2.500083e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , //
21+ constantsASTRA.Q << 1.000017e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //
22+ 0 , 1.000017e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , //
23+ 0 , 0 , 1.000017e -06 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -2.500000e-07 , 0 , 0 , 0 , 0 , 0 , 0 , //
2824 0 , 0 , 0 , 2.083349e-09 , 0 , 0 , 6.250078e-07 , 0 , 0 , 0 , 0 , 0 , -2.083333e-09 , 0 , 0 , 0 , 0 , 0 , //
2925 0 , 0 , 0 , 0 , 2.083349e-09 , 0 , 0 , 6.250078e-07 , 0 , 0 , 0 , 0 , 0 , -2.083333e-09 , 0 , 0 , 0 , 0 , //
3026 0 , 0 , 0 , 0 , 0 , 2.083349e-09 , 0 , 0 , 6.250078e-07 , 0 , 0 , 0 , 0 , 0 , -2.083333e-09 , 0 , 0 , 0 , //
@@ -45,13 +41,12 @@ void reset_controller_state() {
4541 constantsASTRA.R .block <3 , 3 >(0 , 0 ) = Matrix3_3::Identity () * 0.100 ;
4642 constantsASTRA.R .block <3 , 3 >(3 , 3 ) = Matrix3_3::Identity () * 0.100 ;
4743
48- constantsASTRA.K_Att << 1.341480e+00 , -4.423127e-16 , -2.263115e-17 , 1.949556e-01 , -3.652184e-17 , -5.666956e-17 , -6.582806e-01 , 5.461372e-16 , -2.780114e-16 , //
49- 4.924545e-16 , 1.341480e+00 , -3.901911e-16 , 5.099383e-17 , 1.949556e-01 , -3.192517e-16 , -2.775558e-16 , -6.582806e-01 , -2.514962e-16 , //
50- -4.006925e-16 , 5.609321e-16 , 4.035990e+00 , -5.718917e-17 , 1.014174e-16 , 2.059154e+00 , 3.453548e-16 , -4.435380e-16 , -1.581139e+00 ; //
51- //
44+ constantsASTRA.K_Att << 8.722500e-01 , -1.643694e-16 , -8.894669e-16 , 1.345039e-01 , 7.189700e-19 , -7.736332e-17 , -4.787136e-01 , 3.300943e-16 , 4.539530e-16 , //
45+ 6.198463e-16 , 8.722500e-01 , -1.023859e-15 , 4.915936e-17 , 1.345039e-01 , -2.388831e-16 , -1.440612e-15 , -4.787136e-01 , 3.240570e-16 , //
46+ -9.959333e-17 , 7.261800e-16 , 4.035990e+00 , -9.370403e-17 , 2.685714e-17 , 2.059154e+00 , 7.242069e-16 , 2.974059e-16 , -1.581139e+00 ; //
5247
5348 P = 1 * Matrix18_18::Identity ();
54- x_est = Vector13 ::Zero ();
49+ x_est = Vector19 ::Zero ();
5550 x_est[0 ] = 1 ;
5651 lastEMA = Vector3::Zero ();
5752 dnf_X = Matrix9_4::Ones ();
@@ -84,6 +79,7 @@ Controller_Output get_controller_output(Controller_Input ci) {
8479
8580 if (!ci.GND_val && last_GND) { // we left GND this frame
8681 Flight_P = P.block <9 , 9 >(0 , 0 );
82+ ASTRAv2_Controller_reset (); // reset integral gains in the controller itself
8783 }
8884
8985 if (ci.GND_val ) {
@@ -92,8 +88,7 @@ Controller_Output get_controller_output(Controller_Input ci) {
9288 x_est = FlightEstimator (x_est, constantsASTRA, z, dT, Flight_P, ci.new_gps_packet );
9389 }
9490
95- Vector3 EMA_G = EMA_Gyros (z, lastEMA);
96- Vector16 X = StateAUG (x_est, EMA_G);
91+ Vector16 X = StateAUG (x_est.segment <13 >(0 ), z.segment <3 >(3 ));
9792 Vector3 TargetPos;
9893 TargetPos << ci.target_pos_north , ci.target_pos_west , ci.target_pos_up ;
9994 Vector4 raw_co = ASTRAv2_Controller (TargetPos, X, constantsASTRA, dT);
0 commit comments