ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rospy: cannot import name for services, request and response from test

asked 2019-08-02 06:33:10 -0500

Bernat Gaston gravatar image

Hi all,

I am quite new to ROS and I am trying to figure it out. I am using rospy and I have just created a Service following the tutorial. It seems that everything is working since I can rosrun my script and it works. However when I try to unittest my script, it gives an error when loading the service, the request or the response.

Specifically: turning_robot.py:

from turn_robot.srv import TurnRobotService, TurnRobotServiceResponse
class TurnRobot()
    def __init__(self):
        rospy.Service('~turn_robot', TurnRobotService , self.cb_turn_robot)

and then in my test_turn_robot.py

from turn_robot.scripts.turning_robot import TurnRobot
class TestTurnRobot:

and when the test loads the script it gives an error in the import line of the script

from turn_robot.srv import TurnRobotService, TurnRobotServiceResponse
ImportError: cannot import name TurnRobotService
-------------------- >> begin captured logging << --------------------
rospy.topics: INFO: topicmanager initialized
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 1 test in 0.001s
from turn_robot.srv import TurnRobotService, TurnRobotServiceResponse
ImportError: cannot import name TurnRobotService
-------------------- >> begin captured logging << --------------------
rospy.topics: INFO: topicmanager initialized
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 1 test in 0.001s

The tree of my folder is

.
├── CMakeLists.txt
├── config
│   └── config_turn.yaml
├── __init__.py
├── __init__.pyc
├── launch
│   └── turn_robot.launch
├── package.xml
├── scripts
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── turning_robot.py
│   └── turning_robot.pyc
├── srv
│   ├── __init__.py
│   ├── __init__.pyc
│   └── TurnRobotService.srv
└── tests
    ├── __init__.py
    ├── __init__.pyc
    ├── test_turn_robot.py
    └── test_turn_robot.pyc

Moreover I can find this in my computer

catkin_ws/devel/include/turn_robot/TurnRobotService.h
catkin_ws/devel/include/turn_robot/TurnRobotServiceRequest.h
catkin_ws/devel/include/turn_robot/TurnRobotServiceResponse.h

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-08-06 03:11:06 -0500

Bernat Gaston gravatar image

updated 2019-11-05 03:18:29 -0500

Edited: It seems the problem is in the unittesting, since I can rosrun without problems. So it is definitely a problem of paths. Anyway, I have somehow been able to solve the problem I have changed in turning_robot.py

from turn_robot.srv import TurnRobotService, TurnRobotServiceResponse

for

from turn_robot.srv import *

And now it works. It is not the best solution since I don't like to import classes that I really don't need, but I have been unable to find any other solution

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-08-02 06:33:10 -0500

Seen: 814 times

Last updated: Nov 05 '19