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

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.sleep(2.0)
    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!!!.'
    rospy.spin()

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/pwm_servo.py", line 228, in <module>
    servo_cmd_server()      # start the server (doesn't return)
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/pwm_servo.py", 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/tcpros_service.py", 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/tcpros_service.py", line 544, in __init__
    super(ServiceImpl, self).__init__(name, service_class)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/service.py", 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 _MyName.py . 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/pwm_servo.py", line 228, in <module>
    servo_cmd_server()      # start the server (doesn't return)
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/pwm_servo.py", line 73, in servo_cmd_server
    s = rospy.Service('retractor_cmd', PhidgetsServoCommand, handle_servo_cmd)
NameError: global name 'PhidgetsServoCommand' is not defined

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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 __init__.py 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

Comments

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 image blakeh  ( 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 image ahendrix  ( 2014-05-28 05:38:07 -0600 )edit

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

blakeh gravatar image blakeh  ( 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 pwm_servo.py 
Traceback (most recent call last):
  File "/home/blake/Projects/Ros/catkin_ws/src/pwm_ros/scripts/pwm_servo.py", line 23, in <module>
    from PhidgetsServoCommand.srv import *
ImportError: No module named PhidgetsServoCommand.srv
blake@blake-Lenovo-IdeaPad-U530-Touch:~/Projects/Ros/catkin_ws$ 

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

The appropriate import is:

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

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

In general, the syntax is:

from [package].srv import [service]

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

Aha! that worked. thanks for your persistence.

blakeh gravatar image blakeh  ( 2014-05-28 06:47:36 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 5,006 times

Last updated: May 22 '14