Ask Your Question
0

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

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

Mermy 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

Mermy gravatar image

I still do not know what is happening, since it seems that turning_robot.py can load other .srv without problems, but I have been able to solve the issue. I have changed in turning_robot.py

from turn_robot.srv import TurnRobotService, TurnRobotServiceResponse

for

from turn_robot.srv import *

And now it works

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 16 times

Last updated: Aug 06