I’m trying to implement a lqr controller.
As the system matrix varies over time, I have to calculate lqr gain after solving a continuous time algebraic riccati equation every timestep.
To do this, I need Eigen especially for Eigen::FullPivLU.
But when I build the PX4 Autopilot code with “make px4_fmu-v2_default”, I get below error
/usr/include/eigen3/Eigen/Core:96:10: fatal error: complex: No such file or directory
I heard that I can’t use standard cpp library for nuttx which seems to be the cause of the problem.
Is there any way to use Eigen in PX4 Autopilot?
Extract the directory ‘Eigen’ from the zip file and place it in ‘src/lib’ directory of PX4 firmware. This is the section where other math libraries like ‘mathlib’, ‘matrix’, etc are present.
Generally we need to update the CMakeFiles (of ‘src/lib’) whenever we add new directory, but it was not required for ‘Eigen’ (I’m not clear why).
We have to include the Eigen directory in the CMakeFiles to access its functionalities. For my case, I added the following command in ‘src/modules/vtol_att_control/CMakeLists.txt’ file present in ‘vtol_att_control’ :
# Add Eigen include directory
include_directories(${CMAKE_SOURCE_DIR}/src/lib/Eigen
I think this command can be added in the main CMake file instead, PX4-Autopilot_CMakeLists.txt to enable gloabl access to the Eigen library. Let me know if you try this way.
This should solve the eigen library addition problem in control module.
You may get some errors while using Eigen library because px4 considers few warnings as errors. In my case, comparing float variables with equality sign was causing the problem. error: comparing floating point with == or != is unsafe [-Werror=float-equal]
Either you have to change the equality condition with a >= tol everywhere in Eigen library (which is tedious). Instead I just commented the warning in the file ‘cmake/px4_add_common_flags.cmake’