ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
0

QR Module of Eigen library is not found, where do I need to alter the Cmake.txt

asked 2018-05-12 13:49:55 -0500

mojakobi gravatar image

updated 2018-05-14 05:58:17 -0500

Hy everybody,

I am currently writing a function for a ros node. During this calculation I am trying to use the pseudo inverse of the QR Module of Eigen. But unfortunately it is not able to find the include and by that not the function. I think I need to alter my Cmake file. I did already use normal <eigen eigen=""> functions so this is not the problem.

I found a stack overflow post in which it seems very easy to use the function. Just for clarity I add the link here: stack overflow post

Thank you very much for your help. Since I am not posting very often just tell me when I need to change anything. I will add all the information as soon as possible.

The code I am trying to make run:

#include <cv_bridge/cv_bridge.h>
#include "ros/ros.h"
#include <opencv2/highgui/highgui.hpp>
#include <algorithm>  
#include <stdio.h>
#include <Eigen/Eigen>
#include <Eigen/QR> //<- can't find this import

void calc_delta_p(Eigen::Matrix <double,1,6> &delta_p,Eigen::Matrix <double,6,6> &hessian){

hessian.completeOrthogonalDecomposition().pseudoInverse(); //<-cant find this function
delta_p=hessian*delta_p;

}

The compiler throws this error:

/home/catkin_ws/src/image_publisher/src/function_file.cpp:120:13: error: ‘class Eigen::Matrix<double, 6, 6, 0, 6, 6>’ has no member named ‘completeOrthogonalDecomposition’
     hessian.completeOrthogonalDecomposition().pseudoInverse();

Here is my cmake file:

cmake_minimum_required(VERSION 2.8.3)
project(image_publisher)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

 ## Find catkin macros and libraries
 ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
 ## is used, also find other catkin packages
 find_package(catkin REQUIRED COMPONENTS
      cv_bridge
      #opencv2
      roscpp
      sensor_msgs
      std_msgs
      cmake_modules #eigen
      dynamic_reconfigure
       message_generation
       )

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


 ## Generate messages in the 'msg' folder
 add_message_files(
   FILES
   sixDOF.msg
 )


## Generate added messages and services with any dependencies listed here
 generate_messages(
   DEPENDENCIES
   sensor_msgs
   std_msgs
 )


## Generate dynamic reconfigure parameters in the 'cfg' folder
  generate_dynamic_reconfigure_options(
  cfg/dynamic_reconfigure_file.cfg
 )

###################################
## catkin specific configuration ##

###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need catkin_package(   INCLUDE_DIRS include
#  LIBRARIES image_publisher   CATKIN_DEPENDS cv_bridge roscpp sensor_msgs std_msgs dynamic_reconfigure message_runtime
#opencv2
#  DEPENDS system_lib   DEPENDS Eigen #Eigen library )

###########
## Build ##
###########

find_package(OpenCV) find_package(Eigen REQUIRED)
#eigenlibrary


set( PROPRIETARY_FUNCTIONS_H include/image_publisher/function_file.h )

set( PROPRIETARY_FUNCTIONS_CPP src/function_file.cpp )
## Specify additional locations of header files
## Your package locations should be listed before other locations include_directories(   include   ${catkin_INCLUDE_DIRS}   ${OpenCV_INCLUDE_DIRS}   ${Eigen_INCLUDE_DIRS}
#  ${PROPRIETARY_FUNCTIONS_CPP}
#  ${PROPRIETARY_FUNCTIONS_H} )

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/image_publisher.cpp
# )


#always before add dependencies
## Declare a C++ executable 
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide  add_executable(image_publisher_node src/image_publisher_node.cpp ${PROPRIETARY_FUNCTIONS_CPP} ${PROPRIETARY_FUNCTIONS_H} )  add_executable(image_subscriber_node src/image_subscriber_node ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2018-05-12 14:51:01 -0500

I can see where your problem is here.

But one quick point first the #include <Eigen/QR> is working fine, the compiler wouldn't even try to build your code if it couldn't find this include. So that bit's okay.

The problem is that completeOrthogonalDecomposition is a class in its own right not an extra method of the matrix type in Eigen as you're trying to call it.

You need to create an instance of the completeOrthogonalDecomposition class templated with the type of matrix you're using then use that class to do the decomposition. Your code should look something like this :

Eigen::CompleteOrthogonalDecomposition<Eigen::MatrixXd> cqr(A);
pinv = cqr.pseudoInverse();

Hope this helps.

edit flag offensive delete link more

Comments

Thank you very much for your comment. You are right it found the include. I just checked my Eigen library version number and found out that I was using the wrong version number. It seems that Eigen::CompleteOrthogonalDecomposition< _MatrixType > was added in version 3.

mojakobi gravatar imagemojakobi ( 2018-05-13 02:36:57 -0500 )edit
0

answered 2018-05-14 05:51:35 -0500

mojakobi gravatar image

updated 2018-05-14 09:49:46 -0500

Because in Eigen 2 there is no Pseudo inverse function I helped myself by writing my own code.following advice from post number 18 from this blog entry. I am using the JacobiSVD objetct's solve method called with an identity matrix. It returns the pinv my matlab also gives back.

    #include <Eigen/Eigen>
    #include <Eigen/SVD>
    #include <stdio.h>

  void pinv( Eigen::MatrixXd &input_matrix,Eigen::MatrixXd &output_matrix) {
// fills the output matrix with a identity matrix for later use in the solvemethod
    output_matrix=Eigen::MatrixXd::Identity(input_matrix.rows(),input_matrix.cols());
    Eigen::JacobiSVD<Eigen::MatrixXd> svd(input_matrix, Eigen::ComputeThinU | Eigen::ComputeThinV);
    output_matrix=svd.solve(output_matrix); }

A function call looks like this:

        int main(int argc, char **argv)
        {
        Eigen::MatrixXd example_matrix(6,6);
        Eigen::MatrixXd output_matrix(6,6);
        example_matrix <<        1,2,3,4,5,6,
                                 1,2,3,4,5,6,
                                 1,2,3,4,5,6,
                                 1,2,3,4,5,6,
                                 1,2,3,4,5,6,
                                 1,2,3,4,5,6;
        pinv(example_matrix,output_matrix);  //calculates the pseudo inverse
        std::cout << "pinv example matrix: " << output_matrix << std::cout; //output of the matrix

        return 0;
        }
edit flag offensive delete link more

Comments

Why not just find_package(Eigen 3 REQUIRED) (or any of the equivalent forms)?

Eigen 3 must be available on all platforms that ROS Kinetic is distributed.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-14 05:53:02 -0500 )edit
1

It's not a pseudo inverse if it's a square matrix. The whole point of the pseudo inverse operation is that it can work with non-square matrices! See.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-05-14 06:00:22 -0500 )edit

True that :). But this also works for 6 times 6 matrizes with rank deficiencies. My input Matrix is just always square. I do not check if it has full rank.

mojakobi gravatar imagemojakobi ( 2018-05-14 08:09:32 -0500 )edit

The find_package would also be a good suggestion I will check if that works. I was myself unaware that I used Eigen2. I hope that I can force Eigen 3 with that command

mojakobi gravatar imagemojakobi ( 2018-05-14 08:12:28 -0500 )edit

shoot. code does really not work on rank deficient matrixes. Thank you for pointing that out

mojakobi gravatar imagemojakobi ( 2018-05-14 08:17:35 -0500 )edit

corrected that error should now return the result it should

mojakobi gravatar imagemojakobi ( 2018-05-14 09:47:56 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-05-12 13:49:55 -0500

Seen: 265 times

Last updated: May 14 '18