Пример #1
0
def run_empty_service():
    ros_client = Ros('127.0.0.1', 9090)
    ros_client.run()

    service = Service(ros_client, '/test_empty_service', 'std_srvs/Empty')
    service.advertise(lambda req, resp: True)
    time.sleep(1)

    client = Service(ros_client, '/test_empty_service', 'std_srvs/Empty')
    client.call(ServiceRequest())

    service.unadvertise()
    time.sleep(2)
    service.ros.terminate()
Пример #2
0
def run_add_two_ints_service():
    ros_client = Ros('127.0.0.1', 9090)
    ros_client.run()

    def add_two_ints(request, response):
        response['sum'] = request['a'] + request['b']

        return False

    service_name = '/test_sum_service'
    service_type = 'rospy_tutorials/AddTwoInts'
    service = Service(ros_client, service_name, service_type)
    service.advertise(add_two_ints)
    time.sleep(1)

    client = Service(ros_client, service_name, service_type)
    result = client.call(ServiceRequest({'a': 2, 'b': 40}))
    assert (result['sum'] == 42)

    service.unadvertise()
    time.sleep(2)
    service.ros.terminate()