-
Notifications
You must be signed in to change notification settings - Fork 9
/
boatdctl
executable file
·107 lines (82 loc) · 2.93 KB
/
boatdctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
'''
boatdctl - boatd control
Usage:
boatdctl status
boatdctl heading
boatdctl position
boatdctl spin
boatdctl rudder <angle>
boatdctl sail <angle>
Options:
-h --help Show this screen.
--version Show boatd version
'''
import argparse
import sys
from boatdclient import Boat
from boatdclient import Boatd
from boatdclient import Behaviour
if __name__ == '__main__':
arger = argparse.ArgumentParser()
arger.add_argument('--host', default='localhost',
help='host boatd is listening on')
arger.add_argument('--port', type=int, default=2222,
help='port boatd is listening on')
subparsers = arger.add_subparsers(dest='command')
help_parser = subparsers.add_parser('help')
info_parser = subparsers.add_parser('status')
quit_parser = subparsers.add_parser('quit')
behaviour_list_parser = subparsers.add_parser('behaviour-list')
behaviour_start_parser = subparsers.add_parser('behaviour-start')
behaviour_stop_parser = subparsers.add_parser('behaviour-stop')
behaviour_start_parser.add_argument('behaviour')
heading_parser = subparsers.add_parser('heading')
position_parser = subparsers.add_parser('position')
spin_parser = subparsers.add_parser('spin')
rudder_parser = subparsers.add_parser('rudder')
rudder_parser.add_argument('angle')
sail_parser = subparsers.add_parser('sail')
sail_parser.add_argument('angle')
opts = arger.parse_args()
boatd = Boatd(host=opts.host, port=opts.port)
boat = Boat(boatd=boatd)
if opts.command == 'help':
print(__doc__)
if opts.command == 'status':
try:
v = boat.boatd.version
except Exception as e:
print('Problem talking to boatd: "{}"'.format(e))
sys.exit(1)
print('boatd version \'{}\' responding to requests on {}'.format(v,
boat.boatd.url('/')))
if opts.command == 'quit':
boat.boatd.quit()
if opts.command == 'behaviour-list':
behaviour = Behaviour()
for name in behaviour.list():
print(name)
if opts.command == 'behaviour-start':
behaviour = Behaviour()
name = opts.behaviour
message = behaviour.start(name)
print(message)
if opts.command == 'behaviour-stop':
behaviour = Behaviour()
behaviour.stop()
if opts.command == 'heading':
print('heading: {}'.format(boat.heading))
if opts.command == 'position':
print('position: {0:.9f}, {0:.9f}'.format(*boat.position))
if opts.command == 'rudder':
print('setting rudder to', opts.angle)
boat.set_rudder(float(opts.angle))
if opts.command == 'sail':
print('setting sail to', opts.angle)
boat.set_sail(float(opts.angle))
if opts.command == 'spin':
import time
for i in range(90):
a = 45 - (i)
boat.set_rudder(a)