example.py 952 Bytes
Newer Older
1
2
3
4
5
#!/usr/bin/env python


import roslib; roslib.load_manifest('ros_extctrl')
import rospy
6
7
from ros_extctrl.srv import ExtCtrl

8

9
def interact():
10
    while not rospy.is_shutdown():
11
12
        rospy.wait_for_service('extctrl_service')
        start_controller = rospy.ServiceProxy('extctrl_service', ExtCtrl)
13
14
        line = ''
        try:
15
            line = raw_input("Choose a controller to activate: ")
16
17
18
        except EOFError:
            print('\nBye')
            break
19
        aua_id = 0
20
        try:
21
            aua_id = int(line)
22
23
24
        except ValueError:
            print("%s is not a number" % line)
            continue
25
26
        resp = None
        try:
27
            resp = start_controller(aua_id)
28
29
30
31
        except rospy.ServiceException as exc:
            print("Service did not process request: " + str(exc))
            continue
        print("%s" % resp)
32
33
34


if __name__ == '__main__':
35
36
    rospy.init_node('extctrl_usage_example')
    interact()