Ask Your Question
0

Custom msg: strange error during building

asked 2014-07-25 16:42:40 -0500

Andromeda gravatar image

updated 2014-07-25 16:49:25 -0500

Hi, I really don t understand what is wrong in my program. I cannot get a custom msg working, I think it depends on the dependecies with the other packages. Here is my bone program: a simple publisher that should output a float32 just for testing:

#include <ros/ros.h>
#include "msg/customMsg.msg"

int main( int argc, char **argv ) {

    ros::init( argc, argv, "node_anadyr" );

    ros::NodeHandle node;

    ros::Publisher pub = node.advertise<msg::customMsg>( "topic_alpha", 100 );

    ros::Rate rate( 2 );

    while( ros::ok() ) {

        msg::customMsg message;

        message.data = 3.3;
        pub.publish( message );

        rate.sleep();
    }
}

Of course i created a folder in my package:

jack@D-21:~/workspace_ros/src/anadyr$ ls -l | grep msg
drwxrwxr-x 2 jack jack 4096 Jul 25 23:26 msg

inside I put the following file

customMsg.msg

containing the following line:

float32 data

but when I run the catkin_make I get the following error

....
....
####
#### Running command: "make -j1 -l1" in "/home/wilhem/workspace_ros/build"
####
Scanning dependencies of target anadyr
[ 10%] Building CXX object anadyr/CMakeFiles/anadyr.dir/main.cpp.o
In file included from /home/wilhem/workspace_ros/src/anadyr/main.cpp:2:0:
/home/wilhem/workspace_ros/src/anadyr/msg/customMsg.msg:1:1: error: ‘float32’ does not name a type
 float32 data
 ^
make[2]: *** [anadyr/CMakeFiles/anadyr.dir/main.cpp.o] Fehler 1
make[1]: *** [anadyr/CMakeFiles/anadyr.dir/all] Fehler 2
make: *** [all] Fehler 2
Invoking "make" failed

Here is my CMakelist.txt

cmake_minimum_required(VERSION 2.8.3)
project(anadyr)

find_package(catkin REQUIRED COMPONENTS roscpp message_generation std_msgs)

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

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

catkin_package(
  CATKIN_DEPENDS 
  message_runtime
  std_msgs
)

# add_executable(anadyr_node src/anadyr_node.cpp)
add_executable(anadyr main.cpp)
target_link_libraries(anadyr ${catkin_LIBRARIES})

and here my package.xml:

<?xml version="1.0"?>
<package>
  <name>anadyr</name>
  <version>0.0.0</version>
  <description>The anadyr package</description>
  <maintainer email="">wilhem</maintainer>
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>message_runtime</run_depend>
  <run_depend>std_msgs</run_depend>

</package>

I read all the tutorials I could find, but it didnt work. What worng in my dependencies?!? What should I do to use custom messages in my application? Regards

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-07-25 17:19:58 -0500

ahendrix gravatar image

updated 2014-07-25 17:50:09 -0500

Instead of including the message file msg/customMsg.msg, you should be including the generated C++ header: anadyr/customMsg.h

You may also need to add add_dependencies(anadyr ${catkin_EXPORTED_TARGETS}) to your CMakeLists.txt to make sure that the message generation is run before your program is compiled.

edit flag offensive delete link more

Comments

Thanx but it doesn t find the generated file /home/jack/workspace_ros/src/anadyr/main.cpp:2:27: fatal error: anadyr/customMsg.h: file or folder not found #include "anadyr/customMsg.h" ^ compilation terminated. make[2]: *** [anadyr/CMakeFiles/anadyr.dir/main.cpp.o] Fehler 1 make[1]: *** [anadyr/CMakeFiles/anadyr.dir/all] Fehler 2 make: *** [all] Fehler 2 Invoking "make" failed What s wrong`?

Andromeda gravatar imageAndromeda ( 2014-07-25 17:27:04 -0500 )edit

could you tell me, what should I change if I want to put all *.msg files in a third directory and not in the same folder of the package?

Andromeda gravatar imageAndromeda ( 2014-07-26 00:39:52 -0500 )edit
1

answered 2014-07-26 00:38:13 -0500

Andromeda gravatar image

updated 2014-07-26 00:43:40 -0500

Ok it didn t work anyway BUT thanks to your Idea I put and changed ONLY this line of code in my CMakeLists.txt

add_dependencies(anadyr 
  ${anadyr_EXPORTED_TARGETS}
)

and now it is compiling, building and working even for the subscriber.

I m a little bit frustrated because I read through all 4 Websites regarding the custom msg and not a tutorial is mentionign to put that line of code in that file. BUT...people are encouraged to read the tutorials at first.... It would had save me at least 3 hours of trying....

Anyway awesome!!! Thank you very much!

edit flag offensive delete link more

Comments

2

This is clearly documented in the C++ publisher and subscriber tutorial: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

ahendrix gravatar imageahendrix ( 2014-07-26 02:31:32 -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

1 follower

Stats

Asked: 2014-07-25 16:42:40 -0500

Seen: 5,845 times

Last updated: Jul 26 '14