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

General problem with Service Server / Client (python)

asked 2016-04-21 05:03:29 -0500

El_Winnero gravatar image

updated 2016-04-21 05:10:03 -0500

Hey guys actually I'm working on a service Server, and for that i need also the client (testing) And I try to figure out how the whole service system is working ... i did work with the tutorial, but i don't know what is the missing part to get it :(

In short Form:

I do have a method of a class that generates an OccupancyGrid. in the same class i want to implement my service server (and the handler) as a method.

def handle_dynamic_map(self):
    return GetMapResponse() 

def dynamic_map_server(self):
    s = rospy.Service('dynamic_map', GetMap, self.handle_dynamic_map)

so actually i could give the OccupancyGrid in the main-function to the server.

    OcGrid = Map_Import()
    param = OcGrid.Work() # param has the whole OccupancyGrid

    OcGrid.dynamic_map_server()

well now I'm stuck ... I assume that Getmap should be OK. Cause all I need is to response with my param ...

I am working on the Client... Cause as long as I can't be sure if the server is running I can't figure out if the Client is working...

#!/usr/bin/env python

import sys
import rospy
from nav_msgs.srv import GetMap

def dynamic_map_client ():
    rospy.wait_for_service('dynamic_map')
    try:
        Map_Import = rospy.ServiceProxy('dynamic_map', GetMap)
        resp1 = Map_Import()
        print resp1
        return resp1
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

if __name__ == "__main__":
    print dynamic_map_client()

Yeah... Please help me!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-21 09:36:10 -0500

El_Winnero gravatar image

SOLVED!

Well the Problem in generl was .... the parameter was placed in there... well and i just did smth. quick and dirty ^^

    def handle_dynamic_map(self,resp):
    return GetMapResponse(param)

def dynamic_map_server(self):
    s = rospy.Service('dynamic_map', GetMap, self.handle_dynamic_map)

Yeah i know that "resp" thing at handle_dynamic_map might seem to be useless ... it only works like that

The Main was not changed...

now the Service-Client:

#!/usr/bin/env python

import sys
import rospy
from nav_msgs.srv import GetMap

def dynamic_map_client():
    rospy.wait_for_service('dynamic_map')
    try:
        Imported = rospy.ServiceProxy('dynamic_map', GetMap)

    resp1 = Imported()
    return resp1.map
except rospy.ServiceException, e:
    print "Service call failed: %s"%e

if __name__ == "__main__":
    print dynamic_map_client()

Yeah it works like that :)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-21 05:03:29 -0500

Seen: 1,731 times

Last updated: Apr 21 '16