0
$\begingroup$

Rosanswers logo

I've got a python node which runs a service server. Catkin builds it fine and builds the service files (works fine for another package in C++ which uses the same .srv file). Even though it builds the file fine, at runtime the node can't import it. If I revise the python search path as shown:

PYTHONPATH='/home/blake/Projects/Ros/catkin_ws/devel/lib/python2.7/dist-packages/retractor_ros/srv/':$PYTHONPATH

it works. Here's my CMakelist.txt

cmake_minimum_required(VERSION 2.8.3)
project(retractor_ros)

set(BH_LIB_NAME XXXXXXXXXXX)


## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRE COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  rospy
  roscpp
  std_msgs
  message_generation
  ${BH_LIB_NAME}
)
 
 
## Generate services in the 'srv' folder
add_service_files(
   FILES
   PhidgetsServoCommand.srv
#   Service1.srv
#   Service2.srv
)
 
## Generate added messages and services with any dependencies listed here
 generate_messages(
   DEPENDENCIES
   std_msgs
 )
 
catkin_package(
  INCLUDE_DIRS 
#   LIBRARIES ${BH_LIB_NAME}
  CATKIN_DEPENDS message_runtime rospy roscpp std_msgs rstate_machine
#  DEPENDS system_lib
)

###########
## Build ##
########### 
include_directories(
  ${catkin_INCLUDE_DIRS}
#   /opt/ros/hydro/include/turtle_actionlib
  /home/blake/Projects/Ros/catkin_ws/devel/include/retractor_ros
  /home/blake/Projects/Ros/catkin_ws/src/pwm_ros
  /home/blake/Projects/Ros/catkin_ws/src/rstate_machine/include
)
  

## Declare a cpp executable
add_executable(retractor_ros_node retractor_fsm.cpp keyinput.cpp)
target_link_libraries(retractor_ros_node ${BH_LIB_NAME} ${catkin_LIBRARIES})

add_dependencies(${PROJECT_NAME}_node servo_fsm_generate_messages_cpp keyinput.cpp rstate_machine.cpp)
  
install(PROGRAMS
   scripts/pwm_servo.py
   ../devel/lib/retractor_ros/retractor_ros_node
   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
   )

## Mark executables and/or libraries for installation
install(TARGETS retractor_ros_node
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 ) 

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

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I suspect this happens because you aren't importing the service module correctly in your python node.

I suspect you're doing:

import PhidgetsServoCommand

Instead, you should be doing:

from retractor_ros.srv import PhidgetsServoCommand

We can debug more if you add the import line from your node and the python error you're receiving to your question.


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

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by blakeh on 2014-05-22:
Thanks - your fix worked! To bad it's not in the documentation !

Comment by Dirk Thomas on 2014-05-22:
Actually it is part of the first rospy Service tutorial: http://wiki.ros.org/rospy_tutorials/Tutorials/WritingServiceClient

Comment by blakeh on 2014-05-22:
Now that I can import, i find that I can't actually start the service. Basically my project was working as long as I used the "AddTwoInts" service but I think somehow .h files from the ros distribution were sneaking into my build. Now that I have changed the name to "PhidgetsServoCommand", I had trouble above. Now that that is fixed, I can't do rospy.Service(). I'm going to post a new question with details... (Thanks again!)

$\endgroup$

Your Answer

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