-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd_artva_signal.py
117 lines (102 loc) · 3.33 KB
/
add_artva_signal.py
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
108
109
110
111
112
113
114
115
# Example on how to add a new ARTVA measurement to the RSG.
# A single measurement is represented by a Node.
# It has a relation to a GIS origin via Geo Pose (Transform with wgs84 tag, and latlon unit)
#
# The examples use the JSON API that sends a messages via
# ZMQ REQ-REP pattern to the SHERPA WM.
import zmq
import random
import sys
import time
import datetime
import json
# The port is defined by the system composition (sherpa_world_model.usc) file
# via the ``local_json_in_port`` variable.
# e.g.
# local local_json_query_port = "22422"
port = "22422"
# Set up the ZMQ REQ-REP communication layer.
context = zmq.Context()
def sendMessageToSWM(message):
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:%s" % port) # Currently he have to reconnect for every message.
print("Sending update: %s " % (message))
socket.send_string(message)
result = socket.recv()
print("Received result: %s " % (result))
# JSON message to CREATE an origin Node. (As child to the root node.)
newOriginMsg = {
"@worldmodeltype": "RSGUpdate",
"operation": "CREATE",
"node": {
"@graphtype": "Group",
"id": "953cb0f0-e587-4880-affe-90001da1262d",
"attributes": [
{"key": "gis:origin", "value": "wgs84"},
{"key": "comment", "value": "Reference frame for geo poses. Use this ID for Transform queries."},
],
},
"parentId": "e379121f-06c6-4e21-ae9d-ae78ec1986a1",
}
# JSON message to CREATE a new Node. Note, that the parentId must
# exist beforehands, otherwise this operation does not succeed.
# in this case the "parentId": "3304e4a0-44d4-4fc8-8834-b0b03b418d5b"
# denotes the origin node. Though this is a rather arbitrary choice.
# The root node should be fine as well. As best practice a common "measurements"
# Group is recommend.
newArtvaNodeMsg = {
"@worldmodeltype": "RSGUpdate",
"operation": "CREATE",
"node": {
"@graphtype": "Node",
"id": "3e02fe9f-bc0a-4192-86d3-28dfff75f8c9",
"attributes": [
{"key": "sherpa:artva_signal", "value": "77"},
{"key": "sherpa:stamp", "value": "2016-05-22T11:48:05Z"},
],
},
"parentId": "953cb0f0-e587-4880-affe-90001da1262d",
}
# JSON message to CREATE a new Transform. Note that the parentId must
# exist beforehands, otherwise this operation does not succeed.
newTransformMsg = {
"@worldmodeltype": "RSGUpdate",
"operation": "CREATE",
"node": {
"@graphtype": "Connection",
"@semanticContext":"Transform",
"id": "3304e4a0-44d4-4fc8-8834-b0b03b418d5b",
"attributes": [
{"key": "tf:type", "value": "wgs84"}
],
"sourceIds": [
"953cb0f0-e587-4880-affe-90001da1262d",
],
"targetIds": [
"3e02fe9f-bc0a-4192-86d3-28dfff75f8c9",
],
"history" : [
{
"stamp": {
"@stamptype": "TimeStampDate",
"stamp": "2016-05-22T11:48:05Z",
},
"transform": {
"type": "HomogeneousMatrix44",
"matrix": [
[1,0,0,44.153278],
[0,1,0,12.241426],
[0,0,1,2134],
[0,0,0,1]
],
"unit": "latlon"
}
}
],
},
"parentId": "953cb0f0-e587-4880-affe-90001da1262d",
}
# Send the messages.
sendMessageToSWM(json.dumps(newOriginMsg))
sendMessageToSWM(json.dumps(newArtvaNodeMsg))
sendMessageToSWM(json.dumps(newTransformMsg))