From e569578cf9a84a1bcbbc4843a3c28a5fa4909235 Mon Sep 17 00:00:00 2001 From: Paul Riseborough Date: Sat, 4 Mar 2017 12:01:52 +1100 Subject: [PATCH] EKF: add derivation for body frame velocity measurements --- .../GenerateNavFilterEquations.m | 88 +++++++++++++ matlab/scripts/Inertial Nav EKF/H_VELX.c | 7 ++ matlab/scripts/Inertial Nav EKF/H_VELY.c | 7 ++ matlab/scripts/Inertial Nav EKF/H_VELZ.c | 7 ++ matlab/scripts/Inertial Nav EKF/K_VELX.c | 116 ++++++++++++++++++ matlab/scripts/Inertial Nav EKF/K_VELY.c | 116 ++++++++++++++++++ matlab/scripts/Inertial Nav EKF/K_VELZ.c | 116 ++++++++++++++++++ 7 files changed, 457 insertions(+) create mode 100644 matlab/scripts/Inertial Nav EKF/H_VELX.c create mode 100644 matlab/scripts/Inertial Nav EKF/H_VELY.c create mode 100644 matlab/scripts/Inertial Nav EKF/H_VELZ.c create mode 100644 matlab/scripts/Inertial Nav EKF/K_VELX.c create mode 100644 matlab/scripts/Inertial Nav EKF/K_VELY.c create mode 100644 matlab/scripts/Inertial Nav EKF/K_VELZ.c diff --git a/matlab/scripts/Inertial Nav EKF/GenerateNavFilterEquations.m b/matlab/scripts/Inertial Nav EKF/GenerateNavFilterEquations.m index 929113abbb..59b349fb43 100644 --- a/matlab/scripts/Inertial Nav EKF/GenerateNavFilterEquations.m +++ b/matlab/scripts/Inertial Nav EKF/GenerateNavFilterEquations.m @@ -289,6 +289,94 @@ fix_c_code('K_LOSY.c'); clear all; reset(symengine); +%% derive equations for sequential fusion of body frame velocity measurements +load('StatePrediction.mat'); + +% body frame velocity observations +syms velX velY velZ real; + +% velocity observation variance +syms R_VEL real; + +% calculate relative velocity in body frame +relVelBody = transpose(Tbn)*[vn;ve;vd]; + +save('temp1.mat','relVelBody','R_VEL'); + +% calculate the observation Jacobian for the X axis +H_VELX = jacobian(relVelBody(1),stateVector); % measurement Jacobian +H_VELX = simplify(H_VELX); +save('temp2.mat','H_VELX'); +ccode(H_VELX,'file','H_VELX.c'); +fix_c_code('H_VELX.c'); + +clear all; +reset(symengine); +load('StatePrediction.mat'); +load('temp1.mat'); + +% calculate the observation Jacobian for the Y axis +H_VELY = jacobian(relVelBody(2),stateVector); % measurement Jacobian +H_VELY = simplify(H_VELY); +save('temp3.mat','H_VELY'); +ccode(H_VELY,'file','H_VELY.c'); +fix_c_code('H_VELY.c'); + +clear all; +reset(symengine); +load('StatePrediction.mat'); +load('temp1.mat'); + +% calculate the observation Jacobian for the Z axis +H_VELZ = jacobian(relVelBody(3),stateVector); % measurement Jacobian +H_VELZ = simplify(H_VELZ); +save('temp4.mat','H_VELZ'); +ccode(H_VELZ,'file','H_VELZ.c'); +fix_c_code('H_VELZ.c'); + +clear all; +reset(symengine); + +% calculate Kalman gain vector for the X axis +load('StatePrediction.mat'); +load('temp1.mat'); +load('temp2.mat'); + +K_VELX = (P*transpose(H_VELX))/(H_VELX*P*transpose(H_VELX) + R_VEL); % Kalman gain vector +K_VELX = simplify(K_VELX); +ccode(K_VELX,'file','K_VELX.c'); +fix_c_code('K_VELX.c'); + +clear all; +reset(symengine); + +% calculate Kalman gain vector for the Y axis +load('StatePrediction.mat'); +load('temp1.mat'); +load('temp3.mat'); + +K_VELY = (P*transpose(H_VELY))/(H_VELY*P*transpose(H_VELY) + R_VEL); % Kalman gain vector +K_VELY = simplify(K_VELY); +ccode(K_VELY,'file','K_VELY.c'); +fix_c_code('K_VELY.c'); + +clear all; +reset(symengine); + +% calculate Kalman gain vector for the Z axis +load('StatePrediction.mat'); +load('temp1.mat'); +load('temp4.mat'); + +K_VELZ = (P*transpose(H_VELZ))/(H_VELZ*P*transpose(H_VELZ) + R_VEL); % Kalman gain vector +K_VELZ = simplify(K_VELZ); +ccode(K_VELZ,'file','K_VELZ.c'); +fix_c_code('K_VELZ.c'); + +% reset workspace +clear all; +reset(symengine); + %% derive equations for fusion of 321 sequence yaw measurement load('StatePrediction.mat'); diff --git a/matlab/scripts/Inertial Nav EKF/H_VELX.c b/matlab/scripts/Inertial Nav EKF/H_VELX.c new file mode 100644 index 0000000000..4e1fa5bea4 --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/H_VELX.c @@ -0,0 +1,7 @@ +A0[0][0] = q2*vd*-2.0+q3*ve*2.0+q0*vn*2.0; +A0[0][1] = q3*vd*2.0+q2*ve*2.0+q1*vn*2.0; +A0[0][2] = q0*vd*-2.0+q1*ve*2.0-q2*vn*2.0; +A0[0][3] = q1*vd*2.0+q0*ve*2.0-q3*vn*2.0; +A0[0][4] = q0*q0+q1*q1-q2*q2-q3*q3; +A0[0][5] = q0*q3*2.0+q1*q2*2.0; +A0[0][6] = q0*q2*-2.0+q1*q3*2.0; diff --git a/matlab/scripts/Inertial Nav EKF/H_VELY.c b/matlab/scripts/Inertial Nav EKF/H_VELY.c new file mode 100644 index 0000000000..2145409fb4 --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/H_VELY.c @@ -0,0 +1,7 @@ +A0[0][0] = q1*vd*2.0+q0*ve*2.0-q3*vn*2.0; +A0[0][1] = q0*vd*2.0-q1*ve*2.0+q2*vn*2.0; +A0[0][2] = q3*vd*2.0+q2*ve*2.0+q1*vn*2.0; +A0[0][3] = q2*vd*2.0-q3*ve*2.0-q0*vn*2.0; +A0[0][4] = q0*q3*-2.0+q1*q2*2.0; +A0[0][5] = q0*q0-q1*q1+q2*q2-q3*q3; +A0[0][6] = q0*q1*2.0+q2*q3*2.0; diff --git a/matlab/scripts/Inertial Nav EKF/H_VELZ.c b/matlab/scripts/Inertial Nav EKF/H_VELZ.c new file mode 100644 index 0000000000..6b8b4ff00b --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/H_VELZ.c @@ -0,0 +1,7 @@ +A0[0][0] = q0*vd*2.0-q1*ve*2.0+q2*vn*2.0; +A0[0][1] = q1*vd*-2.0-q0*ve*2.0+q3*vn*2.0; +A0[0][2] = q2*vd*-2.0+q3*ve*2.0+q0*vn*2.0; +A0[0][3] = q3*vd*2.0+q2*ve*2.0+q1*vn*2.0; +A0[0][4] = q0*q2*2.0+q1*q3*2.0; +A0[0][5] = q0*q1*-2.0+q2*q3*2.0; +A0[0][6] = q0*q0-q1*q1-q2*q2+q3*q3; diff --git a/matlab/scripts/Inertial Nav EKF/K_VELX.c b/matlab/scripts/Inertial Nav EKF/K_VELX.c new file mode 100644 index 0000000000..6162ece2c0 --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/K_VELX.c @@ -0,0 +1,116 @@ +t2 = q0*q3*2.0; +t3 = q1*q2*2.0; +t4 = t2+t3; +t5 = q0*q0; +t6 = q1*q1; +t7 = q2*q2; +t8 = q3*q3; +t9 = t5+t6-t7-t8; +t10 = q0*q2*2.0; +t25 = q1*q3*2.0; +t11 = t10-t25; +t12 = q3*ve*2.0; +t13 = q0*vn*2.0; +t26 = q2*vd*2.0; +t14 = t12+t13-t26; +t15 = q3*vd*2.0; +t16 = q2*ve*2.0; +t17 = q1*vn*2.0; +t18 = t15+t16+t17; +t19 = q0*vd*2.0; +t20 = q2*vn*2.0; +t27 = q1*ve*2.0; +t21 = t19+t20-t27; +t22 = q1*vd*2.0; +t23 = q0*ve*2.0; +t28 = q3*vn*2.0; +t24 = t22+t23-t28; +t29 = P[0][0]*t14; +t30 = P[1][1]*t18; +t31 = P[4][5]*t9; +t32 = P[5][5]*t4; +t33 = P[0][5]*t14; +t34 = P[1][5]*t18; +t35 = P[3][5]*t24; +t79 = P[6][5]*t11; +t80 = P[2][5]*t21; +t36 = t31+t32+t33+t34+t35-t79-t80; +t37 = t4*t36; +t38 = P[4][6]*t9; +t39 = P[5][6]*t4; +t40 = P[0][6]*t14; +t41 = P[1][6]*t18; +t42 = P[3][6]*t24; +t81 = P[6][6]*t11; +t82 = P[2][6]*t21; +t43 = t38+t39+t40+t41+t42-t81-t82; +t44 = P[4][0]*t9; +t45 = P[5][0]*t4; +t46 = P[1][0]*t18; +t47 = P[3][0]*t24; +t84 = P[6][0]*t11; +t85 = P[2][0]*t21; +t48 = t29+t44+t45+t46+t47-t84-t85; +t49 = t14*t48; +t50 = P[4][1]*t9; +t51 = P[5][1]*t4; +t52 = P[0][1]*t14; +t53 = P[3][1]*t24; +t86 = P[6][1]*t11; +t87 = P[2][1]*t21; +t54 = t30+t50+t51+t52+t53-t86-t87; +t55 = t18*t54; +t56 = P[4][2]*t9; +t57 = P[5][2]*t4; +t58 = P[0][2]*t14; +t59 = P[1][2]*t18; +t60 = P[3][2]*t24; +t78 = P[2][2]*t21; +t88 = P[6][2]*t11; +t61 = t56+t57+t58+t59+t60-t78-t88; +t62 = P[4][3]*t9; +t63 = P[5][3]*t4; +t64 = P[0][3]*t14; +t65 = P[1][3]*t18; +t66 = P[3][3]*t24; +t90 = P[6][3]*t11; +t91 = P[2][3]*t21; +t67 = t62+t63+t64+t65+t66-t90-t91; +t68 = t24*t67; +t69 = P[4][4]*t9; +t70 = P[5][4]*t4; +t71 = P[0][4]*t14; +t72 = P[1][4]*t18; +t73 = P[3][4]*t24; +t92 = P[6][4]*t11; +t93 = P[2][4]*t21; +t74 = t69+t70+t71+t72+t73-t92-t93; +t75 = t9*t74; +t83 = t11*t43; +t89 = t21*t61; +t76 = R_VEL+t37+t49+t55+t68+t75-t83-t89; +t77 = 1.0/t76; +A0[0][0] = t77*(t29+P[0][5]*t4+P[0][4]*t9-P[0][6]*t11+P[0][1]*t18-P[0][2]*t21+P[0][3]*t24); +A0[1][0] = t77*(t30+P[1][5]*t4+P[1][4]*t9+P[1][0]*t14-P[1][6]*t11-P[1][2]*t21+P[1][3]*t24); +A0[2][0] = t77*(-t78+P[2][5]*t4+P[2][4]*t9+P[2][0]*t14-P[2][6]*t11+P[2][1]*t18+P[2][3]*t24); +A0[3][0] = t77*(t66+P[3][5]*t4+P[3][4]*t9+P[3][0]*t14-P[3][6]*t11+P[3][1]*t18-P[3][2]*t21); +A0[4][0] = t77*(t69+P[4][5]*t4+P[4][0]*t14-P[4][6]*t11+P[4][1]*t18-P[4][2]*t21+P[4][3]*t24); +A0[5][0] = t77*(t32+P[5][4]*t9+P[5][0]*t14-P[5][6]*t11+P[5][1]*t18-P[5][2]*t21+P[5][3]*t24); +A0[6][0] = t77*(-t81+P[6][5]*t4+P[6][4]*t9+P[6][0]*t14+P[6][1]*t18-P[6][2]*t21+P[6][3]*t24); +A0[7][0] = t77*(P[7][5]*t4+P[7][4]*t9+P[7][0]*t14-P[7][6]*t11+P[7][1]*t18-P[7][2]*t21+P[7][3]*t24); +A0[8][0] = t77*(P[8][5]*t4+P[8][4]*t9+P[8][0]*t14-P[8][6]*t11+P[8][1]*t18-P[8][2]*t21+P[8][3]*t24); +A0[9][0] = t77*(P[9][5]*t4+P[9][4]*t9+P[9][0]*t14-P[9][6]*t11+P[9][1]*t18-P[9][2]*t21+P[9][3]*t24); +A0[10][0] = t77*(P[10][5]*t4+P[10][4]*t9+P[10][0]*t14-P[10][6]*t11+P[10][1]*t18-P[10][2]*t21+P[10][3]*t24); +A0[11][0] = t77*(P[11][5]*t4+P[11][4]*t9+P[11][0]*t14-P[11][6]*t11+P[11][1]*t18-P[11][2]*t21+P[11][3]*t24); +A0[12][0] = t77*(P[12][5]*t4+P[12][4]*t9+P[12][0]*t14-P[12][6]*t11+P[12][1]*t18-P[12][2]*t21+P[12][3]*t24); +A0[13][0] = t77*(P[13][5]*t4+P[13][4]*t9+P[13][0]*t14-P[13][6]*t11+P[13][1]*t18-P[13][2]*t21+P[13][3]*t24); +A0[14][0] = t77*(P[14][5]*t4+P[14][4]*t9+P[14][0]*t14-P[14][6]*t11+P[14][1]*t18-P[14][2]*t21+P[14][3]*t24); +A0[15][0] = t77*(P[15][5]*t4+P[15][4]*t9+P[15][0]*t14-P[15][6]*t11+P[15][1]*t18-P[15][2]*t21+P[15][3]*t24); +A0[16][0] = t77*(P[16][5]*t4+P[16][4]*t9+P[16][0]*t14-P[16][6]*t11+P[16][1]*t18-P[16][2]*t21+P[16][3]*t24); +A0[17][0] = t77*(P[17][5]*t4+P[17][4]*t9+P[17][0]*t14-P[17][6]*t11+P[17][1]*t18-P[17][2]*t21+P[17][3]*t24); +A0[18][0] = t77*(P[18][5]*t4+P[18][4]*t9+P[18][0]*t14-P[18][6]*t11+P[18][1]*t18-P[18][2]*t21+P[18][3]*t24); +A0[19][0] = t77*(P[19][5]*t4+P[19][4]*t9+P[19][0]*t14-P[19][6]*t11+P[19][1]*t18-P[19][2]*t21+P[19][3]*t24); +A0[20][0] = t77*(P[20][5]*t4+P[20][4]*t9+P[20][0]*t14-P[20][6]*t11+P[20][1]*t18-P[20][2]*t21+P[20][3]*t24); +A0[21][0] = t77*(P[21][5]*t4+P[21][4]*t9+P[21][0]*t14-P[21][6]*t11+P[21][1]*t18-P[21][2]*t21+P[21][3]*t24); +A0[22][0] = t77*(P[22][5]*t4+P[22][4]*t9+P[22][0]*t14-P[22][6]*t11+P[22][1]*t18-P[22][2]*t21+P[22][3]*t24); +A0[23][0] = t77*(P[23][5]*t4+P[23][4]*t9+P[23][0]*t14-P[23][6]*t11+P[23][1]*t18-P[23][2]*t21+P[23][3]*t24); diff --git a/matlab/scripts/Inertial Nav EKF/K_VELY.c b/matlab/scripts/Inertial Nav EKF/K_VELY.c new file mode 100644 index 0000000000..a5ce04f766 --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/K_VELY.c @@ -0,0 +1,116 @@ +t2 = q0*q3*2.0; +t9 = q1*q2*2.0; +t3 = t2-t9; +t4 = q0*q0; +t5 = q1*q1; +t6 = q2*q2; +t7 = q3*q3; +t8 = t4-t5+t6-t7; +t10 = q0*q1*2.0; +t11 = q2*q3*2.0; +t12 = t10+t11; +t13 = q1*vd*2.0; +t14 = q0*ve*2.0; +t26 = q3*vn*2.0; +t15 = t13+t14-t26; +t16 = q0*vd*2.0; +t17 = q2*vn*2.0; +t27 = q1*ve*2.0; +t18 = t16+t17-t27; +t19 = q3*vd*2.0; +t20 = q2*ve*2.0; +t21 = q1*vn*2.0; +t22 = t19+t20+t21; +t23 = q3*ve*2.0; +t24 = q0*vn*2.0; +t28 = q2*vd*2.0; +t25 = t23+t24-t28; +t29 = P[0][0]*t15; +t30 = P[1][1]*t18; +t31 = P[5][4]*t8; +t32 = P[6][4]*t12; +t33 = P[0][4]*t15; +t34 = P[1][4]*t18; +t35 = P[2][4]*t22; +t78 = P[4][4]*t3; +t79 = P[3][4]*t25; +t36 = t31+t32+t33+t34+t35-t78-t79; +t37 = P[5][6]*t8; +t38 = P[6][6]*t12; +t39 = P[0][6]*t15; +t40 = P[1][6]*t18; +t41 = P[2][6]*t22; +t81 = P[4][6]*t3; +t82 = P[3][6]*t25; +t42 = t37+t38+t39+t40+t41-t81-t82; +t43 = t12*t42; +t44 = P[5][0]*t8; +t45 = P[6][0]*t12; +t46 = P[1][0]*t18; +t47 = P[2][0]*t22; +t83 = P[4][0]*t3; +t84 = P[3][0]*t25; +t48 = t29+t44+t45+t46+t47-t83-t84; +t49 = t15*t48; +t50 = P[5][1]*t8; +t51 = P[6][1]*t12; +t52 = P[0][1]*t15; +t53 = P[2][1]*t22; +t85 = P[4][1]*t3; +t86 = P[3][1]*t25; +t54 = t30+t50+t51+t52+t53-t85-t86; +t55 = t18*t54; +t56 = P[5][2]*t8; +t57 = P[6][2]*t12; +t58 = P[0][2]*t15; +t59 = P[1][2]*t18; +t60 = P[2][2]*t22; +t87 = P[4][2]*t3; +t88 = P[3][2]*t25; +t61 = t56+t57+t58+t59+t60-t87-t88; +t62 = t22*t61; +t63 = P[5][3]*t8; +t64 = P[6][3]*t12; +t65 = P[0][3]*t15; +t66 = P[1][3]*t18; +t67 = P[2][3]*t22; +t89 = P[4][3]*t3; +t90 = P[3][3]*t25; +t68 = t63+t64+t65+t66+t67-t89-t90; +t69 = P[5][5]*t8; +t70 = P[6][5]*t12; +t71 = P[0][5]*t15; +t72 = P[1][5]*t18; +t73 = P[2][5]*t22; +t92 = P[4][5]*t3; +t93 = P[3][5]*t25; +t74 = t69+t70+t71+t72+t73-t92-t93; +t75 = t8*t74; +t80 = t3*t36; +t91 = t25*t68; +t76 = R_VEL+t43+t49+t55+t62+t75-t80-t91; +t77 = 1.0/t76; +A0[0][0] = t77*(t29-P[0][4]*t3+P[0][5]*t8+P[0][6]*t12+P[0][1]*t18+P[0][2]*t22-P[0][3]*t25); +A0[1][0] = t77*(t30-P[1][4]*t3+P[1][5]*t8+P[1][0]*t15+P[1][6]*t12+P[1][2]*t22-P[1][3]*t25); +A0[2][0] = t77*(t60-P[2][4]*t3+P[2][5]*t8+P[2][0]*t15+P[2][6]*t12+P[2][1]*t18-P[2][3]*t25); +A0[3][0] = t77*(-t90-P[3][4]*t3+P[3][5]*t8+P[3][0]*t15+P[3][6]*t12+P[3][1]*t18+P[3][2]*t22); +A0[4][0] = t77*(-t78+P[4][5]*t8+P[4][0]*t15+P[4][6]*t12+P[4][1]*t18+P[4][2]*t22-P[4][3]*t25); +A0[5][0] = t77*(t69-P[5][4]*t3+P[5][0]*t15+P[5][6]*t12+P[5][1]*t18+P[5][2]*t22-P[5][3]*t25); +A0[6][0] = t77*(t38-P[6][4]*t3+P[6][5]*t8+P[6][0]*t15+P[6][1]*t18+P[6][2]*t22-P[6][3]*t25); +A0[7][0] = t77*(-P[7][4]*t3+P[7][5]*t8+P[7][0]*t15+P[7][6]*t12+P[7][1]*t18+P[7][2]*t22-P[7][3]*t25); +A0[8][0] = t77*(-P[8][4]*t3+P[8][5]*t8+P[8][0]*t15+P[8][6]*t12+P[8][1]*t18+P[8][2]*t22-P[8][3]*t25); +A0[9][0] = t77*(-P[9][4]*t3+P[9][5]*t8+P[9][0]*t15+P[9][6]*t12+P[9][1]*t18+P[9][2]*t22-P[9][3]*t25); +A0[10][0] = t77*(-P[10][4]*t3+P[10][5]*t8+P[10][0]*t15+P[10][6]*t12+P[10][1]*t18+P[10][2]*t22-P[10][3]*t25); +A0[11][0] = t77*(-P[11][4]*t3+P[11][5]*t8+P[11][0]*t15+P[11][6]*t12+P[11][1]*t18+P[11][2]*t22-P[11][3]*t25); +A0[12][0] = t77*(-P[12][4]*t3+P[12][5]*t8+P[12][0]*t15+P[12][6]*t12+P[12][1]*t18+P[12][2]*t22-P[12][3]*t25); +A0[13][0] = t77*(-P[13][4]*t3+P[13][5]*t8+P[13][0]*t15+P[13][6]*t12+P[13][1]*t18+P[13][2]*t22-P[13][3]*t25); +A0[14][0] = t77*(-P[14][4]*t3+P[14][5]*t8+P[14][0]*t15+P[14][6]*t12+P[14][1]*t18+P[14][2]*t22-P[14][3]*t25); +A0[15][0] = t77*(-P[15][4]*t3+P[15][5]*t8+P[15][0]*t15+P[15][6]*t12+P[15][1]*t18+P[15][2]*t22-P[15][3]*t25); +A0[16][0] = t77*(-P[16][4]*t3+P[16][5]*t8+P[16][0]*t15+P[16][6]*t12+P[16][1]*t18+P[16][2]*t22-P[16][3]*t25); +A0[17][0] = t77*(-P[17][4]*t3+P[17][5]*t8+P[17][0]*t15+P[17][6]*t12+P[17][1]*t18+P[17][2]*t22-P[17][3]*t25); +A0[18][0] = t77*(-P[18][4]*t3+P[18][5]*t8+P[18][0]*t15+P[18][6]*t12+P[18][1]*t18+P[18][2]*t22-P[18][3]*t25); +A0[19][0] = t77*(-P[19][4]*t3+P[19][5]*t8+P[19][0]*t15+P[19][6]*t12+P[19][1]*t18+P[19][2]*t22-P[19][3]*t25); +A0[20][0] = t77*(-P[20][4]*t3+P[20][5]*t8+P[20][0]*t15+P[20][6]*t12+P[20][1]*t18+P[20][2]*t22-P[20][3]*t25); +A0[21][0] = t77*(-P[21][4]*t3+P[21][5]*t8+P[21][0]*t15+P[21][6]*t12+P[21][1]*t18+P[21][2]*t22-P[21][3]*t25); +A0[22][0] = t77*(-P[22][4]*t3+P[22][5]*t8+P[22][0]*t15+P[22][6]*t12+P[22][1]*t18+P[22][2]*t22-P[22][3]*t25); +A0[23][0] = t77*(-P[23][4]*t3+P[23][5]*t8+P[23][0]*t15+P[23][6]*t12+P[23][1]*t18+P[23][2]*t22-P[23][3]*t25); diff --git a/matlab/scripts/Inertial Nav EKF/K_VELZ.c b/matlab/scripts/Inertial Nav EKF/K_VELZ.c new file mode 100644 index 0000000000..31fbad5998 --- /dev/null +++ b/matlab/scripts/Inertial Nav EKF/K_VELZ.c @@ -0,0 +1,116 @@ +t2 = q0*q2*2.0; +t3 = q1*q3*2.0; +t4 = t2+t3; +t5 = q0*q0; +t6 = q1*q1; +t7 = q2*q2; +t8 = q3*q3; +t9 = t5-t6-t7+t8; +t10 = q0*q1*2.0; +t25 = q2*q3*2.0; +t11 = t10-t25; +t12 = q0*vd*2.0; +t13 = q2*vn*2.0; +t26 = q1*ve*2.0; +t14 = t12+t13-t26; +t15 = q1*vd*2.0; +t16 = q0*ve*2.0; +t27 = q3*vn*2.0; +t17 = t15+t16-t27; +t18 = q3*ve*2.0; +t19 = q0*vn*2.0; +t28 = q2*vd*2.0; +t20 = t18+t19-t28; +t21 = q3*vd*2.0; +t22 = q2*ve*2.0; +t23 = q1*vn*2.0; +t24 = t21+t22+t23; +t29 = P[0][0]*t14; +t30 = P[6][4]*t9; +t31 = P[4][4]*t4; +t32 = P[0][4]*t14; +t33 = P[2][4]*t20; +t34 = P[3][4]*t24; +t78 = P[5][4]*t11; +t79 = P[1][4]*t17; +t35 = t30+t31+t32+t33+t34-t78-t79; +t36 = t4*t35; +t37 = P[6][5]*t9; +t38 = P[4][5]*t4; +t39 = P[0][5]*t14; +t40 = P[2][5]*t20; +t41 = P[3][5]*t24; +t80 = P[5][5]*t11; +t81 = P[1][5]*t17; +t42 = t37+t38+t39+t40+t41-t80-t81; +t43 = P[6][0]*t9; +t44 = P[4][0]*t4; +t45 = P[2][0]*t20; +t46 = P[3][0]*t24; +t83 = P[5][0]*t11; +t84 = P[1][0]*t17; +t47 = t29+t43+t44+t45+t46-t83-t84; +t48 = t14*t47; +t49 = P[6][1]*t9; +t50 = P[4][1]*t4; +t51 = P[0][1]*t14; +t52 = P[2][1]*t20; +t53 = P[3][1]*t24; +t85 = P[5][1]*t11; +t86 = P[1][1]*t17; +t54 = t49+t50+t51+t52+t53-t85-t86; +t55 = P[6][2]*t9; +t56 = P[4][2]*t4; +t57 = P[0][2]*t14; +t58 = P[2][2]*t20; +t59 = P[3][2]*t24; +t88 = P[5][2]*t11; +t89 = P[1][2]*t17; +t60 = t55+t56+t57+t58+t59-t88-t89; +t61 = t20*t60; +t62 = P[6][3]*t9; +t63 = P[4][3]*t4; +t64 = P[0][3]*t14; +t65 = P[2][3]*t20; +t66 = P[3][3]*t24; +t90 = P[5][3]*t11; +t91 = P[1][3]*t17; +t67 = t62+t63+t64+t65+t66-t90-t91; +t68 = t24*t67; +t69 = P[6][6]*t9; +t70 = P[4][6]*t4; +t71 = P[0][6]*t14; +t72 = P[2][6]*t20; +t73 = P[3][6]*t24; +t92 = P[5][6]*t11; +t93 = P[1][6]*t17; +t74 = t69+t70+t71+t72+t73-t92-t93; +t75 = t9*t74; +t82 = t11*t42; +t87 = t17*t54; +t76 = R_VEL+t36+t48+t61+t68+t75-t82-t87; +t77 = 1.0/t76; +A0[0][0] = t77*(t29+P[0][4]*t4+P[0][6]*t9-P[0][5]*t11-P[0][1]*t17+P[0][2]*t20+P[0][3]*t24); +A0[1][0] = t77*(P[1][4]*t4+P[1][0]*t14+P[1][6]*t9-P[1][5]*t11-P[1][1]*t17+P[1][2]*t20+P[1][3]*t24); +A0[2][0] = t77*(t58+P[2][4]*t4+P[2][0]*t14+P[2][6]*t9-P[2][5]*t11-P[2][1]*t17+P[2][3]*t24); +A0[3][0] = t77*(t66+P[3][4]*t4+P[3][0]*t14+P[3][6]*t9-P[3][5]*t11-P[3][1]*t17+P[3][2]*t20); +A0[4][0] = t77*(t31+P[4][0]*t14+P[4][6]*t9-P[4][5]*t11-P[4][1]*t17+P[4][2]*t20+P[4][3]*t24); +A0[5][0] = t77*(-t80+P[5][4]*t4+P[5][0]*t14+P[5][6]*t9-P[5][1]*t17+P[5][2]*t20+P[5][3]*t24); +A0[6][0] = t77*(t69+P[6][4]*t4+P[6][0]*t14-P[6][5]*t11-P[6][1]*t17+P[6][2]*t20+P[6][3]*t24); +A0[7][0] = t77*(P[7][4]*t4+P[7][0]*t14+P[7][6]*t9-P[7][5]*t11-P[7][1]*t17+P[7][2]*t20+P[7][3]*t24); +A0[8][0] = t77*(P[8][4]*t4+P[8][0]*t14+P[8][6]*t9-P[8][5]*t11-P[8][1]*t17+P[8][2]*t20+P[8][3]*t24); +A0[9][0] = t77*(P[9][4]*t4+P[9][0]*t14+P[9][6]*t9-P[9][5]*t11-P[9][1]*t17+P[9][2]*t20+P[9][3]*t24); +A0[10][0] = t77*(P[10][4]*t4+P[10][0]*t14+P[10][6]*t9-P[10][5]*t11-P[10][1]*t17+P[10][2]*t20+P[10][3]*t24); +A0[11][0] = t77*(P[11][4]*t4+P[11][0]*t14+P[11][6]*t9-P[11][5]*t11-P[11][1]*t17+P[11][2]*t20+P[11][3]*t24); +A0[12][0] = t77*(P[12][4]*t4+P[12][0]*t14+P[12][6]*t9-P[12][5]*t11-P[12][1]*t17+P[12][2]*t20+P[12][3]*t24); +A0[13][0] = t77*(P[13][4]*t4+P[13][0]*t14+P[13][6]*t9-P[13][5]*t11-P[13][1]*t17+P[13][2]*t20+P[13][3]*t24); +A0[14][0] = t77*(P[14][4]*t4+P[14][0]*t14+P[14][6]*t9-P[14][5]*t11-P[14][1]*t17+P[14][2]*t20+P[14][3]*t24); +A0[15][0] = t77*(P[15][4]*t4+P[15][0]*t14+P[15][6]*t9-P[15][5]*t11-P[15][1]*t17+P[15][2]*t20+P[15][3]*t24); +A0[16][0] = t77*(P[16][4]*t4+P[16][0]*t14+P[16][6]*t9-P[16][5]*t11-P[16][1]*t17+P[16][2]*t20+P[16][3]*t24); +A0[17][0] = t77*(P[17][4]*t4+P[17][0]*t14+P[17][6]*t9-P[17][5]*t11-P[17][1]*t17+P[17][2]*t20+P[17][3]*t24); +A0[18][0] = t77*(P[18][4]*t4+P[18][0]*t14+P[18][6]*t9-P[18][5]*t11-P[18][1]*t17+P[18][2]*t20+P[18][3]*t24); +A0[19][0] = t77*(P[19][4]*t4+P[19][0]*t14+P[19][6]*t9-P[19][5]*t11-P[19][1]*t17+P[19][2]*t20+P[19][3]*t24); +A0[20][0] = t77*(P[20][4]*t4+P[20][0]*t14+P[20][6]*t9-P[20][5]*t11-P[20][1]*t17+P[20][2]*t20+P[20][3]*t24); +A0[21][0] = t77*(P[21][4]*t4+P[21][0]*t14+P[21][6]*t9-P[21][5]*t11-P[21][1]*t17+P[21][2]*t20+P[21][3]*t24); +A0[22][0] = t77*(P[22][4]*t4+P[22][0]*t14+P[22][6]*t9-P[22][5]*t11-P[22][1]*t17+P[22][2]*t20+P[22][3]*t24); +A0[23][0] = t77*(P[23][4]*t4+P[23][0]*t14+P[23][6]*t9-P[23][5]*t11-P[23][1]*t17+P[23][2]*t20+P[23][3]*t24);