Ask Your Question

communication node with c-Funktion as executable in catkin

asked 2015-01-14 04:07:08 -0500

JanOr gravatar image

updated 2015-01-15 06:08:49 -0500

Hey there,

The task:

I want to create a control for robots via ROS: I receive data via a callback function (Subscriber) and send directly the calculated outputs in this function (Publisher). The calculation of the control parameters also needs some additional functions, which are given via other c files. All this code is given in c.

The Structure


 1. CMakeLists.txt 

 2. package.xml 

 3. include/ (Contains all c++ headerfiles):
    - euler1.h 
    - eulermod2.h 
    - grampc_init.h
    - grampc_mess.h
    - grampc_run.h
    - grampc_setopt.h 
    - grampc_setparam.h
    - heun2.h
    - probfct.h 
    - ruku45.h

 4.  src/ (Contains all c++ sourcefiles):
    - grampc.cpp #<<-- This is the file with the callback function and therefor the node
    - euler1.c 
    - eulermod2.c 
    - grampc_init.c
    - grampc_mess.c 
    - grampc_run.c
    - grampc_setopt.c 
    - grampc_setparam.c
    - heun2.c 
    - probfct.c 
    - ruku45.c

 5.  srv/ (Contains all servicefiles)
    - grampc_IO.srv

The concept:

So the concept is to build one executable (grampc_node with grampc.cpp) which can use functions of other files (euler1.c, euler1.h ....) and that can communicate via a service (grampc_IO).

**The Package:**

cmake_minimum_required(VERSION 2.8)

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation rosbag)

add_service_files(FILES grampc_IO.srv)

generate_messages(DEPENDENCIES std_msgs)

catkin_package(      CATKIN_DEPENDS roscpp rospy std_msgs rosbag    )

include_directories(include     /include )

#define sources

#define a grampc_node target
add_executable(grampc_node src/grampc.cpp ${grampc_SRCS})

#now link our node to the library, and all the libraries from the other pkgs
target_link_libraries(grampc_node ${catkin_LIBRARIES})

add_dependencies(grampc_node grampc_gencpp)



  <!-- Package Metadata -->
  <!-- Required by Catkin -->

  <!-- at build time you need message_generation -->
  <!-- at run time you need message_runtime -->

  <!-- Add services -->
 add_service_files(FILES grampc_IO.srv )


Problem: The required source files (which are located in grampc/src) or headerfiles (which are located in grampc/include) are not getting linked or better: I get undefined references. I don't know how to proceed. It would be amazing if you would have any ideas about that.

With the catkin_make grampc to just make the Package:

user:~/Workspace/catkin$ catkin_make grampc
Base path: /home/user/Workspace/catkin
    Source space: /home/user/Workspace/catkin/src
    Build space: /home/user/Workspace/catkin/build
    Devel space: /home/user/Workspace/catkin/devel
    Install space: /home/user/Workspace/catkin/install
    #### Running command: "make cmake_check_build_system" in "/home/user/Workspace/catkin/build"

#### Running command: "make grampc -j4 -l4" in "/home/user/Workspace/catkin/build"

with the catkin_make command for the whole workspace:

/home/user/Workspace/catkin/src/grampc/src/grampc.cpp:133:44: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   grampc_setparam_vector(mpc_ws,"xdes ...
edit retag flag offensive close merge delete


Did you try naming your header files *.h instead of *.c?

BennyRe gravatar image BennyRe  ( 2015-01-14 06:02:09 -0500 )edit

Are your header files really named ".c" rather than ".h" or ".hpp" or is that an error in your description?

Wolf gravatar image Wolf  ( 2015-01-14 06:11:44 -0500 )edit

Sorry my mistake. They have the ending *.h. I changed it above.

JanOr gravatar image JanOr  ( 2015-01-14 07:40:23 -0500 )edit

In principle that should work as you did... Maybe check the code of your files again? Are the functions really defined somewhere in the named src files with exactly the same signature? It appears that all missing refs have a typeGRAMPC pointer? Maybe there are ambiguous declarations of this type??

Wolf gravatar image Wolf  ( 2015-01-15 00:59:42 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2015-01-15 08:11:29 -0500

JanOr gravatar image

The Problem was solved. The external functions are c-Code. So you have to refer to them with extern "C"

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2015-01-14 04:07:08 -0500

Seen: 181 times

Last updated: Jan 15 '15