Skip to content

Commit

Permalink
implement matrix mods in main
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamSmego committed Mar 13, 2021
1 parent 803859e commit 6391f51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ void setup()

// set up controller
// TODO : move stuff below
float * initialize={0, 0, 0, 0, 0, 0};
ws.x=Matrix(6, 1, initialize);
ws.y=Matrix(4, 1, initialize);
ws.u=Matrix(2, 1, initialize);
float * initialize_6={0, 0, 0, 0, 0, 0};
float * initialize_4={0, 0, 0, 0};
float * initialize_2={0, 0};
ws.x=Matrix(6, 1, initialize_6);
ws.y=Matrix(4, 1, initialize_4);
ws.u=Matrix(2, 1, initialize_2);

ws.uLast[0] = 0; //last commanded tvc x input
ws.uLast[1] = 0; //last commanded tvc y input
Expand Down Expand Up @@ -273,9 +275,9 @@ void loop()
//if so, then updates the control constant by multiplying by the current thrust
//construct x
//construct y
ws.u=sMult(mMult(), -1); //calculate input
ws.u=(K*ws.x).scale(-1); //calculate input
ws.x=mAdd(ws.x, sMult(mAdd(mAdd(), ), ws.dt));
ws.x+=ws.dt*(ws.A*ws.x+ws.B*ws.u+ws.L*(ws.y-ws.C*ws.x)); //calculate next state
ws.x=ws.x+((A*ws.x)+(B*ws.u)+(L*(ws.y-(C*ws.x)))).scale(ws.dt); //calculate next state
//process u
//send u to tvc
}
Expand Down
2 changes: 1 addition & 1 deletion main/matrix.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Matrix
}
Matrix operator+(Matrix);
Matrix operator-(Matrix);
Matrix scale (float k);
Matrix scale (float);
Matrix operator*(Matrix);
};

Expand Down
8 changes: 4 additions & 4 deletions main/mission_constants.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ Matrix B=Matrix(6, 2, B_VALUES);
0,0,0,0,0,0}; //controller gain
Matrix K=Matrix(2, 6, K_VALUES);

float C_VALUES [24] = {0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0}; //sensor matrix
float C_VALUES [24] = {1,0,0,0,0,0,
0,0,1,0,0,0,
0,0,0,1,0,0,
0,0,0,0,0,1}; //sensor matrix
Matrix C=Matrix(4, 6, C_VALUES);

float L_VALUES [24] = {0, 0, 0, 0,
Expand Down

0 comments on commit 6391f51

Please sign in to comment.