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.).
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <signal.h>
static inline void PrintMatrix(const float mat[16])
{
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
printf("%f \t", mat[x + y * 4]);
}
printf("\n");
}
}
static sig_atomic_t running = 1;
static sig_atomic_t restart = 0;
static const uint32_t numberOfSamplesToGrab = 100;
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
{
running = 0;
}
{
PrintMatrix(mat);
}
}
{
switch (mode)
{
printf("Tracker tracking\n");
break;
printf("Tracker paused\n");
break;
printf("Tracker disconnected\n");
break;
printf("Tracker reconnected\n");
restart = 1;
break;
default:
printf("Mode: %d\n", (int)mode);
break;
}
}
static void Exithandler(int sig)
{
running = 0;
}
void PrintLastErrorMessage()
{
char* last_error_message = NULL;
{
last_error_message = "Failed to allocate memory error.";
}
printf("last error message: %s \n", last_error_message);
}
{
{
PrintLastErrorMessage();
exit(status);
}
}
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
#ifdef WIN32
#else
CheckErrorCode(
pst_tracker_init4(&ctracker,
"",
"config.cfg",
"models.db", argv[1]));
#endif
{
printf("\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");
printf("Press enter to continue...\n");
getchar();
return 1;
}
char* version_string;
printf("Running PST Server version %s \n", version_string);
printf("Put the Reference card in front of the PST in order to see tracking results.\n\n");
double fps;
printf("Frame rate set to %f \n", fps);
while (running == 1)
{
if (restart == 1)
{
restart = false;
}
#ifdef WIN32
Sleep(100);
#else
usleep(100000);
#endif
}
return 0;
}
EPstErrorStatus pst_tracker_get_framerate(const PstTracker *ctracker, double *fps)
Get current frame rate.
EPstErrorStatus pst_tracker_init(PstTracker *ctracker)
This function initializes the tracker object.
EPstErrorStatus pst_alloc_and_get_last_error_message(char **cstring)
This function returns the last error message that was recorded by the system.
EPstErrorStatus pst_tracker_init4(PstTracker *ctracker, const char path[], const char config_file[], const char db_file[], const char grabber_name[])
This function initializes the tracker object.
void pst_tracker_destroy(PstTracker *ctracker)
void pst_sdk_shutdown()
Shutdown the tracking system, stopping tracking.
EPstErrorStatus pst_tracker_remove_tracker_callbacks(PstTracker *ctracker, void(*on_tracker_data)(const PstTrackerData *, EPstErrorStatus), void(*on_tracker_mode)(EPstTrackerMode))
Remove callback functions for tracker data and mode changes.
EPstErrorStatus pst_tracker_alloc_and_get_version_info(const PstTracker *ctracker, char **version_string)
Get version information of the SDK.
void pst_free(void *data)
Free data allocated by the PST SDK.
EPstErrorStatus pst_tracker_start(PstTracker *ctracker)
Start tracking.
EPstTrackerMode
Tracker mode enum class.
Definition pstsdk_c.h:95
EPstErrorStatus pst_tracker_set_framerate(PstTracker *ctracker, double fps)
Set tracker frame rate.
void pst_camera_urls_init(PstCameraURLs *urls)
void pst_camera_urls_destroy(PstCameraURLs *urls)
EPstStatusMessage pst_tracker_system_check(const PstTracker *ctracker)
Check if the tracker is running correctly.
EPstErrorStatus pst_tracker_add_tracker_callbacks(PstTracker *ctracker, void(*on_tracker_data)(const PstTrackerData *, EPstErrorStatus), void(*on_tracker_mode)(EPstTrackerMode))
Add callback functions for tracker data and mode changes.
EPstErrorStatus
Tracker error messages enum class.
Definition pstsdk_c.h:44
EPstErrorStatus pst_tracker_get_uncalibrated_camera_urls(const PstTracker *ctracker, bool silent, PstCameraURLs *urls)
Check if cameras of the connected PST Tracker are calibrated.
@ PST_MODE_LOWPOWER
Definition pstsdk_c.h:96
@ PST_MODE_DISCONNECT
Definition pstsdk_c.h:100
@ PST_MODE_TRACKING
Definition pstsdk_c.h:98
@ PST_MODE_RECONNECT
Definition pstsdk_c.h:101
@ PST_ERROR_STATUS_OK
Definition pstsdk_c.h:45
Struct to request urls for calibration information.
Definition pstsdk_c.h:277
size_t number_of_urls
Definition pstsdk_c.h:279
char name[128]
Definition pstsdk_c.h:134
float pose_matrix[16]
Definition pstsdk_c.h:201
PstTarget target
Definition pstsdk_c.h:200
Tracking information retrieved from tracker.
Definition pstsdk_c.h:248
size_t number_of_targets
Definition pstsdk_c.h:251
PstTargetPose * targetlist
Definition pstsdk_c.h:253
Main PST SDK struct for tracker communication.
Definition pstsdk_c.h:264