Loading...
Searching...
No Matches
minimal.py
1"""Minimal example of the PST SDK
2
3 This is a bare minimum example showing how to connect to the PST SDK and how to
4 register a listener to receive data.
5
6 In order to be able to run this example, the PST Tracker has to be initialized first.
7 This can be done by starting the PST-Server and the PST-Client application and making
8 sure the calibration files have been downloaded and a tracking target is available.
9 The tracking target can be the default Reference target or a newly trained or imported
10 target. For more information, please see the Initialization section of the PST SDK manual
11 or check the PST Manual.
12
13 Copyright PS-Tech B.V. All Rights Reserved.
14"""
15 import context
16 import time
17 import sys
18 import pstech.pstsdk.tracker as pst
19 import pstech.pstsdk.errors as psterrors
20
21"""Implementation of the pst.Listener class to receive tracking data and mode changes."""
22 class MyListener(pst.Listener):
23
24 """Implementation of a tracker data callback function
25
26 Implementation of a tracker data callback function. The on_tracker_data
27 function receives the data as soon as it becomes available.
28
29 Args:
30 tracker_data: Object containing tracking information retrieved from tracker
31 status_message: Status message reported by the tracker.
32
33 See Also:
34 pstech.pstdk.trackerdata.TrackerData
35 pstech.pstsdk.errors.EStatusMessage
36 """
37 def on_tracker_data(self, tracker_data, status_message):
38 # Do something with the tracker data
39 pass
40
41 def main():
42 if(len(sys.argv) < 2):
43 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
44 "See the documentation of the Python bindings for more information.")
45 exit(0)
46
47 try:
48 # Use Context Manager to prevent improper Tracker shutdown on errors.
49 # Create an instance of the Tracker object using the default configuration path and file names.
50 with pst.Tracker("", "","", sys.argv[1]) as tracker:
51
52 # Create listener with callback functions for data and/or mode updates.
53 listener = MyListener()
54
55 # Register the listener object to the tracker server.
56 tracker.add_tracker_listener(listener)
57
58 # Start the tracker server.
59 tracker.start()
60
61 # Wait for 10 seconds, allowing for the detection of tracking targets.
62 time.sleep(10)
63 except psterrors.TrackerError as err:
64 # Catch TrackerError and print error messages.
65 print(err.message)
66
67 if __name__ == "__main__":
68 main()
pstech.pstsdk.errors
Module containing all error related classes and functions.
Definition errors.py:1
pstech.pstsdk.tracker
Module containing all tracker related classes and functions.
Definition tracker.py:1