Registered Member
|
I have coded a model predictive controller on a pixhawk hardware to control the attitude (angles) of the quadcopter. I exchanged messages with one of the developers of pixhawk and he advised me to use single precision. My code is in double precision.
Before this, I tested a numerical problem with MatrixXd (double precision) using Eigen C++ Library and my code was able to get the same answer. I used the `ldlt()` Cholesky solver for a dense linear systems (all the other solver methods resulted in the wrong answer). I replaced all MatrixXd with MatrixXf and double with float in order to solve the problem with single precision but I was unable to get the same answer. So I want to get some insight as to why I am not getting the same answer achieved by MatrixXd when I use MatrixXf. Below is the relevant section. The y variable at the end produces the -nan(ind); -nan(ind) as it's solution when I declare my variables and matrices with MatrixXf but when I use MatrixXd I get the desired solution of 1; 0.9999.
Below is the QPhild function:
I know that the main problem is from the function above because I put various cout lines to check outputs of various matrices within it. They start off at 0 then go to inf then to nan. I know that the post should be MCV but I have close to 600 lines of code and posting all that is obviously not an option. These are the crucial parts of the code, I do hope it helps some how. Because it is missing other function definitions and variable initialization which will make the post less MCV. Please let me know if this makes more sense now or if you need more clarity from my end. Thank you |
Moderator
|
Hard to help without knowing the contents of the matrix E. If only LDLT is giving you a satisfactory result when using double, then this means there is something fishy about it. Since it seems to be small you could past it's content here (with full accuracy, both using double and float), and also print its singular-values: cout << E.jacobiSvd().singularValues().transpose() << endl;, again both in double and single precision.
|
Moderator
|
btw, better factorize the matrix E only once:
you can then replace LDLT by other solvers, like PartialPivLU, HouseholderQR, JacobiSVD, etc. |
Moderator
|
Let's continue there: https://stackoverflow.com/questions/45896354
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]