ImportError: No module named package.srv

asked 2018-07-26 08:15:28 -0500

dougha gravatar image

I tried to get answer for my question by following the 2 web site bellow : and 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/

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


#!/usr/bin/env python

import rospy
import sys
from pc2.srv import *

    def add_two_ints_client(x, y):
            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])
            print usage()
        print "Requesting %s+%s"%(x, y)
        print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))


#!/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():
    s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
    print "Ready to add two ints."

if __name__ == "__main__":

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

edit retag flag offensive close merge delete