ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

catkin/src/grampc/

 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:**
CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(grampc)

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
set(grampc_SRCS
  src/euler1.c
  src/eulermod2.c
  src/heun2.c
  src/probfct.c
  src/ruku45.c
  src/grampc_run.c
  src/grampc_mess.c
  src/grampc_setopt.c
  src/grampc_setparam.c
  src/grampc_init.c
)

#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)

install(TARGETS grampc_node RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

package.xml:

<package>
  <!-- Package Metadata -->
  <name>grampc</name>
  <version>1.2.4</version>
  <license>BSD</license>
  <!-- Required by Catkin -->
  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>std_msgs</build_depend>
  <run_depend>std_msgs</run_depend>
  <build_depend>rospy</build_depend>
  <run_depend>rospy</run_depend>
  <build_depend>roscpp</build_depend>
  <run_depend>roscpp</run_depend>
  <build_depend>rosbag</build_depend>
  <run_depend>rosbag</run_depend>
  <!-- at build time you need message_generation -->
  <build_depend>message_generation</build_depend>
  <!-- at run time you need message_runtime -->
  <run_depend>message_runtime</run_depend>

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

</package>

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 ...
(more)
edit retag flag offensive close merge delete

Comments

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
1

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

Question Tools

1 follower

Stats

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

Seen: 279 times

Last updated: Jan 15 '15