PST SDK 7.0.0.0-ebe6e713
Loading...
Searching...
No Matches
Using PST SDK

The PST SDK can be used to receive tracking results and images from a PST Tracker. Implementing the SDK is done by creating an instance of the PSTech.Pstsdk.Tracker class. This class provides access to settings on the PST Tracker and enables its user to receive tracking data.

Setup

In order to start working with the PST SDK, create a Visual Studio (2015 or newer) project using any .NET implementation (e.g. .NET Core, .NET Framework) that supports .NET Standard 2.0 and add the PST-SDK C# assembly as a dependency. In order to run an application that is linked to the PST SDK, copy the required files from the Redist directory to the location of the application. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder. Please note that, while the PST SDK C# assembly is an AnyCPU assembly, the installation type of the PST Software Suite (x64 or x86) should still match your application type in order to have access to the right dependencies.

In order to use the PST SDK in an application, use the PSTech.Pstsdk namespace in your project. To handle exceptions use the PSTech.TrackerException class. The application is dynamically linked to PSTech.Pstsdk.dll binary file which can be found in the Assemblies\netstandard2.0 directory, when the PST SDK has been installed through the PST Software Suite installer the Assemblies folder can be found in the Development folder. Add PSTech.Pstsdk.dll as dependency to your application. In order to run the application, copy all other required binary dependencies from the Redist directory to the location of the application. A list of files to use for specific use-cases can be found in the Redistribution section of the PST SDK overview.

Initialization

Before using the PST Tracker for object tracking, it must be initialized with calibration and tracking target information. This information can be provided through the PST SDK directly, or using several alternative methods.

Calibration

Each time a PST Tracker is connected to a new computer, tracker calibration information needs to be provided. When the PSTech.Pstsdk.Tracker object is initialized it checks whether or not calibration information can be found in the specified configuration directory. If no calibration information can be found, a message specifying the download locations of the required files will be printed on the command line. It is also possible to call PSTech.Pstsdk.Tracker.GetUncalibratedCameraUrls() or PSTech.Pstsdk.Tracker.GetConnectedCameraInfo() to receive a vector of download URLs.

Note
PSTech::Pstsdk::Tracker::GetConnectedCameraUrls() is deprecated and maintained only for backward compatibility. It will be removed in a future release. Users are strongly encouraged to use PSTech.Pstsdk.Tracker.GetConnectedCameraInfo() instead.

A single PST Tracker requires two calibration files. The download URL of these files takes the following form: http://www.ps-tech.com/pstsw/calibrations/iris_####.cam, where #### is the identification number of each camera. After downloading the calibration files and making them available on the local system, they can be uploaded to the configuration directory and loaded into the system using PSTech.Pstsdk.Tracker.LoadCalibrationFromLocalPath(). When the PST Tracker that is going to be used is known on forehand, tracker calibration files can be provided by copying the right files from any medium into the configuration directory manually.

Calibration File Verification

Warning
In Multi-PST setups, the SHA1 hashes of the local and server calibration files may differ even when the local files are up to date.
During the registration process, the system calculates the position and orientation of all PST units relative to each other, updating the local calibration files.
These modifications cause the local file checksums to differ from the original versions on the PS-tech server.

The PST SDK provides a convenient way to verify whether local calibration files are up to date. By calling PSTech.Pstsdk.Tracker.GetConnectedCameraInfo(), users can access verification data for each connected camera, including the local SHA1 values and the URLs to retrieve the corresponding server SHA1 values. Users can then compare the local SHA1 with the server SHA1 obtained from provided URLs to confirm that the local calibration files are synchronized with the latest version on the PS-tech server.

Note
Internet access is required to retrieve the SHA1 checksums from the server. Without a connection, only the local file checksums can be obtained, and comparison with the files on the PS-tech server cannot be performed.

This verification mechanism helps ensure that calibration files are valid and up to date, preventing issues caused by outdated, missing, or unreadable calibration data. If mismatches are detected between local and server files, users can download the latest calibration files directly from the provided download URLs.

Tracking Target Setup

A new installation of the PST software will not contain any tracking targets. In order to start tracking, tracking targets need to be added to the model database. When a tracking target model definition is available in the JSON format described in Appendix A of the PST Manual, it can be added to the model database using PSTech.Pstsdk.Tracker.ImportJSONModel(). This function takes a JSON-formatted string describing the target model. After calling this function, the model will be available for tracking.

