Exemplo n.º 1
0
    def test_offline(self):
        import rosservice
        orig_uri = os.environ['ROS_MASTER_URI']
        os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'

        try:
            c = 'rosservice'

            try:
                rosservice.get_service_type('/add_two_ints')
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_list([c, 'list'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_info([c, 'info', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_type([c, 'type', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_uri([c, 'uri', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_find(
                    [c, 'find', 'test_ros/AddTwoInts'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

            try:
                rosservice._rosservice_cmd_call(
                    [c, 'call', '/add_two_ints', '1', '2'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass

        finally:
            os.environ['ROS_MASTER_URI'] = orig_uri
    def test_offline(self):
        import rosservice
        orig_uri = os.environ['ROS_MASTER_URI']
        os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'

        try:
            c = 'rosservice'

            try:
                rosservice.get_service_type('/add_two_ints')
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException:
                pass
            
            try:
                rosservice._rosservice_cmd_list([c, 'list'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass
            
            try:
                rosservice._rosservice_cmd_info([c, 'info', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass

            try:
                rosservice._rosservice_cmd_type([c, 'type', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass

            try:
                rosservice._rosservice_cmd_uri([c, 'uri', '/add_two_ints'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass

            try:
                rosservice._rosservice_cmd_find([c, 'find', 'test_ros/AddTwoInts'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass
            
            try:
                rosservice._rosservice_cmd_call([c, 'call', '/add_two_ints', '1', '2'])
                self.fail("should have raised ROSServiceIOException")
            except rosservice.ROSServiceIOException: pass

        finally:
            os.environ['ROS_MASTER_URI'] = orig_uri
def getobjpose(modelname='atlas'):
    stdout = sys.stdout
    sys.stdout = StringIO.StringIO() # replace by stringio to capture model command
    _rosservice_cmd_call([1,2,'gazebo/get_model_state', '{model_name: '+modelname+'}'])
    sys.stdout.seek(0)
    outstr = sys.stdout.read()
    sys.stdout = stdout # restore sysout
    
    parsevars = ["x", "y", "z"]
    pos = []
    for v in parsevars:
        s = outstr[(outstr.index(v+": ")+3):(outstr.index(v+": ")+14)]
        s = s.split(' ')[0].strip()
        pos.append(float(s))
    outstr = outstr[outstr.index('orientation:'):]
    parsevars = ["x", "y", "z", "w"]
    angle = []
    for v in parsevars:
        s = outstr[(outstr.index(v+": ")+3):(outstr.index(v+": ")+14)]
        s = s.split(' ')[0].strip()
        angle.append(float(s))
    return pos, angle
def getobjpose(modelname='atlas'):
    stdout = sys.stdout
    sys.stdout = StringIO.StringIO(
    )  # replace by stringio to capture model command
    _rosservice_cmd_call(
        [1, 2, 'gazebo/get_model_state', '{model_name: ' + modelname + '}'])
    sys.stdout.seek(0)
    outstr = sys.stdout.read()
    sys.stdout = stdout  # restore sysout

    parsevars = ["x", "y", "z"]
    pos = []
    for v in parsevars:
        s = outstr[(outstr.index(v + ": ") + 3):(outstr.index(v + ": ") + 14)]
        s = s.split(' ')[0].strip()
        pos.append(float(s))
    outstr = outstr[outstr.index('orientation:'):]
    parsevars = ["x", "y", "z", "w"]
    angle = []
    for v in parsevars:
        s = outstr[(outstr.index(v + ": ") + 3):(outstr.index(v + ": ") + 14)]
        s = s.split(' ')[0].strip()
        angle.append(float(s))
    return pos, angle