Loading...
Searching...
No Matches
exposure.cs

This example can be found in `examples\csharp\exposure\exposure.cs`. 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 adjust exposure settings using the PST SDK. It shows how to change exposure settings based on frame rate and the available exposure range for a certain PST Tracker at a certain frame rate.

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.).

// Copyright PS-Tech B.V. All Rights Reserved.
using System;
using System.Runtime.InteropServices;
using System.Threading;
using PSTech.Pstsdk;
namespace PsTech.Exposure
{
public class Exposure
{
//Registering control handler function.
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
private delegate bool ConsoleEventHandler(CtrlType sig);
static ConsoleEventHandler ConsoleCtrlEventHandler;
public enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogOffEvent = 5,
CtrlShutdownEvent = 6,
}
private static bool ConsoleHandler(CtrlType sig)
{
Exithandler((int)sig);
return true;
}
// Control variable for main loop.
static bool Running = true;
// Number of data points to grab before application termination.
static int NumberOfSamplesToGrab = 1000;
static int SamplesGrabbed = 0;
class MyTrackerListener : TrackerListener
{
public override void OnTrackerData(TrackerData data, ErrorStatus status)
{
if (SamplesGrabbed++ >= NumberOfSamplesToGrab)
{
Running = false;
}
// Do something with the received data.
}
}
static void Exithandler(int sig)
{
Tracker.Shutdown(); // Cleans up native resources only; does NOT remove listeners
Running = false;
}
static int Main(string[] args)
{
// Register the exit handler with the application
ConsoleCtrlEventHandler += new ConsoleEventHandler(ConsoleHandler);
SetConsoleCtrlHandler(ConsoleCtrlEventHandler, true);
// 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.
// Wrap the Tracker in a using statement to ensure Dispose() is called automatically
using (Tracker tracker = new Tracker())
{
// Print version number of the tracker server being used.
Console.Write("Running PST Server version " + tracker.GetVersionInfo() + "\n");
//Create tracker listener with callback functions for data and/or mode updates.
TrackerListener listener = new MyTrackerListener();
// Register the TrackerListener object to the tracker server.
tracker.AddTrackerListener(listener);
// Start the tracker server.
tracker.StartTracker();
// Perform a system check to see if the tracker server is running OK and print the result.
Console.Write("System check: " + tracker.Systemcheck() + "\n\n");
Console.Write("***************************\n\n");
// Set the frame rate to 30 Hz.
tracker.SetFramerate(30);
// Print the new frame rate to see if it was set correctly. Note that for PST HD and Pico
// trackers the frame rate actually being set can differ from the value provided to SetFramerate().
Console.Write("Frame rate set to " + tracker.GetFramerate() + " Hz\n");
// Query available exposure range for the current frame rate and try setting the maximum exposure value
double min = 0.0, max = 0.0;
tracker.GetExposureRange(ref min, ref max);
Console.Write("Exposure range: " + min + " s - " + max + " s\n");
Console.Write("Set exposure to " + max + "\n");
tracker.SetExposure(max);
Console.Write("Check new exposure: " + tracker.GetExposure() + " s\n\n");
Console.Write("***************************\n\n");
// Increase frame rate and check exposure value. For PST HD and PST Pico trackers, maximum exposure
// depends on frame rate. Exposure will be automatically decreased when necessary.
Console.Write("Set frame rate to 60 Hz\n");
tracker.SetFramerate(60);
Console.Write("Frame rate set to " + tracker.GetFramerate() + " Hz\n");
Console.Write("Check exposure: " + tracker.GetExposure() + " s\n");
// Check new exposure range
tracker.GetExposureRange(ref min, ref max);
Console.Write("New exposure range " + min + " s - " + max + " s\n\n");
Console.Write("***************************\n\n");
// Set exposure half-way
double exposureHalf = min + (max - min) / 2.0;
Console.Write("Set exposure half way: " + exposureHalf + " s\n");
tracker.SetExposure(exposureHalf);
Console.Write("New exposure: " + tracker.GetExposure() + " s\n\n");
Console.Write("***************************\n\n");
// Main loop, wait for auto-termination.
while (Running)
{
Thread.Sleep(100);
}
}
}
catch (Exception e)
{
// Catch PSTech.TrackerException exceptions and print error messages.
Console.Write(e + "\n");
}
// Pause command line to see results.
Console.Write("Press enter to continue...\n");
Console.Read();
return 0;
}
}
}
PSTech.Pstsdk.TrackerData
Tracking information retrieved from tracker.
Definition TrackerData.cs:25
PSTech.Pstsdk.Tracker.GetFramerate
double GetFramerate()
Get current frame rate.
Definition Tracker.cs:589
PSTech.Pstsdk.Tracker.StartTracker
void StartTracker()
Start tracking.
Definition Tracker.cs:524
PSTech.Pstsdk.Tracker.Systemcheck
StatusMessage Systemcheck()
Check if the tracker is running correctly.
Definition Tracker.cs:568
PSTech.Pstsdk.Tracker.AddTrackerListener
void AddTrackerListener(TrackerListener listener)
Add a listener for tracker data and/or mode change reporting.
Definition Tracker.cs:476
PSTech.Pstsdk.Tracker.GetExposure
double GetExposure()
Get the current exposure time.
Definition Tracker.cs:642
PSTech.Pstsdk.Tracker.SetExposure
void SetExposure(double exposure)
Set the exposure time.
Definition Tracker.cs:633
PSTech.Pstsdk.Tracker.GetExposureRange
void GetExposureRange(ref double min, ref double max)
Get the allowed exposure range.
Definition Tracker.cs:661
PSTech.Pstsdk.Tracker.SetFramerate
void SetFramerate(double fps)
Set tracker frame rate.
Definition Tracker.cs:579
PSTech.Pstsdk.Tracker.GetVersionInfo
string GetVersionInfo()
Get version information of the SDK.
Definition Tracker.cs:400
PSTech.Pstsdk.TrackerListener
Implements the TrackerListener class to receive tracking information and tracking mode updates.
Definition Tracker.cs:166
PSTech.Pstsdk
Definition CApi.cs:9
PSTech.Pstsdk.ErrorStatus
ErrorStatus
Tracker error messages enum class.
Definition ErrorHandler.cs:17