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

Importing a service in python defined by others

asked 2020-05-12 04:58:26 -0600

Bernat Gaston gravatar image

I am stuck in something that should be pretty easy... I have a service called "set_odometry", which I can use doing rosservice from the bash. This service is installed from apt-get so I don't have the code for it, I guess it is written in C++ but it shares the .srv file in /opt/kinetic/share/PATH_TO_SERVICE/set_odometry.srv

Now, I want to use it from my python based node. Of course, I can simply do a rosservice call from the script, but I think this is not the way to proceed. I am trying to use it as if it was a service that I defined, this means using rospy.ServiceProxy. However, I can not import the .srv in my python code. I have tried several ways to do

from set_odometry.srv import *

It always answers no module named set_odometry. I have included /opt/kinetic/share/PATH_TO_SERVICE/ in my python path, I have added __init__.py in the folder... nothing has worked so far. I think this should be something easy and standard to do, I mean, using another one's service from my code, but I am unable to do it.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2020-05-12 05:11:45 -0600

ipa-jba gravatar image

Hi, I'm not sure about your definition of the service file. A quick google search lead me to https://github.com/RobotnikAutomation... which provides a service definition and maybe was released for kinetic, so the path would be /opt/ros/kinetic/….

My assumption is you confused the package name with the service name here. Like in the Tutorial (http://wiki.ros.org/ROS/Tutorials/Wri...) you have to from package_name.srv import *, so in your case from robotnik_msgs.srv import * (even though in general just import the things you need, so SetOdometry and SetOdometryRequest in this case)

If the command line command rossrv show robotnik_msgs/SetOdometry works, then the import statement of your python script should work as well.

Hope this helps.

edit flag offensive delete link more

Comments

Thanks! it worked. Ok I understand the error that I was doing. Thank you so much

Bernat Gaston gravatar image Bernat Gaston  ( 2020-05-12 05:22:44 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2020-05-12 04:58:26 -0600

Seen: 1,090 times

Last updated: May 12 '20