Importing services declared in the same package in python and catkin
I'm building om groovy a catkin package that declares a service and contains a python node that acts as server for the service.
The service is declared in the file usv_comm/srv/sendTwist.srv
.
The node script is in the file usv_comm/scripts/usv_comm.py
.
The service is listed correctly when I make a rossrv list
and rossrv show usv_comm/sendTwist
.
The service is imported into the python script by from usv_comm.srv import sendTwist
.
However, when I run the node as rosrun usv_comm usv_comm.py
, I get the following error:
from usv_comm.srv import sendTwist
ImportError: No module named srv
I have previously declared and used services with rosbuild without problems, but I'm quite new to catkin so I'm basically lost right now.
I have followed the tutorials for creating srv (wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv) and using services (wiki.ros.org/ROS/Tutorials/WritingServiceClient%28python%29) for catkin and python.
Any insight in this problem will be appreciated.
Configuration files:
setup.py
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['usv_comm'],
package_dir={'': 'scripts'}
)
setup(**d)
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(usv_comm)
find_package(catkin REQUIRED COMPONENTS
rospy
roscpp
std_msgs
geometry_msgs
message_generation
)
add_service_files(
DIRECTORY srv
FILES
sendTwist.srv
)
generate_messages(
DEPENDENCIES
std_msgs
geometry_msgs
)
catkin_package(
CATKIN_DEPENDS rospy std_msgs geometry_msgs message_runtime
)
include_directories(
${catkin_INCLUDE_DIRS}
)
package.xml
<?xml version="1.0"?>
<package>
<name>usv_comm</name>
<version>0.0.0</version>
<description>The usv_comm package</description>
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<run_depend>rospy</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
</package>
Thank you and best regards.
Edit 1: Added CMakeLists.txt file.
Edit 2: Added package.xml
Edit 3: Added setup.py
Did your package build successfully? What is in your ~/catkin_ws/devel/lib/python2.7/dist-packages/usv_comm/srv folder?
Yes, the package build successfully. In that folder there are two files: __init__.py and _sendTwist.py.
what does "echo $PYTHONPATH" print?
That looks OK. It might help for you to edit your original question, adding relevant parts of your CMakeLists.txt.
You might also check with this page: http://docs.ros.org/api/catkin/html/howto/building_msgs.html .
Thank you for your suggestions. I will edit the question adding the CMakeLists.txt.
Adding this might help: ``catkin_install_python(PROGRAMS scripts/usv_comm.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})``