0
$\begingroup$

Rosanswers logo

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 
    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 
    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!


Originally posted by blakeh on ROS Answers with karma: 17 on 2014-05-22

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by ahendrix with karma: 47576 on 2014-05-22

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by blakeh on 2014-05-28:
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.

Comment by ahendrix on 2014-05-28:
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.

Comment by blakeh on 2014-05-28:
Actually above is wrong. somehow that line is now an error!

Comment by blakeh on 2014-05-28:
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$ 

Comment by ahendrix on 2014-05-28:
The appropriate import is:

from retractor_ros.srv import *

or

from retractor_ros.srv import PhidgetsServoCommand

Comment by ahendrix on 2014-05-28:
In general, the syntax is:

from [package].srv import [service]

Comment by blakeh on 2014-05-28:
Aha! that worked. thanks for your persistence.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.