0
$\begingroup$

Rosanswers logo

Hi everyone!

I made a custom service following this tutorial: http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv#Common_step_for_msg_and_srv

I edited the CMakeLists.txt and package.xml files as instructed.

I can see my service when I run rossrv list, but the .py file does not appear in devel/lib/python2.7/dist-packages/my_package/srv. The full path exists, but the srv directory is empty.

When I try and import the service in my python file using

from my_package.srv import my_service

I get the error:

ImportError: No module named srv

Here is my CMakeLists.txt file for your review:

cmake_minimum_required(VERSION 2.8.3)
project(my_package)


find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  nav_msgs
  roscpp
  rospy
  std_msgs
  message_generation
)


add_service_files(
  FILES
  my_service.srv
)


 generate_messages(
   DEPENDENCIES
   geometry_msgs   nav_msgs   std_msgs  
 )

catkin_package(
  CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy std_msgs message_runtime
)


include_directories(
  ${catkin_INCLUDE_DIRS}
)

Any help?

Ubuntu 12.04 ROS Hydro


Originally posted by Robocop87 on ROS Answers with karma: 255 on 2014-06-12

Post score: 1

$\endgroup$

1 Answer 1

1
$\begingroup$

Rosanswers logo

I believe the problem was the executable python file and included class were the same name as the package, so instead of trying to import from the package's srv directory it was trying to find a module within my defined class named srv, which it could not find.

Moral of the story, don't create python classes within .py files which are the same name as the ros package.

"rosrun name name.py" where "name.py" contains a class called "name" is a no-no


Originally posted by Robocop87 with karma: 255 on 2014-06-12

This answer was ACCEPTED on the original site

Post score: 9


Original comments

Comment by akab on 2016-03-26:
in my case just renaming the python file works well!

Comment by mudrole1 on 2016-04-19:
Thank you so much for this post! I spent 2h of trying to figure out what am I doing wrong.

$\endgroup$

Your Answer

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