Robotics StackExchange | Archived questions

ImportError: No module named package.srv

I tried to get answer for my question by following the 2 web site bellow : http://wiki.ros.org/ROS/Tutorials/MultipleMachines and http://wiki.ros.org/ROS/NetworkSetup My work : i'm trying to communicate between 2 machines with custom messages ( client/server ). In PC1: i create : - a catkin package named "pc1" . - msg/Num.msg inside pc1. - scripts/client.py

In PC2: i create : - a catkin package named "pc2" . - srv/AddTwoInts.srv inside pc2. - scripts/server.py

pc1/scripts/client.py:

#!/usr/bin/env python

import rospy
import sys
from pc2.srv import *

    def add_two_ints_client(x, y):
        rospy.wait_for_service('add_two_ints')
        try:
            add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
            resp1 = add_two_ints(x, y)
            return resp1.sum
        except rospy.ServiceException, e:
            print "Service call failed: %s"%e

    def usage():
        return "%s [x y]"%sys.argv[0]

    if __name__ == "__main__":
        if len(sys.argv) == 3:
            x = int(sys.argv[1])
            y = int(sys.argv[2])
        else:
            print usage()
            sys.exit(1)
        print "Requesting %s+%s"%(x, y)
        print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))

pc2/scripts/server.py:

#!/usr/bin/env python

from pc2.srv import *
import rospy

def handle_add_two_ints(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()

i executed in pc2 ssh command with $ roscore and $ rosrun pc2 server.py in pc1 , i executed ssh and export commends but when i executed $rosrun pc1 client.py i faced this ERROR: importError: No module named pc1.srv

Asked by dougha on 2018-07-26 08:15:28 UTC

Comments

Answers