There are also a number of alternative ways to get tracking target models into the model database.

  1. Copy an existing tracking target model database (models.db) into the configuration directory.
  2. Train a new tracking target model using the 'New device model' tab in the PST-Client.
  3. Import an existing tracking target model (JSON or PSM formatted) using the 'Edit device model' tab in the PST-Client.

When tracking target models are added using the PST-Client, a shared memory pipeline needs to be available to connect the PST-Client to the PST Tracker. Shared memory access can be enabled using the C# API by calling PSTech.Pstsdk.Tracker.EnableSharedMemory(). Implementing this function allows the PST-Client to directly connect to an application. This way, tracking target model data will directly be saved to the model database file set in the application.

Alternatively, the PST-Server application can be started to allow the PST-Client to connect to the PST Tracker.

Note
On Windows, an application that implements shared memory access must be run with administrator privileges.
The PST Interface Service will not be available when the PST SDK has been installed.
The PST-Server and the application implementing the PST SDK can not be active at the same time, since only one application can connect to the PST Tracker at any given time.

The PST-Server will store its model database at C:\ProgramData\PS-Tech\PST Iris\models.db. The application implementing the PST SDK can either use the same configuration directory and model database file, or the model database file can be copied to the configuration directory used by the application.

Usage

A clear example of how to use the PST SDK can be found in the Examples section of this documentation. The first step of connecting to the PST Tracker is creating an instance of the PSTech.Pstsdk.Tracker object. When the PSTech.Pstsdk.Tracker object is no longer needed, make sure it is shut down properly using PSTech.Pstsdk.Tracker.Shutdown() in order to safely disconnect from the PST Tracker. More on this topic will be discussed in the section Safe Tracker Termination.

Receiving tracker data

Tracking data can be received by registering to the Listener using PSTech.Pstsdk.Tracker.AddTrackerListener(). After enabling the required tracking targets using PSTech.Pstsdk.Tracker.SetTargetStatus() and calling PSTech.Pstsdk.Tracker.StartTracker(), the PSTech.Pstsdk.Tracker.OnTrackerDataCallback callback function will start receiving tracking data in the form of a PSTech.Pstsdk.TrackerData object. These objects contain the time stamp of the recorded data, a recording id, a list of all detected 3D points that could not be matched to any of the activated tracking targets and a list of detected tracking targets and their poses.

While tracking is in progress, settings like the frame rate and exposure can be adjusted using their corresponding functions. It is also possible to change which tracking targets are active.

Attention
Registered listeners should be explicitly removed using PSTech.Pstsdk.Tracker.RemoveTrackerListener() once they are no longer needed. Callbacks from all listeners are executed synchronously, so leaving listeners registered can slow down or block other listeners and may interfere with subsequent tracking sessions. Properly removing listeners ensures that tracking data is processed efficiently and avoids unexpected behavior in your application. If listeners are not removed explicitly, they are removed automatically when the owning PSTech.Pstsdk.Tracker instance is disposed. Therefore, Tracker instances must always be disposed deterministically, for example by using the C# using statement or a try/finally construct.
Note
When building an application based on the PST SDK, make sure to add the PST SDK C# assembly in the Assemblies\netstandard2.0 folder as a dependency to your application and make sure that all dependencies are copied from the Redist directory to the binary directory of the application. When the PST SDK has been installed through the PST Software Suite installer the Assemblies and Redist folders can be found in the Development folder.

Detection regions

On selected PST Trackers it is possible to specify a Detection Region. Using PSTech.Pstsdk.Tracker.SupportsDetectionRegionPruning() it can be determined if the currently connected PST Tracker supports Detection Regions.

The Detection Region can be set to OPTIMAL or FULL using PSTech.Pstsdk.Tracker.SetMarkerDetectionRegion(). Setting the Detection Region to OPTIMAL limits tracking target detection and tracking to a well-characterized working space with higher accuracy. When the Detection Region is set to FULL, tracking is performed in the full PST Tracker field of view, including areas that have not been fully characterized. On supported PST Trackers, the Detection Region will be set to OPTIMAL by default on startup unless changed.

Each detected PSTech.Pstsdk.Point has an associated PSTech.Pstsdk.TrackingRegion which specifies in which Detection Region the marker was found. For each detected tracking target, the PSTech.Pstsdk.TargetPose.MatchedPoints list specifies for each of the markers matched to the tracking target in which Detection Region it was detected. When the Detection Region is set to OPTIMAL, markers outside the OPTIMAL Detection Region will not be used to compute the pose of a tracking target.

Filtering

