Ask Your Question

rospy.service fail

asked 2014-05-22 08:00:09 -0600

blakeh gravatar image

Now that catkin is building my service files OK, I can't run it. The relevant code section is:

    rospy.init_node('servo_cmd_server', log_level=rospy.INFO)
    rospy.loginfo("Started Phidgets Servo Command Server Node")
    rospy.loginfo("Setting up the command service")
    rospy.loginfo("Namespace: %s", rospy.get_namespace())
    rospy.loginfo("getname:   %s", rospy.get_name())
    rospy.loginfo("Resolved name:   %s", rospy.resolve_name("PhidgetsServoCommand", caller_id="retractor_ros"))

    s = rospy.Service('retractor_cmd', _PhidgetsServoCommand, handle_servo_cmd)
    print 'Ready to receive servo commands!!!.'

And the relevant output is:

[INFO] [WallTime: 1400781040.063425] Namespace: /
[INFO] [WallTime: 1400781040.063572] getname:   /servo_cmd_server
[INFO] [WallTime: 1400781040.063730] Resolved name:   /PhidgetsServoCommand
Traceback (most recent call last):
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/", line 228, in <module>
    servo_cmd_server()      # start the server (doesn't return)
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/", line 73, in servo_cmd_server
    s = rospy.Service('retractor_cmd', _PhidgetsServoCommand, handle_servo_cmd)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/impl/", line 696, in __init__
    super(Service, self).__init__(name, service_class, handler, buff_size)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/impl/", line 544, in __init__
    super(ServiceImpl, self).__init__(name, service_class)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/", line 59, in __init__
    self.request_class = service_class._request_class
AttributeError: 'module' object has no attribute '_request_class'

Any ideas?? BTW, catkin has prefixed the MyName.srv file with an underscore to create . without the underscore, you get:

[INFO] [WallTime: 1400781520.326304] Namespace: /
[INFO] [WallTime: 1400781520.326438] getname:   /servo_cmd_server
[INFO] [WallTime: 1400781520.326581] Resolved name:   /PhidgetsServoCommand
Traceback (most recent call last):
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/", line 228, in <module>
    servo_cmd_server()      # start the server (doesn't return)
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/", line 73, in servo_cmd_server
    s = rospy.Service('retractor_cmd', PhidgetsServoCommand, handle_servo_cmd)
NameError: global name 'PhidgetsServoCommand' is not defined


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-22 10:11:20 -0600

ahendrix gravatar image

It looks like you still aren't following the tutorial properly.

You should NOT be using the underscore prefixed names; those are internal to the generated module. The normal names ARE defined in the generated inside the python srv directory.

This would be easier to troubleshoot if you included your ENTIRE python program, including the import lines.

edit flag offensive delete link more


Thank you. It seems that different tutorials import differently and not as clearly. Fixing import statement to

#  Ros imports
from retractor_ros.srv import * 
import rospy
(and avoiding the underscores) Seemed to do the trick.

blakeh gravatar imageblakeh ( 2014-05-28 05:35:28 -0600 )edit

If the tutorials are incorrect, you should either update the wiki to fix them, post them here so that another user can take a look, or contact the author if they're not hosted on the ROS wiki.

ahendrix gravatar imageahendrix ( 2014-05-28 05:38:07 -0600 )edit

Actually above is wrong. somehow that line is now an error!

blakeh gravatar imageblakeh ( 2014-05-28 05:58:06 -0600 )edit

Latest output

blake@blake-Lenovo-IdeaPad-U530-Touch:~/Projects/Ros/catkin_ws$ source devel/setup.bash 
blake@blake-Lenovo-IdeaPad-U530-Touch:~/Projects/Ros/catkin_ws$ rossrv 
list      md5       package   packages  show      
blake@blake-Lenovo-IdeaPad-U530-Touch:~/Projects/Ros/catkin_ws$ rossrv show retractor_ros/PhidgetsServoCommand 
int64 servo
float64 displacement
int64 return_flag

blake@blake-Lenovo-IdeaPad-U530-Touch:~/Projects/Ros/catkin_ws$ rosrun retractor_ros 
Traceback (most recent call last):
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/", line 23, in <module>
    from PhidgetsServoCommand.srv import *
ImportError: No module named PhidgetsServoCommand.srv

blakeh gravatar imageblakeh ( 2014-05-28 06:19:33 -0600 )edit

The appropriate import is:

from retractor_ros.srv import *
from retractor_ros.srv import PhidgetsServoCommand

ahendrix gravatar imageahendrix ( 2014-05-28 06:22:32 -0600 )edit

In general, the syntax is:

from [package].srv import [service]

ahendrix gravatar imageahendrix ( 2014-05-28 06:27:42 -0600 )edit

Aha! that worked. thanks for your persistence.

blakeh gravatar imageblakeh ( 2014-05-28 06:47:36 -0600 )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


Asked: 2014-05-22 08:00:09 -0600

Seen: 3,267 times

Last updated: May 22 '14