Sync Interrupt sample application.
#include <windows.h>
#include "HelperFunctions.h"
using namespace RSI::RapidCode;
const int SYNC_PERIOD = (1);
const int AXIS_COUNT = (6);
const double MS_PER_SECOND = (1000.0);
void syncInterruptMain()
{
double encoderPositions[AXIS_COUNT];
short torqueOutputs[AXIS_COUNT] = { 0, 0, 0, 0, 0, 0 };
long currentCounter = 0;
long previousCounter = 0;
long deltaSamples = 0;
long iterations = 0;
unsigned long cpuFreq = 0;
double deltaTime = 0.0;
double minTime = 1000000.0;
double maxTime = 0.0;
long i = 0;
long errorCount = 0;
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
for (i = 0; i < AXIS_COUNT; i++)
{
SampleAppsCPP::HelperFunctions::CheckErrors(axes[i]);
}
printf("CPU Frequency is: %u Hz\n", cpuFreq);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
{
{
printf("\n\n Oops, we took too long processing the last interrupt. \n");
}
deltaSamples = currentCounter - previousCounter;
previousCounter = currentCounter;
deltaTime = (double)(deltaSamples * (double)(1 / (double)cpuFreq)) * MS_PER_SECOND;
if (iterations > 1)
{
if (deltaTime > maxTime)
{
maxTime = deltaTime;
}
if (deltaTime < minTime)
{
minTime = deltaTime;
}
printf("IRQ %ld: %3.3lf ms Min: %3.3lf Max: %3.3lf \n", iterations, deltaTime, minTime, maxTime);
}
for (int i = 0; i < AXIS_COUNT; i++)
{
}
for (int i = 0; i < AXIS_COUNT; i++)
{
}
iterations++;
}
}
{
printf(
"\n%s\n", err.
text);
}
printf("Press a key to exit.\n");
{
controller->OS->
Sleep(100);
}
system("pause");
}