Ask Your Question

Simple Service and Client Tutorial Problem [closed]

asked 2011-06-15 06:49:18 -0500

Tubbs gravatar image

updated 2011-08-22 10:02:27 -0500

mjcarroll gravatar image

I am going through the tutorial with ROS, and its been fairly smooth so far. However, I just got to the section on creating a simple service and client in c++, and regardless of what I do, I keep running into errors when making add_two_ints_client.cpp and add_two_ints_server.cpp. They both call on a header file called AddTwoInts.h, however the tutorial never went over what that was. To compensate for that, I went and grabbed the TwoInts.h header file from the roscpp_tutorials package. At first I put it under beginners_tutorials like the example suggested, but I received a message stating beginner_tutorials was not declared in this scope. I did, however, get the code to accept TwoInts.h by just throwing it in src with the rest of the code and just calling

#include "TwoInts.h"

With that out of the way, I now receive an additional error down the line when I go to use TwoInts. I go to call

ros::ServiceClient client = n.serviceClient<TwoInts>("add_two_ints");

but the compiler says it doesn't know what TwoInts is. I then tried beginner_tutorials::TwoInts, then TwoInts::TwoInts, and even roscpp::TwoInts, but each time, it could not make.

My code looks almost identical to the sample code (aside from it being in a different location). I keep going back to past tutorials hoping to find something that mentions TwoInts.h, but if its there, I can't find it.

Has anyone run into this? How am I supposed to solve this?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Wim
close date 2011-08-02 11:26:30

2 Answers

Sort by ยป oldest newest most voted

answered 2011-06-15 07:06:48 -0500

At the top of the tutorial, in section 1.1, it says to make sure to build on two completed tutorials:

I suspect that using those will resolve your issue.

edit flag offensive delete link more

answered 2011-06-16 05:27:29 -0500

Tubbs gravatar image

Well, I have finally managed to get the example to build. To do so:

  1. copy the TwoInts.h file from roscpp_tutorials to the include folder of your tutorial project.
  2. rename the namespace for the TwoInts.h file to your project name and go through and change every recurrance. i.e. since my project was under beginner_tutorials, change every roscpp_tutorials::TwoInt to beginner_tutorials::TwoInt
  3. in your add_two_ints_server.cpp and add_two_ints_client.cpp files, make sure the include refers to where you put the TwoInts.h (also, make sure its not 'AddTwoInts.h' like the tutorial)
  4. When you go to use TwoInts in your client and server file, make sure it refers to your namespace (for me it was beginner_tutorials::TwoInt).
edit flag offensive delete link more


"TwoInts.h" is an auto-generated header file that should neither be copied, moved, nor manipulated. The proper way to do this is to follow Asomerville's advice and create the AddTwoInts.srv file as directed by
jbohren gravatar image jbohren  ( 2011-06-16 05:38:25 -0500 )edit

Question Tools


Asked: 2011-06-15 06:49:18 -0500

Seen: 1,376 times

Last updated: Jun 16 '11