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

ImportError: cannot import name AddTWoIntsResponse

asked 2021-06-17 04:12:54 -0600

akash12124234 gravatar image

I am following a tutorial and where my srv file is AddTwoInts.srv

int64 a
int64 b
---
int64 sum

and i have created a server.py file under scripts

#!/usr/bin/env python

from __future__ import print_function

from service_node.srv import AddTwoInts,AddTWoIntsResponse

import rospy
def handle_add_two_inst(req):
    print("Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b)))
    return AddTwoIntsResponse(req.a + req.b)
def add_two_ints_server():
    rospy.init_node('add_two_ints_server')
    s= rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
    print("Ready to add two ints.")
    rospy.spin()

if __name__ == "__main__":
    add_two_ints_server()

after made changes on cmake and package xml and runiing catkin_make

i tried to run the server.py using

rosrun service_node server.py

and i am getting the following error

Traceback (most recent call last):
  File "/home/akash/catkin_ws/src/service_node/scripts/server.py", line 5, in <module>
    from service_node.srv import AddTwoInts,AddTWoIntsResponse
ImportError: cannot import name AddTWoIntsResponse
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-17 04:24:54 -0600

gvdhoorn gravatar image

Please pay attention to the error message:

ImportError: cannot import name AddTWoIntsResponse

notice how it says: AddTWoIntsResponse.

The name of your service is AddTwoInts. The name of the service response type would be AddTwoIntsResponse.

Both are with a lower-case w. You wrote it with an uppercase W:

from service_node.srv import AddTwoInts,AddTWoIntsResponse

Just as in your previous question (#q380524) such details are important. Capitalisation of characters matters, as w is different from W.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-06-17 04:12:54 -0600

Seen: 792 times

Last updated: Jun 17 '21