Update Buffer Points sample application.
This application is designed to assist in managing the buffer in streaming motion. The behavior of continuing streaming motion (with the parameter final=false) will increment the MotionID (retrieved by calling MotionIdExecutingGet()). It will also reset the motion element ID to 0 (retrieved with MotionElementIdExecutingGet()).
The number sent points needs to be managed, somehow. This sample does so by using a fixed buffer size and keeping at least one buffer associated with a Motion ID queued. This should be changed as appropiate.
#include <cassert>
#include "rsi.h"
using namespace RSI::RapidCode;
{
{
printf(
"%s\n", err->
text);
}
if (hasError)
{
exit(1);
}
}
{
char *err;
{
printf("%s\n", err);
}
if (hasError)
{
exit(1);
}
}
void updateBufferPointsMain()
{
const double TIME_SLICE = 0.001;
const int AXIS_COUNT = 1;
const int REVS = 5;
const int RPS = 1;
const int CPS = (int)std::powl(2, 20);
const int TOTAL_POINTS = (int)(REVS / TIME_SLICE / RPS);
const int BUFFER_SZ = 100;
const int EMPTY_CT = 10;
PrintUpdateBufferErrors(controller);
try {
PrintUpdateBufferNetworkErrors(controller);
PrintUpdateBufferErrors(multiAxis);
for (int i = 0; i < AXIS_COUNT; i++)
{
PrintUpdateBufferErrors(tempAxis);
}
std::vector<double> positions, times;
for (int i = 0; i < TOTAL_POINTS; i += AXIS_COUNT)
{
positions.push_back(i * TIME_SLICE * RPS);
times.push_back(TIME_SLICE);
}
int curMotionElementID = 0, curMotionID = 0, finalMotionID = 0;
int numPointsToSend = BUFFER_SZ;
int endOfLastSent = 0;
bool exitCondition = false;
const int motionHoldGate = 3;
for (int i = 0; i < 2; ++i)
{
endOfLastSent += numPointsToSend;
++finalMotionID;
}
while (!exitCondition)
{
if (std::abs(finalMotionID - curMotionID) < 2)
{
if (TOTAL_POINTS <= (endOfLastSent + BUFFER_SZ))
{
numPointsToSend = TOTAL_POINTS - endOfLastSent;
exitCondition = true;
}
printf("MotionID %d\nEnd of Last Sent %d\nElement ID %d\nNum to Send %d\nIs Done %s\n===========================================\n\n",
curMotionID, endOfLastSent, curMotionElementID, numPointsToSend, exitCondition ? "yes" : "no");
endOfLastSent += numPointsToSend;
++finalMotionID;
}
}
printf("Updates Done. Waiting to finish motion.\n");
}
printf(
"\n%s\n", err.
text);
}
}