-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathViconMan.py
93 lines (79 loc) · 3.9 KB
/
ViconMan.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
import socket
from random import randint
from time import sleep
class Vicon:
"""
A class for managing starting and stopping Vicon recordings
over the network.
To use this class, make sure you've armed vicon and enabled network triggers.
See this page for more info: https://docs.vicon.com/display/Nexus213/Automatically+start+and+stop+capture
Kevin Best 10/22
"""
# Local hostname: ROB-ROUSE-VICON.adsroot.itcs.umich.edu
# IP address: 141.212.77.30
def __init__(self, viconPC_IP = 'ROB-ROUSE-VICON.adsroot.itcs.umich.edu', viconPC_port = 30,
viconPath = 'E:'):
self.destinationIP = viconPC_IP
self.destinationPort = viconPC_port
self.viconPath = viconPath
self.delayPriorToRecord_ms = 0
self.fileName = ''
self.fileDescription = ''
# Setup UDP
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def start_recording(self, fileNameIn: str, fileDescription: str = 'A vicon recording'):
"""
Send command to vicon to start file recording.
Requires 2 inputs:
fileNameIn: File name to be used on the vicon PC
fileDescription: Any notes you want to add to your file. Fills the description field on vicon
"""
msg = self._assemble_payload_start(fileNameIn, fileDescription)
self.sock.sendto(msg, (self.destinationIP, self.destinationPort))
def stop_recording(self):
msg = self._assemble_payload_stop()
self.sock.sendto(msg, (self.destinationIP, self.destinationPort))
def _assemble_payload_start(self, fileNameIn, fileDescription):
"""
Creates the proper XML string to trigger vicon.
More documentation available here:
https://docs.vicon.com/pages/viewpage.action?pageId=152010925
"""
# Update self
self.fileName = fileNameIn
self.fileDescription = fileDescription
# Construct the string
notes = 'Vicon triggered from python over UDP'
cmdHeader = '\n<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<CaptureStart>\n'
nameLine = '<Name VALUE="{}"/>\n'.format(self.fileName)
notesLine = '<Notes VALUE="{}"/>\n'.format(notes)
descriptionLine = '<Description VALUE="{}"/>\n'.format(self.fileDescription)
databasePathLine = '<DatabasePath VALUE="{}"/>\n'.format(self.viconPath)
delayLine = '<Delay VALUE="{}"/>\n'.format(self.delayPriorToRecord_ms)
packetIDline = '<PacketID VALUE="{}"/>\n'.format(randint(1,2**16))
suffixLine = '</CaptureStart>'
fullPayloadString = cmdHeader + nameLine + notesLine + descriptionLine + databasePathLine + delayLine + packetIDline + suffixLine
# print(fullPayloadString)
# Convert string to utf-8 bytes string to send over network.
return bytes(fullPayloadString, "utf-8")
def _assemble_payload_stop(self):
"""
Creates the proper XML string to stop vicon.
More documentation available here:
https://docs.vicon.com/pages/viewpage.action?pageId=152010925
"""
cmdHeader = '\n<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<CaptureStop RESULT="SUCCESS">\n'
nameLine = '<Name VALUE="{}"/>\n'.format(self.fileName)
databasePathLine = '<DatabasePath VALUE="{}"/>\n'.format(self.viconPath)
delayLine = '<Delay VALUE="{}"/>\n'.format(self.delayPriorToRecord_ms)
packetIDline = '<PacketID VALUE="{}"/>\n'.format(randint(1,2**16))
suffixLine = '</CaptureStop>'
fullPayloadString = cmdHeader + nameLine + databasePathLine + delayLine + packetIDline + suffixLine
# print(fullPayloadString)
# Convert string to utf-8 bytes string to send over network.
return bytes(fullPayloadString, "utf-8")
if __name__ == '__main__':
vicon = Vicon()
vicon.start_recording('File1')
sleep(5)
vicon.stop_recording()