PST SDK  5.1.0.0-e242fa9
trackingtarget.cpp
#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
/*
* Define handler functions required to ensure a clean shutdown of the PST Tracker when the
* application is terminated.
*/
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
/* End of handler functions */
#include <memory>
#include <iostream>
#include <thread>
#include <chrono>
#include "pst-sdk.h"
/* Control variable for main loop */
static bool running = true;
/* Number of data points to grab before application termination */
static const uint32_t numberOfSamplesToGrab = 100;
/*
* 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 name to the command line.
*/
class MyListener : public PSTech::pstsdk::Listener
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
std::cout << "Detected " << pose.name << "\n";
}
} 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;
/*
* Implement the exit handler to shut-down the PST Tracker connection on application termination.
*/
static void Exithandler(int sig)
{
pst->Shutdown();
running = false;
}
int main(int argc, char *argv[])
{
// Register the exit handler with the application
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
// 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
pst = std::make_shared<PSTech::pstsdk::Tracker>();
#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
pst = std::make_shared<PSTech::pstsdk::Tracker>("","config.cfg","models.db",argv[1]);
#endif
// Print version number of the tracker server being used.
std::cout << "Running PST Server version " << pst->GetVersionInfo() << "\n";
// Register the listener object to the tracker server.
pst->AddTrackerListener(&listener);
std::cout << "Put the Reference card in front of the PST in order to see tracking results.\n\n";
// Start the tracker server.
pst->Start();
// Perform a system check to see if the tracker server is running OK and print the result.
std::cout << "System check: " << (int)pst->Systemcheck() << "\n";
// Retrieve the list of registered tracking targets and print their names and current status (active or not).
std::cout << "Found " << targets.size() << " tracking targets:\n";
for (PSTech::pstsdk::TargetStatus& t : targets)
std::cout << t.name << "\t" << t.status << "\n";
std::cout << "\n";
// Enable the Reference target. Note that this will cause a PSTech::TrackerException in case the Reference
// target has not been created. The Reference target can be created using the PST Client.
pst->SetTargetStatus("Reference", true);
// Get the 3D marker positions making up the Reference device and display them.
// Note that this will cause a PSTech::TrackerException in case the Reference target has not been created.
PSTech::pstsdk::MarkerList markers = pst->GetTargetMarkers("Reference");
std::cout << "3D marker positions making up the Reference target:\n";
for (auto& marker : markers)
std::cout << "x: " << marker[0] << "\t" << "y: " << marker[1] << "\t" << "z: " << marker[2] << "\n";
std::cout << "\n";
// Main loop, wait for auto-termination.
while (running)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
{
// Catch PSTech::TrackerException exceptions and print error messages.
std::cout << e.full_description() << "\n";
}
// Make sure that the connection to the PST Tracker is shut down properly.
pst->Shutdown();
// Pause command line to see results.
std::cout << "Press enter to continue...\n";
std::cin.get();
return 0;
}
PSTech::pstsdk::TargetStatus
Tracking target status.
Definition: pst-sdk.h:118
PSTech::pstsdk::Listener::OnTrackerData
virtual void OnTrackerData(TrackerData &data)
Callback function receiving tracking information from the tracker.
Definition: pst-sdk.h:232
PSTech::pstsdk::Tracker::GetTargetMarkers
MarkerList GetTargetMarkers(const std::string &name) const
Get 3D marker positions of stored tracking Target.
PSTech::pstsdk::TargetPose
Estimated tracking target pose.
Definition: pst-sdk.h:143
PSTech::pstsdk::Tracker::GetTargetList
TargetStatuses GetTargetList() const
Get TargetStatuses object containing all tracking targets and their status.
PSTech::pstsdk::TrackerData
Tracking information retrieved from tracker.
Definition: pst-sdk.h:203
PSTech::pstsdk::MarkerList
std::vector< std::array< float, 3 > > MarkerList
Vector of 3D marker positions of a tracking Target.
Definition: pst-sdk.h:190
PSTech::pstsdk::Listener
Abstract listener class for receiving tracking information.
Definition: pst-sdk.h:220
pst-sdk.h
PSTech::pstsdk::TrackerData::targetlist
TargetPoses targetlist
Definition: pst-sdk.h:207
PSTech::pstsdk::Tracker::AddTrackerListener
void AddTrackerListener(Listener *listener)
Add a listener for tracker data.
PSTech::pstsdk::TargetStatuses
std::vector< TargetStatus > TargetStatuses
Vector of TargetStatus objects.
Definition: pst-sdk.h:130
PSTech::pstsdk::Tracker::Systemcheck
StatusMessage Systemcheck() const
Check if the tracker is running correctly.
PSTech::pstsdk::Tracker::Start
void Start()
Start tracking.
PSTech::pstsdk::Tracker::SetTargetStatus
void SetTargetStatus(const std::string &name, bool active)
Set status of a single tracking Target.
TrackerExceptions.h
PSTech::pstsdk::Tracker::Shutdown
void Shutdown()
Shutdown the tracking system, stopping tracking.
PSTech::TrackerException::full_description
virtual std::string full_description() const
PSTech::pstsdk::Tracker::GetVersionInfo
std::string GetVersionInfo() const
Get version information of the SDK.
PSTech::pstsdk::Target::name
std::string name
Definition: pst-sdk.h:92
PSTech::TrackerException
Generic tracker exception.
Definition: TrackerExceptions.h:30