1"""Reference example of the PST SDK
2
3This example shows how to use the PST SDK to adjust the PST Tracker reference system.
4The reference system defines the Cartesian coordinate system in which tracking results
5are reported. The example shows how to set the reference system by supplying a 4x4
6homogeneous transformation matrix. It also shows how to check if the reference system
7was set successfully.
8
9Copyright PS-Tech B.V. All Rights Reserved.
10"""
11import context
12import time
13import sys
16
17
18running = True
19max_samples = 1000
20samples = 0
21
22"""Helper function for printing """
23def print_matrix(matrix):
24 for y in range(4):
25 for x in range(4):
26 print(str(matrix[x + y * 4]), end="\t")
27 print("")
28 print("\n")
29
30
31running = True
32
33
34max_samples = 100
35
36
37samples = 0
38
39"""Implementation of the pst.Listener class to receive tracking data and mode changes."""
40class MyListener(pst.Listener):
41
42 """Implementation of a tracker data callback function
43
44 Implementation of a tracker data callback function. The on_tracker_data
45 function receives the data as soon as it becomes available.
46
47 Args:
48 tracker_data: Object containing tracking information retrieved from tracker
49 status_message: Status message reported by the tracker.
50
51 See Also:
52 pstech.pstdk.trackerdata.TrackerData
53 pstech.pstsdk.errors.EStatusMessage
54 """
55 def on_tracker_data(self, tracker_data, status_message):
56 global samples
57 global running
58
59 if samples >= max_samples:
60 running = False
61
62 samples += 1
63
64
65"""Helper function to register the exit handler with the application"""
66def register_exit_handler():
67 if sys.platform.startswith("linux"):
68 import signal
69 signal.signal(signal.SIGTERM, exit_handler)
70 signal.signal(signal.SIGHUP, exit_handler)
71 signal.signal(signal.SIGQUIT, exit_handler)
72 signal.signal(signal.SIGINT, exit_handler)
73 elif sys.platform.startswith("win"):
74 import win32api
75 win32api.SetConsoleCtrlHandler(exit_handler, True)
76
77"""Implement the exit handler to shut-down the PST Tracker connection on application termination."""
78def exit_handler(*args):
79 global running
80 pst.Tracker.shutdown()
81 running = False
82 return True
83
84def main():
85 if(len(sys.argv) < 2):
86 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
87 "See the documentation of the Python bindings for more information.")
88 exit(0)
89
90
91 register_exit_handler()
92
93 try:
94
95
96 with pst.Tracker("", "","", sys.argv[1]) as tracker:
97
98 print("Running PST Server version " + tracker.get_version_info())
99
100
101 listener = MyListener()
102
103
104 tracker.add_tracker_listener(listener)
105
106
107 tracker.start()
108
109
110 print("System check: " + str(tracker.system_check()))
111
112
113 tracker.set_framerate(30)
114
115
116
117 print("Frame rate set to: " + str(tracker.get_framerate()))
118 print("***************************\n")
119
120
121 print("Current reference system transformation matrix:")
122 print_matrix(tracker.get_reference())
123
124
125
126
127
128 reference = [-1.0, 0.0, 0.0, 0.1,
129 0.0, 0.0, 1.0,-0.5,
130 0.0, 1.0, 0.0, 0.5,
131 0.0, 0.0, 0.0, 1.0]
132
133 tracker.set_reference(reference)
134 print("New reference system transformation matrix:")
135 print_matrix(tracker.get_reference())
136
137
138
139 non_orthonormal_reference = [-1.0, 1.0, 0.0, 0.1,
140 0.0, 0.0,-1.0,-0.5,
141 0.0,-1.0, 0.0, 0.5,
142 0.0, 0.0, 0.0, 1.0
143 ]
144 try:
145 tracker.set_reference(non_orthonormal_reference)
146 print("Reference input incorrectly applied!")
147 except psterrors.TrackerError as err:
148
149 print("Reference input correctly ignored: %s" % err.message)
150 print("New reference system after applying non-orthonormal transformation:")
151 print_matrix(tracker.get_reference())
152
153
154
155 relative_reference = [ 0.0,-1.0, 0.0, 0.5,
156 1.0, 0.0, 0.0, 0.4,
157 0.0, 0.0, 1.0, 0.0,
158 0.0, 0.0, 0.0, 1.0
159 ]
160 tracker.set_reference(relative_reference, True)
161 print("New reference system after applying relative transformation:")
162 print_matrix(tracker.get_reference())
163 print("***************************\n")
164
165
166
167 tracker.set_default_reference()
168 print("Reset default reference system:")
169 print_matrix(tracker.get_reference())
170
171 while running:
172 time.sleep(0.1)
173
174 except psterrors.TrackerError as err:
175
176 print(err.message)
177
178if __name__ == "__main__":
179 main()
Module containing all error related classes and functions.
Definition errors.py:1
Module containing all tracker related classes and functions.
Definition tracker.py:1