ZilantRobotics/innopolis_vtol_dynamics

Setting CMAKE_BUILD_TYPE as Debug causes exiting the program after arming the vehicle in SITL mode

prihex opened this issue · 3 comments

CMAKE_BUILD_TYPE is currently set as RelWithDebInfo in inno_vtol_dynamics project.

CMakeLists.txt:9
SET(CMAKE_BUILD_TYPE RelWithDebInfo)

If I set it to Debug and arm the vehicle. Program exits.

[ INFO] [1646913596.306345559]: inno_vtol:  mc  [0.00, 0.00, 0.00, 0.00]  fw rpy  [0.00, 0.00, 0.00] throttle  [0.00],  enu pose  [0.0, 0.0, 0.0]
[ INFO] [1646913596.872489711]: cmd: Arm
node: /usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:364: Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::Index, Eigen::Index) [with Derived = Eigen::Matrix<double, -1, -1>; Eigen::DenseCoeffsBase<Derived, 1>::Scalar = double; Eigen::Index = long int]: Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.
================================================================================REQUIRED process [inno_dynamics_sim-4] has died!
process has died [pid 294660, exit code -6, cmd /home/prihex/catkin_ws/devel/lib/innopolis_vtol_dynamics/node __name:=inno_dynamics_sim __log:=/home/prihex/.ros/log/90dcdc54-a069-11ec-9b20-d93dcf7f6b57/inno_dynamics_sim-4.log].
log file: /home/prihex/.ros/log/90dcdc54-a069-11ec-9b20-d93dcf7f6b57/inno_dynamics_sim-4*.log
Initiating shutdown!
================================================================================
[rosapi-9] killing on exit
[rosbridge_websocket-8] killing on exit
[static_transform_publisher_camera-7] killing on exit
[static_transform_publisher1-6] killing on exit

in /uav_dynamics/inno_vtol_dynamics/src/dynamics/vtolDynamicsSim.cpp:701

void InnoVtolDynamicsSim::calculatePolynomialUsingTable(const Eigen::MatrixXd& table,
                                                        double airSpeedMod,
                                                        Eigen::VectorXd& polynomialCoeffs) const{
    size_t prevRowIdx = findRow(table, airSpeedMod);
    if(prevRowIdx + 2 <= table.rows()){
        size_t nextRowIdx = prevRowIdx + 1;
        Eigen::MatrixXd prevRow = table.row(prevRowIdx);
        Eigen::MatrixXd nextRow = table.row(nextRowIdx);
        double t = (airSpeedMod - prevRow(0, 0)) / (nextRow(0, 0) - prevRow(0, 0));
        for(size_t idx = 0; idx < 7; idx++){
            polynomialCoeffs[idx] = lerp(prevRow(0, idx + 1), nextRow(0, idx + 1), t); // This line
        }
    }else{
        for(size_t idx = 0; idx < 7; idx++){
            polynomialCoeffs[idx] = 0;
        }
    }
}

nextRow(0, idx + 1) couldn't be calculated because in function

    EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
    {
      eigen_internal_assert(row >= 0 && row < rows()
                         && col >= 0 && col < cols()); // This assertion fails
      return internal::evaluator<Derived>(derived()).coeffRef(row,col);
    }

Both col and cols() returns** 6 when armed in debug mode. Release and RelWithDebInfo doesn't evaluate assertions. Thus they never crash.

#define EIGEN_NO_DEBUG

before

#include "vtolDynamicsSim.hpp"

in vtolDynamicsSim.cpp

solved the problem

@hdbalyozsht Hi. Thanks for the issue. I tried it with DEBUG build type and I got the same error.
I modified tests a little bit and reproduce the problem in test workflow.
Then I fixed it in the next commit, so now it should be ok.

#define EIGEN_NO_DEBUG is not the solution. The actual problem was related to the fact that CDPolynomial matrix has the size (8, 6) less than other similar matrices (8, 8). calculatePolynomialUsingTable was hardcoded to handle only the (8, 8) size case. Now it is more robust.

I made fixes here: #12