Ask Your Question
0

ROSTutorialsWritingPublisherSubscriber(c++)

asked 2015-02-03 15:15:30 -0500

YunfeiLu gravatar image

updated 2015-02-05 01:59:09 -0500

gvdhoorn gravatar image

I have some questions when I go through this tutorial. When I finished 1.1 and 1.2, then in the 1.3 I try to change the content in the CMakeLists.txt, then it's supposed to create two executables, talker and listener, which by default will go into package directory of your devel space, located by default at ~/catkin_ws/devel/lib/share/, however there isn't share in lib and there are no executables.

Hello everyone, after I asked for some people's help finally I solved this problem, first of all, something was wrong in the tutorial that is there does not exist ~/catkin_ws/devel/lib/share/, instead we have devel/lib/beginner_tutorials (which is my package name). But before we get two executable in beginner_tutorials, the last thing we should do is to change some content in Cmakelists.txt, the Cmakelists.txt in the tutorial also has something wrong.
In the tutorial:

# %Tag(FULLTEXT)%
cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

# %EndTag(FULLTEXT)%

we should comment out

add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

this two line, which means it should be like this: #add.......

if you don't do this, you will find something wrong when you try to use catkin_make

edit retag flag offensive close merge delete

Comments

Could you add the CMakeLists.txt and the console output from catkin_make in your post?

kokirits gravatar image kokirits  ( 2015-02-04 01:35:14 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-02-05 02:11:05 -0500

gvdhoorn gravatar image

updated 2015-02-05 02:14:50 -0500

Without the actual console output from your catkin_make invocation (and the error message), the below is just a guess, but:

[..] we should comment out

add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

this two line, which means it should be like this: #add.......

if you don't do this, you will find something wrong when you try to use catkin_make

I don't think your suggested changes are needed.

Do you still have the Num.msg and AddTwoInts.srv files in the msg and srv subdirectories of your package from the Creating a ROS msg and srv tutorial? If you don't, then catkin_make will probably fail, as it cannot find those files.

The Writing a Simple Publisher and Subscriber (C++) tutorial explicitly states (under 1.3 Building your nodes) (emphasis mine):

The generated CMakeLists.txt should look like this (with modifications from the Creating Msgs and Srvs tutorial and unused comments and examples removed)

And then shows the lines you added to your OP.

If msg/Num.msg and srv/AddTwoInts.srv are no longer in your package, then you should comment the lines you suggested. But in general they should be there, as the next tutorials (Writing a Simple Service and Client (C++) fi) depend on them.

edit flag offensive delete link more
0

answered 2015-02-04 08:51:49 -0500

I believe that is just a mistake in the tutorial, at least for current versions of Catkin (I just updated the tutorial page). On current versions of Catkin using Groovy, Hydro, and Indigo the default location for these executables should be ~/catkin_ws/devel/lib/beginner_tutorials/ (I've removed the share/ directory). Are your talker and listener executables located in this location?

edit flag offensive delete link more

Comments

No, my lib only has pkgconfig

YunfeiLu gravatar image YunfeiLu  ( 2015-02-04 09:27:20 -0500 )edit

Did you run catkin_make from the ~/catkin_ws/ directory after updating the CMakeLists.txt for the beginner_tutorials package (as instructed in the tutorial)? If you did, the last few lines of that output should say something about "Linking CXX executable..." and "[100%] Built target..."

jarvisschultz gravatar image jarvisschultz  ( 2015-02-04 10:14:42 -0500 )edit

If your catkin_make call isn't actually building your executable, then as @kokirits suggested, we'd need to see the output of catkin_make. Your CMakeLists.txt file wouldn't hurt either, but hopefully yours is exactly like the one in the tutorial.

jarvisschultz gravatar image jarvisschultz  ( 2015-02-04 10:16:13 -0500 )edit

Oh my god, it finally worked, the Cmakelists.txt file has something wrong

 # add_message_files(FILES Num.msg)
# add_service_files(FILES AddTwoInts.srv)
# generate_messages(DEPENDENCIES std_msgs)
YunfeiLu gravatar image YunfeiLu  ( 2015-02-04 12:12:02 -0500 )edit

sorry, I don't know how to attach the code, but some line in the CMakelist.txt should be commented out.

YunfeiLu gravatar image YunfeiLu  ( 2015-02-04 12:13:00 -0500 )edit

Typically the nicest thing for future users would be for you to edit your original question explaining the resolution. Also if your problem is solved, it would be nice to accept an answer. Thanks!

jarvisschultz gravatar image jarvisschultz  ( 2015-02-04 18:06:13 -0500 )edit

Yeah,I'd like to help other new users, I'm going to do it right now

YunfeiLu gravatar image YunfeiLu  ( 2015-02-04 18:25: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: 2015-02-03 15:15:30 -0500

Seen: 657 times

Last updated: Feb 05 '15