#include <cassert>
#include "rsi.h"
#include <cmath>
#include "SampleApps.h"
#include "SampleAppsHelper.h"
int UpdateBufferPoints::Run()
{
const int AXIS_COUNT = 1;
const int AXIS_NUMBER = 0;
const double USER_UNITS = 1048576;
const double TIME_SLICE = 0.001;
const int REVS = 2;
const int RPS = 1;
const int TOTAL_POINTS = (int)(REVS / TIME_SLICE / RPS);
const int BUFFER_SZ = 100;
const int EMPTY_CT = 10;
USE_HARDWARE = false;
if (USE_HARDWARE)
{
}
else
{
}
try
{
controller->MotionCountSet(AXIS_COUNT + 1);
multiAxis = controller->MultiAxisGet(AXIS_COUNT);
Axis* axis = controller->AxisGet(AXIS_NUMBER);
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;
controller->MotionHoldGateSet(motionHoldGate, true);
for (int i = 0; i < 2; ++i)
{
endOfLastSent += numPointsToSend;
++finalMotionID;
}
controller->SyncInterruptPeriodSet(10);
controller->SyncInterruptEnableSet(true);
controller->MotionHoldGateSet(motionHoldGate, false);
while (!exitCondition)
{
int32_t sampleRecieved = controller->SyncInterruptWait();
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);
return -1;
}
controller->Delete();
return 0;
}
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void PositionSet(double position)
Set the Command and Actual positions.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
uint16_t MotionIdExecutingGet()
uint16_t MotionElementIdExecutingGet()
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
void MotionIdSet(uint16_t id)
Set the Motion identifier.
RSIState StateGet()
Get the Axis or MultiAxis state.
void MotionHoldGateSet(bool hold)
Set the Motion Hold Gate.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
void EStopAbort()
E-Stop, then abort an axis.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
@ RSIMotionTypePT
Position-Time algorithm with continuous position but discontinuous velocity. Best for short time inte...
@ RSIActionNONE
None - do not perform any action.
@ RSIStateIDLE
Idle, ready for anything.
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.