ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

can't access std_srvs

asked 2012-02-24 08:09:05 -0600

cassander gravatar image

The turtlesim node offers a service called "/reset" that allows me to reset the position of the turtle. The type of message accepted by the "/reset" service is of type

std_srvs.Empty

I tried to do,

import std_srvs
from std_srvs.srv import Empty

but it didn't work. I kept getting error messages saying std_srvs couldn't be found. I then tried adding 'std_srvs' as one of the dependencies in the manifest file of the package. Now the node was able to access std_srvs but not 'Empty'. Finally I had to do,

roscp std_srvs Empty mypackage/srv

and then rosmake and finally it worked.

Could someone please tell me, why I wasn't able to access std_srv.Empty before copying it to the srv folder in my package?

Thanks

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-02-24 08:16:21 -0600

DimitriProsser gravatar image

updated 2012-02-24 08:26:17 -0600

You must include the following before importing any ROS packages:

import roslib; roslib.load_manifest('package_name')

EDIT:

You must also have the packages that you want to use in your manifest.xml.

Here's an example... If your package is called "beginner_tutorials", you would put the following in your node:

import roslib; roslib.load_manifest('beginner_tutorials')

If your node uses the std_srvs package, your manifest.xml file must contain the following line:

<depend package="std_srvs" />
edit flag offensive delete link more

Comments

I got those errors I mentioned earlier in spite of having that line which you have mentioned. But did you mean to say I should have had the line "import roslib; roslib.load_manifest('std_srvs')"? I don't suppose so..

cassander gravatar image cassander  ( 2012-02-24 08:19:45 -0600 )edit
1

answered 2014-03-25 08:31:52 -0600

updated 2014-03-25 08:34:02 -0600

i did try this: atention for type Empty into msg and srv


for import msg

from std_msgs.msg import String, Float32, Empty

for import service - without problem Empty

import std_srvs.srv

publish message

take.publish(Empty())

call service

rospy.ServiceProxy('ardrone/flattrim', std_srvs.srv.Empty())

good luck!

edit flag offensive delete link more
0

answered 2022-04-01 16:10:02 -0600

dsoike gravatar image

updated 2022-04-01 16:11:41 -0600

Verify CMakeLists.txt and package.xml Specify std_srvs

If you want to use std_srvs in one of your packages via:

from std_srvs.srv import Trigger, TriggerRequest, TriggerResponse

Make sure your CMakeLists.txt file contains references to std_srvs:

find_package(catkin REQUIRED COMPONENTS
  rospy
  std_msgs
  std_srvs # <-- HERE
  message_generation
)

generate_messages(
  DEPENDENCIES
  std_msgs
  std_srvs # <-- HERE
)

catkin_package(
  CATKIN_DEPENDS rospy std_msgs std_srvs message_runtime # <-- HERE
)

And your package.xml file contains:

<!-- standard service dependencies -->
<build_depend>std_srvs</build_depend>
<run_depend>std_srvs</run_depend>
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-02-24 08:09:05 -0600

Seen: 5,151 times

Last updated: Apr 01 '22