This example shows how to use the PST SDK to adjust the PST Tracker reference system. The reference system defines the Cartesian coordinate system in which tracking results are reported. The example shows how to set the reference system by supplying a 4x4 homogeneous transformation matrix. It also shows how to check if the reference system was set successfully.
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 const uint32_t numberOfSamplesToGrab = 1000;
{
virtual void OnTrackerData(
const PSTech::pstsdk::TrackerData& td)
override
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
}
public:
virtual ~MyListener() override
{
}
} 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 <<
"Running PST Server version " << pst.
GetVersionInfo() <<
"\n";
std::cout <<
"System check: " << (int)pst.
Systemcheck() <<
"\n";
std::cout <<
"Frame rate set to " << pst.
GetFramerate() <<
"\n\n";
std::cout << "*******************\n\n";
std::cout << "Current reference system transformation matrix:\n";
std::cout << "\n\n*******************\n\n";
0.0f, 0.0f, 1.0f, -0.5f,
0.0f, 1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
std::cout << "New reference system transformation matrix:\n";
std::cout << "Reference not set correctly!\n";
else
std::cout << "Reference set correctly!\n";
std::cout << "\n\n*******************\n\n";
0.0f, 0.0f, -1.0f, -0.5f,
0.0f, -1.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f };
try
{
std::cout << "Reference input incorrectly applied!\n";
}
{
std::cout <<
"Reference input correctly ignored: " << e.
what() <<
"\n";
}
std::cout << "New reference system after applying non-orthonormal transformation:\n";
std::cout << "\n\n*******************\n\n";
1.0f, 0.0f, 0.0f, 0.4f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
std::cout << "New reference system after applying relative transformation:\n";
std::cout << "\n\n*******************\n\n";
std::cout << "Reset default reference system:\n";
while (running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
{
}
std::cout << "Press enter to continue...\n";
std::cin.get();
return 0;
}
virtual const char * what() const
virtual const char * full_description() const
Definition TrackerExceptions.h:54
Abstract listener class for receiving tracking information and tracking mode updates.
Definition pstsdk_cpp.h:38
virtual void OnTrackerData(const TrackerData &data)
Callback function receiving tracking information from the tracker.
Definition pstsdk_cpp.h:49
Main PST SDK class implementing tracker communication.
Definition pstsdk_cpp.h:101
void Start()
Start tracking.
Utils::PstString GetVersionInfo() const
Get version information of the SDK.
StatusMessage Systemcheck() const
Check if the tracker is running correctly.
static void Shutdown()
Shutdown the tracking system, stopping tracking.
double GetFramerate() const
Get current frame rate.
Utils::PstArray< float, 16 > GetReference() const
Gets the transformation matrix for the current reference system.
void SetDefaultReference()
Reset the reference system to the default reference system.
static void AddTrackerListener(Listener *listener)
Add a listener for receiving tracker data and tracking mode updates.
static void RemoveTrackerListener(Listener *listener)
Remove a listener for receiving tracker data and tracking mode updates.
void SetReference(const Utils::PstArray< float, 16 > &reference, bool relative=false)
Set the reference system in which tracking results are reported.
void SetFramerate(double fps)
Set tracker frame rate.