Settings controlling the amount of filtering that is applied to the tracking data can be adjusted at all times. The filtering strength for the position and orientation can be adjusted independently using PSTech.Pstsdk.Tracker.SetPositionFilter() and PSTech.Pstsdk.Tracker.SetOrientationFilter() respectively. Filtering using the DESP filter is enabled by default while the tremor filter is disabled by default. When data filtering is part of the end-user application it is recommended to disable PST SDK filtering using PSTech.Pstsdk.Tracker.DisableFiltering() to prevent double filtering and over smoothing the data.

Note
When shared memory is used to connect the PST-Client to the PST SDK, all filtering on the side of the PST SDK will be disabled since the PST-Client performs its own filtering. After closing the PST-Client, filtering should be re-enabled manually by calling PSTech.Pstsdk.Tracker.EnableFiltering() and PSTech.Pstsdk.Tracker.EnableTremorFilter().

Camera Images

It is possible to retrieve image data from the cameras inside the PST Tracker. In order to do so, image transfer has to be enabled on the PST Tracker by calling PSTech.Pstsdk.Tracker.EnableImageTransfer().

When image transfer has been enabled, images can be requested by calling PSTech.Pstsdk.Tracker.GetImage(). Images are provided as a PSTech.Pstsdk.Image object containing the width and height of the images in pixels and a vector containing pointers to the first pixel of the left and right camera image. Images are gray scale and provided as a IntPtr array without memory alignment.

In order to keep receiving images, a call to PSTech.Pstsdk.Tracker.GetImage() has to be made at least every 4 seconds. For performance reasons, image transfer will be automatically disabled after no images have been requested for 4 seconds.

Note
Enabling image transfer when using a standard PST Iris or PST Base will reduce the PST Tracker's frame rate to 30 Hz for as long as images are being requested. When image transfer is disabled, either automatically or manually by calling PSTech.Pstsdk.Tracker.DisableImageTransfer(), the frame rate of the PST Tracker will be reset to its original value.

Reference System

Tracking results are reported relative to a predefined right-handed Cartesian coordinate system, called the reference system. The default reference system is located at 1 meter from the PST Tracker. It is oriented such that the Z-axis points away from the PST tracker and the X-axis is parallel to the PST tracker. The reference system can be changed by the user and is stored as a transformation matrix in a file called otracker.ref located in the configuration directory. Setting the reference system can be done in several ways.

  1. Use the PSTech.Pstsdk.Tracker.SetReference() function to supply a relative or absolute reference system.
  2. Use the pose of a tracking target on the 'Reference System' tab in the PST-Client.
  3. Enter a relative or absolute reference system transformation on the 'Reference System' tab in the PST-Client.
  4. Copy an existing otracker.ref reference system file into the configuration directory.

The PST-Client can be used to set the reference system according to the methods described in section Tracking Target Setup.

Safe Tracker Termination

The PST Tracking systems are sensitive hardware. Therefore, it is important that the PST Tracker is correctly terminated every time an application connecting to the PST Tracker is closed. Improper termination may result in unpredictable behavior or interfere with other trackers.

In C#, the recommended way to terminate a Tracker safely is to dispose the Tracker instance deterministically. This can be done by:

  1. Calling PSTech.Pstsdk.Tracker.Dispose() explicitly.
  2. Wrapping the Tracker in a C# using statement.
  3. Using a try/finally block and calling Dispose() in the finally section.

Disposing the Tracker:

  1. Disconnects from the native tracker safely.
  2. Removes all registered listeners automatically.
  3. Ensures callbacks from slow or unremoved listeners do not affect other trackers.

Registered listeners can also be removed explicitly using PSTech.Pstsdk.Tracker.RemoveTrackerListener() if desired. However, if they are not removed manually, Dispose() guarantees they are cleaned up.

Relying on the finalizer or the garbage collector for cleanup is not recommended, because the garbage collector runs non-deterministically and may not clean up Tracker instances in time to safely remove listeners or disconnect from the native tracker.

Exceptions thrown by PST SDK functions (for example, PSTech.TrackerException) should be caught using try/catch blocks. When the Tracker is disposed using using or try/finally, cleanup occurs even when exceptions happen.

For abnormal termination scenarios, such as the console being closed or the application receiving Ctrl-C, a console exit handler can be implemented using the Windows API function SetConsoleCtrlHandler(). The exit handler can signal the main program to stop and call PSTech.Pstsdk.Tracker.Shutdown() to release native resources. Shutdown only cleans up native resources and does not remove registered listeners; it is not a substitute for Dispose().

Taking the above mentioned precautions should take care of most cases where disconnecting from the PST Tracker can result in unwanted behavior.