0
$\begingroup$

Rosanswers logo

I am attempting to use some of the definitions and functions found in the IKFast plugin package (more on this below) but am running into trouble adding the necessary dependencies in my CMakeLists.txt

The file structure of the files relevant to me look like this:

myrobot_ikfast_plugin/
    include/
        ikfast.h
    src/
        myrobot_group_ikfast_solver.cpp
    CMakeLists.txt
    package.xml
my_package/
    src/
        my_iksolver.cpp
    CMakeLists.txt
    package.xml

Within my_iksolver.cpp I require the use of

  • IkSolutionList
  • IkSolutionBase
  • IkReal
  • ComputeIk()

The above definitions and functions come from both ikfast.h and myrobot_group_ikfast_solver.cpp, so I suppose I only really need to include the cpp file as it already has a #include ikfast.h. Where I'm stuck is editing the CMakeLists.txts to include the few things I need from IKFast.

As noted here by, my lord and savior, gvdhoorn https://answers.ros.org/question/217214/catkin-tools-how-to-include-source-file-from-another-package/, the "elegant" way to do this is to consider using libraries so naturally I tried the following:

Added to myrobot_ikfast_plugin/CMakeLists.txt:

add_library(ik_solver src/kuka_arm_ikfast_solver.cpp)
target_link_libraries(ik_solver ${catkin_LIBRARIES})

And added the ik_solver to the install:

install(TARGETS ${IKFAST_LIBRARY_NAME} ik_solver LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

Then I added to my_package/CMakeLists.txt:

  • kuka_ikfast_plugin to find_package()
  • add_executable(my_iksolver src/my_iksolver.cpp)
  • target_link_libraries(my_iksolver ik_solver) (see above created library)

But when attempting to #include <kuka_arm_ikfast_solver.cpp> I get a build error "No such file or directory`.

So the questions that I would like to be answered are summarized as follows:

  1. How should I edit IKFast's CMakeLists.txt so that I can use components of both the cpp and header files.
  2. How should I edit my_package CMakeLists.txt and my_package/package.xml to use those components.
  3. How should I #include the cpp file (marked as a library) to be used by my_package/src/my_iksolver.cpp.

Thanks for the help ahead of time!


Originally posted by maxgitt on ROS Answers with karma: 18 on 2018-05-02

Post score: 0


Original comments

Comment by gvdhoorn on 2018-05-03:\

I suppose I only really need to include the cpp file as it already has a #include ikfast.h

I would not recommend including a cpp file. I know the (MoveIt) IKFast plugin infrastructure does that, but it's not really nice.

Treat the IKFast lib as library, include the ikfast.h and ..

Comment by gvdhoorn on 2018-05-03:
.. it should work.

Comment by maxgitt on 2018-05-03:
so I removed everything from both CMakeLists.txts except for find_package(myrobot_ikfast_plugin), I can't seem to #include ikfash.h, maybe I'm missing something. what commands do I have to give in both CMakeLists to "treat IKfast lib as library"?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Solved, the docs for catkin helped me do this properly. First in the CMakeLists.txt catkin_package

catkin_package(
  # Other pkgs can use ikfast.h
  INCLUDE_DIRS
    include
)

Now other packages can use ikfast.h but a good number of definitions and functions have been excluded by #ifdef. So you must

#define IKFAST_HAS_LIBRARY

in ikfast.h. And then a a link to the definition of computerIK() must be created to <myrobot>_<group>_ikfast_solver.cpp by making the additional changes to the CMakeLists.txt

catkin_package(
  # Other pkgs can use ikfast.h
  INCLUDE_DIRS
    include
  LIBRARIES
    ik_solver_lib
)

add_library(ik_solver_lib src/kuka_arm_ikfast_solver.cpp)
target_link_libraries(ik_solver_lib ${catkin_LIBRARIES})

# And include in installs
install(TARGETS ${IKFAST_LIBRARY_NAME} ik_solver_lib LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

Now all that's needed is to add to the package that you would like to use IKFast's functionality by adding

find_package(catkin REQUIRED COMPONENTS 
    ...
    kuka_ikfast_plugin
)

Simply #include <ikfast.h> in any cpp in your package.


Originally posted by maxgitt with karma: 18 on 2018-05-03

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.