This example can be found in examples\cpp\listener\listener.cpp
. When the PST SDK has been installed through the PST Software Suite installer the examples can be found in the Development folder.
This example shows how to implement the PST SDK using the PSTech::pstsdk::Tracker class and how to receive data and tracker mode changes by implementing the PSTech::pstsdk::Listener class. The example initializes the PST Tracker and grabs 100 datapoints.
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 applications 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 or check the PST Manual.
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.
#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
{
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
std::cout << mat[x + y * 4] << "\t";
}
std::cout << "\n";
}
}
static std::atomic<bool> running(true);
static std::atomic<bool> restart(false);
static const uint32_t numberOfSamplesToGrab = 100;
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
{
std::cout <<
"Pose for " << td.
targetlist[d].name <<
"\n";
PrintMatrix(mat);
}
}
{
switch(mode)
{
std::cout << "Tracker tracking" << std::endl;
break;
std::cout << "Tracker paused" << std::endl;
break;
std::cout << "Tracker disconnected" << std::endl;
break;
std::cout << "Tracker reconnected" << std::endl;
restart = true;
break;
default:
std::cout << "Mode " << static_cast<int>(mode) << std::endl;
break;
}
}
} listener;
static void Exithandler(int sig)
{
running = false;
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
try
{
#ifdef WIN32
#else
#endif
{
std::cout << "\nNo calibration information could be found in the configuration directory. "
"Please use the PST Server and PST Client application to initialize the PST Tracker and create/import a tracking target. "
"More information can be found in the Initialization section of the PST SDK manual and the PST Manual.\n\n";
std::cout << "Press enter to continue...\n";
std::cin.get();
return 1;
}
std::cout <<
"Running PST Server version " << pst.
GetVersionInfo() <<
"\n";
std::cout << "Put the Reference card in front of the PST in order to see tracking results.\n\n";
std::cout <<
"System check: " << (int)pst.
Systemcheck() <<
"\n";
std::cout <<
"Frame rate set to " << pst.
GetFramerate() <<
"\n";
while (running)
{
if(restart)
{
restart = false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
{
std::cout << "Press enter to continue...\n";
std::cin.get();
}
return 0;
}