This example can be found in examples\python\minimal.py
. When the PST SDK has been installed through the PST Software Suite installer the examples can be found in the Development folder.
This is a bare minimum example showing how to connect to the PST SDK and how to register a listener to receive data.
Note that for simplicity reasons, this example does not take the recommended safety precautions to shut down the PST Tracker when the application shuts down. In an actual implementation, please follow the safety precautions recommended in the Safe Tracker Termination section of the Using PST SDK page of the manual. Examples of how to implement the safety precautions can be found in the other examples.
"""Minimal example of the PST SDK
This is a bare minimum example showing how to connect to the PST SDK and how to
register a listener to receive data.
In order to be able to run this example, the PST Tracker has to be initialized first.
This can be done by starting the PST-Server and the PST-Client application and making
sure the calibration files have been downloaded and a tracking target is available.
The tracking target can be the default Reference target or a newly trained or imported
target. For more information, please see the Initialization section of the PST SDK manual
or check the PST Manual.
Copyright PS-Tech B.V. All Rights Reserved.
"""
import context
import time
import sys
"""Implementation of the pst.Listener class to receive tracking data and mode changes."""
class MyListener(pst.Listener):
"""Implementation of a tracker data callback function
Implementation of a tracker data callback function. The on_tracker_data
function receives the data as soon as it becomes available.
Args:
tracker_data: Object containing tracking information retrieved from tracker
status_message: Status message reported by the tracker.
See Also:
pstech.pstdk.trackerdata.TrackerData
pstech.pstsdk.errors.EStatusMessage
"""
def on_tracker_data(self, tracker_data, status_message):
pass
def main():
if(len(sys.argv) < 2):
print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
"See the documentation of the Python bindings for more information.")
exit(0)
try:
with pst.Tracker("", "","", sys.argv[1]) as tracker:
listener = MyListener()
tracker.add_tracker_listener(listener)
tracker.start()
time.sleep(10)
except psterrors.TrackerError as err:
print(err.message)
if __name__ == "__main__":
main()