PST SDK  6.0.0.0-272350a
minimal.cpp

This example can be found in examples\cpp\minimal\minimal.cpp. 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.

When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.). On Windows, the Visual Studio project files are configured to use a relative path to the Redist directory as the working directory. If the examples have been copied, please ensure the working directory is still valid.

#include <thread>
#include <chrono>
#include "pstsdk_cpp.h"
/*
* Implementation of the PSTech::pstsdk::Listener class to receive tracking data.
* The OnTrackerData() callback function receives the data as soon as it becomes
* available and prints the tracking target pose to the command line.
*/
class MyListener : public PSTech::pstsdk::Listener
{
{
// Do something with the tracker data in td
}
} listener;
int main(int argc, char *argv[])
{
// Implement error handling of PSTech::TrackerException exceptions to prevent
// improper PST Tracker shutdown on errors.
try
{
// Create an instance of the Tracker object using the default configuration path and file names.
#ifdef WIN32
#else
// On Linux, specify the type of grabber that needs to be used as the last parameter:
// "basler_ace" for PST HD or "basler_dart" for PST Pico
PSTech::pstsdk::Tracker pst("","config.cfg","models.db",argv[1]);
#endif
// Register the listener object to the tracker server.
pst.AddTrackerListener(&listener);
// Start the tracker server.
pst.Start();
// Wait for 10 seconds, allowing for the detection of tracking targets.
std::this_thread::sleep_for(std::chrono::seconds(10));
}
{
// Do something with the error.
}
// Make sure that the connection to the PST Tracker is shut down properly.
return 0;
}
PSTech::pstsdk::Tracker
Main PST SDK class implementing tracker communication.
Definition: pstsdk_cpp.h:87
PSTech::pstsdk::TrackerData
Tracking information retrieved from tracker.
Definition: PstTypes.h:157
PSTech::pstsdk::Listener
Abstract listener class for receiving tracking information and tracking mode updates.
Definition: pstsdk_cpp.h:35
PSTech::pstsdk::Tracker::Shutdown
static void Shutdown()
Shutdown the tracking system, stopping tracking.
PSTech::pstsdk::Tracker::AddTrackerListener
void AddTrackerListener(Listener *listener)
Add a listener for receiving tracker data and tracking mode updates.
PSTech::pstsdk::Tracker::Start
void Start()
Start tracking.
pstsdk_cpp.h
PSTech::pstsdk::Listener::OnTrackerData
virtual void OnTrackerData(const TrackerData &data)
Callback function receiving tracking information from the tracker.
Definition: pstsdk_cpp.h:47
TrackerExceptions.h
PSTech::TrackerException
Definition: TrackerExceptions.h:49