Ask Your Question
0

ROS Service global name not defined

asked 2019-01-18 10:58:41 -0500

Jägermeister gravatar image

updated 2019-01-18 11:14:06 -0500

I am trying to make my node a ROS service which gets triggered when it receives boolean value of true, thus I have added the following to its constructor:

self.imgproc_srv = rospy.Service("/perception/request_detection", RequestDetection, self.detection_processor_srv)

here is the callback:

def detection_processor_srv(self, req): 
         print("It works!")
   return

And of course, I have the file RequestDetection.srv as:

bool detection_requested # our trigger to initiate the visual detection

and I imported this in my script as:

from common.srv import *

which is where I plan to keep the services.

Needless to say, I did catkin_make as well, after all this.

Yet I receive:

NameError: global name 'RequestDetection' is not defined

What am I doing wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-01-18 11:12:08 -0500

It looks like you haven't defined your service properly, I would have expected you to get an error when you try and catkin_make this.

If you look at the tutorial on messages and services, you can see that a service needs to define both the request and response parts separated by there hyphens --- like the example shown there:

int64 a
int64 b
---
int64 sum

As also described in the tutorial above you need to setup your CMakeLists.txt file to make sure that this service is built too.

Hope this helps.

edit flag offensive delete link more

Comments

If I only want to call this service and not expect anything in return, the parts above --- are not required, right? I noticed since I won't expect anything, it should now work as it is like in my code?

EDIT: It was the CMakeLists.txt ,now it works.

Jägermeister gravatar imageJägermeister ( 2019-01-18 11:13:21 -0500 )edit

I see. Glad you got this working.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2019-01-18 12:33:25 -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: 2019-01-18 10:58:41 -0500

Seen: 127 times

Last updated: Jan 18