-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_pose.py
74 lines (65 loc) · 1.81 KB
/
update_pose.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
# Example on how to update an existing pose.
#
# The examples use the JSON API that sends a messages via
# ZMQ 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_in_port = "12911"
port = "12911"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
# Set up the ZMQ PUB-SUB communication layer.
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)
# Of course we want to update a with fresh information generated _now_.
currentTimeStamp = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
# New position to update the pose.
x = 34.97
y = 39.23
z = 0.0999
# JSON message to update an existing Transform. Note that the Transform
# (and thus the id) must
# exist beforehands, otherwise this operation does not succeed.
# in this case the "id": "3304e4a0-44d4-4fc8-8834-b0b03b418d5b"
# denotes the Transform that is cereaten in the add_pose.py example.
transforUpdateMsg = {
"@worldmodeltype": "RSGUpdate",
"operation": "UPDATE_TRANSFORM",
"node": {
"@graphtype": "Connection",
"@semanticContext":"Transform",
"id": "3304e4a0-44d4-4fc8-8834-b0b03b418d5b",
"history" : [
{
"stamp": {
"@stamptype": "TimeStampDate",
"stamp": currentTimeStamp,
},
"transform": {
"type": "HomogeneousMatrix44",
"matrix": [
[1,0,0, x],
[0,1,0, y],
[0,0,1, z],
[0,0,0,1]
],
"unit": "m"
}
}
],
}
}
# Send message.
time.sleep(1)
print (json.dumps(transforUpdateMsg))
socket.send_string(json.dumps(transforUpdateMsg))
time.sleep(1)