-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgetposition.py
More file actions
85 lines (74 loc) · 2.78 KB
/
getposition.py
File metadata and controls
85 lines (74 loc) · 2.78 KB
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
"""
Get position from Water Linked Underwater GPS
"""
import argparse
import json
import requests
def get_data(url):
try:
r = requests.get(url)
except requests.exceptions.RequestException as exc:
print("Exception occured {}".format(exc))
return None
if r.status_code != requests.codes.ok:
print("Got error {}: {}".format(r.status_code, r.text))
return None
return r.json()
def get_antenna_position(base_url):
return get_data("{}/api/v1/config/antenna".format(base_url))
def get_acoustic_position(base_url):
return get_data("{}/api/v1/position/acoustic/filtered".format(base_url))
def get_global_position(base_url, acoustic_depth = None):
return get_data("{}/api/v1/position/global".format(base_url))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"-u",
"--url",
help = "Base URL to use",
type = str,
default = "https://demo.waterlinked.com")
parser.add_argument(
"-a",
"--antenna",
action = "store_true",
help = (
"Use mid-point of base of antenna as origin for the acoustic " +
"position. Default origin is the point at sea level directly " +
"below/above that which the positions of the receivers/antenna " +
"are defined with respect to"))
args = parser.parse_args()
base_url = args.url
print("Using base_url: %s" % args.url)
acoustic_position = get_acoustic_position(base_url)
antenna_position = None
if args.antenna:
antenna_position = get_antenna_position(base_url)
depth = None
if acoustic_position:
if antenna_position:
print(acoustic_position)
print(antenna_position)
print("Current acoustic position relative to antenna. X: {}, Y: {}, Z: {}".format(
acoustic_position["x"] - antenna_position["x"],
acoustic_position["y"] - antenna_position["y"],
acoustic_position["z"] - antenna_position["depth"]))
else:
print("Current acoustic position. X: {}, Y: {}, Z: {}".format(
acoustic_position["x"],
acoustic_position["y"],
acoustic_position["z"]))
depth = acoustic_position["z"]
global_position = get_global_position(base_url)
if global_position:
if depth:
print("Current global position. Latitude: {}, Longitude: {}, Depth: {}".format(
global_position["lat"],
global_position["lon"],
depth))
else:
print("Current global position latitude :{} longitude :{}".format(
global_position["lat"],
global_position["lon"]))
if __name__ == "__main__":
main()