PST SDK  5.0.1.0-acae3ae
minimal.cpp

This example can be found in Development\minimal\minimal.cpp.

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.

#include <thread>
#include <memory>
#include "pst-sdk.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;
/*
* Create a shared pointer for storing the PSTech::pstsdk::Tracker object instance.
* By making use of a shared pointer, proper destruction of the PST Tracker connection
* is ensured in case the application is shut down.
*/
std::shared_ptr<PSTech::pstsdk::Tracker> pst;
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.
pst = std::make_shared<PSTech::pstsdk::Tracker>();
// 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.
pst->Shutdown();
return 0;
}