Error while importing services for python : ImportError: No module named srv
Hello everyone, I am new to the ROS community and I am currently learning to use ROS kinetic, but I'm unable to find an easy way to create and use a service proprely. I have updated the CMakelist and the package.xml file as described in this tutorials in order to account for the new .srv file, but I still have ImportError. I have also double checked in this Cmakelist documentation. I hope that it is a small and dumb mistake. The weird thing is that the service seems to be recognized by ros. I find that the documentation is pretty vague about this, or maybe I just skipped a step.
Here is the code of my wcomputation_node.py:
#!/usr/bin/env python
import rospy
import numpy as np
from geometry_msgs.msg import Pose2D
from wcomputation.srv import *
Here is the Wservice.srv file
float64 x
float64 y
float64 theta
---
float64 wa
float64 wb
float64 wc
.
├── CMakeLists.txt -> /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
├── gui
│ ├── CMakeLists.txt
│ ├── launch
│ │ └── gui.launch
│ ├── package.xml
│ └── src
│ └── gui.py
└── wcomputation
├── CMakeLists.txt
├── msg
├── package.xml
├── scripts
│ ├── sendserial.py
│ ├── wcomputation_node.py
│ └── wcomputation_node.pyc
├── src
└── srv
└── Wservice.srv
And finally the service seems to be recognized by ROS
user@ordi:~/Bureau/omniROS/omniROS_ws/src$ rossrv show wcomputation/Wservice float64 x
float64 y
float64 theta
---
float64 wa
float64 wb
float64 wc
user@ordi:~/Bureau/omniROS/omniROS_ws/src$ rossrv info wcomputation/Wservice
float64 x
float64 y
float64 theta
---
float64 wa
float64 wb
float64 wc
And here is my CMakeList :
EDIT : I do need to use this service via a python script. Here is my CMakeList file :
cmake_minimum_required(VERSION 2.8.3)
project(wcomputation)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
roscpp
rospy
message_generation
std_msgs
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to ...
Hi Robin, Have you tried the solution in this post : https://answers.ros.org/question/2716... ?
Yes I did, I have copied the content of my CMakeList file
Where's your python script in this? I don't see any install or python rules
So, maybe you forgot to run catkin_make ? Or did you install anaconda or an other python interpreter that can change your default python 2.7 to python 3 ? btw, you can upload a link to you workspace if you have one, you should have enough Karma (or you can put it in a
to show it :) )
I'm talking about your cmakelists file, there's no install rules for python or setting up the workspace to work with it.