Ask Your Question

ros::service::waitForService() blocks infinite

asked 2013-03-18 08:57:45 -0500

inflo gravatar image

updated 2014-01-28 17:15:46 -0500

ngrennan gravatar image

hi, when i use ros::service::call() to call e.g. gazebo/apply_joint_effort inside a rostest (c++,gtest) the call sometimes fail and sometimes don't fail ?

So i thought, using ros::service::waitForService("gazebo/apply_joint_effort", -1)) to wait for "something" and then use the call() function, but the waitForService() is blocking endless. But when i call the service with the commandline tool "rosservice", the service is available and returns success ?

is waitForService() for another usage?

thanks flo

Change 1: Inserting

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") rosbuild_add_gtest(test/mytest test/mytest.cpp)

into CMakeList.txt file and running then the binary bin/test/mytest the service call returns success, but the service (force) does not get applied to the model in gazebo ?

gazebo dies with:

terminate called after throwing an instance of 'std::runtime_error' what(): Time is out of dual 32-bit range Aborted (core dumped)

I got ubuntu-12.04-amd64 installed. Someone knows what this error causes?

Also if i use: rosbuild_add_executable() rosbuild_add_gtest_build_flags() rosbuild_add_rostest()

in my CMakeList.txt file instead the two other options mentioned before, and run rostest mypackage mytest the test is run 3 times in a row after building? Why is that so? Also the rostest lib cannot call the service, but the test-binary can call the service (but gazebo dies) ?

Is there a way to prevent the test from running after building it with make test ?

thanks flo

edit retag flag offensive close merge delete


I think running it is the intended behaviour of make test.

dornhege gravatar image dornhege  ( 2013-03-20 06:09:30 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2013-03-18 11:26:10 -0500

dornhege gravatar image

You are passing -1 for the timeout, which means: wait infinite. Just pass a real timeout that you want to wait for.

edit flag offensive delete link more


yes i pass -1 because i want to block so long till i get the service. I know that the service is available because i can run rosservice from console "before" and "after" i run the rostest with the awaitForService() call. The question is more: why is it blocking, but the service is available ?

inflo gravatar image inflo  ( 2013-03-18 21:43:17 -0500 )edit

Maybe you did something wrong in the software. You can just call the service to see, if it works in principle.

dornhege gravatar image dornhege  ( 2013-03-19 01:28:35 -0500 )edit

like i wrote in my question, it sometimes works and sometimes fails

inflo gravatar image inflo  ( 2013-03-19 03:25:14 -0500 )edit

How are you registering the service client/calling the service? Also ros::service::call?

dornhege gravatar image dornhege  ( 2013-03-19 05:58:06 -0500 )edit

what does the <2> and the green check-mark right beside your answer mean ?

inflo gravatar image inflo  ( 2013-03-19 05:59:21 -0500 )edit

yes i use (ros::service::call("/gazebo/apply_joint_effort", req, res)

inflo gravatar image inflo  ( 2013-03-19 06:00:00 -0500 )edit

Your call does have a / before gazebo unlike the waitForService. Did you try @Hansg91's suggestion?

dornhege gravatar image dornhege  ( 2013-03-19 06:02:45 -0500 )edit

yes i tried it, like i wrote in the answer to Hansg91 :)

inflo gravatar image inflo  ( 2013-03-19 06:05:15 -0500 )edit

answered 2013-03-19 05:56:43 -0500

inflo gravatar image

the call ros::service::waitForService("/gazebo/apply_joint_effort", -1) blocks also infinite ?

my test is just:

TEST(MyTest, firstTest) { ros::Time::init(); //used for waitForService if(ros::service::waitForService("/gazebo/apply_joint_effort", -1)) EXPECT_EQ(1,2) << "wait for service ok"; }

Are there some other functions i can call to get more info? like what namespace i am in, or something?

thanks flo

edit flag offensive delete link more



Please do not create answers for discussion or comments. Instead, either edit and append to your original post or use the comment functionality.

dornhege gravatar image dornhege  ( 2013-03-19 06:55:30 -0500 )edit

answered 2013-03-19 02:06:33 -0500

Hansg91 gravatar image

I'm not sure but it might be using your namespace in the check if it is available (and is therefore waiting for /your_ns/gazebo/apply_joint_effort).

Could you try :

ros::service::waitForService("/gazebo/apply_joint_effort", -1));

That might work, because it is then ignoring your namespace. At least for registering and subscribing topics this is the case.

edit flag offensive delete link more


with the namespaces i must check (later), but i need the service to publish a service request, so registering and subscribing is not enough. i reply if it works

inflo gravatar image inflo  ( 2013-03-19 03:27:12 -0500 )edit

There are some functions for that in the ros namespace. However, if you use the / this shouldn't matter unless you remapped that.

dornhege gravatar image dornhege  ( 2013-03-19 06:55:06 -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


Asked: 2013-03-18 08:57:45 -0500

Seen: 6,154 times

Last updated: Mar 20 '13