#include <map>
#include "helpers.h"
#include "config.h"
#include "rsi.h"
static const std::map<RSIState, std::string> RSIStateMap = {
};
int main()
{
const std::string SAMPLE_APP_NAME = "📜 Math Blocks: Difference of Position User Limit";
const int NUM_AXES = 2;
const int AXIS_X_INDEX = 0;
const int AXIS_Y_INDEX = 1;
const double MAX_POSITION_DIFFERENCE = 0.5;
const int USER_LIMIT_DURATION = 0;
const double RELATIVE_POSITION = 2 * MAX_POSITION_DIFFERENCE;
const double VELOCITY = 1;
const double ACCELERATION = 10;
const double DECELERATION = 10;
const double JERK_PCT = 0;
int initialUserLimitCount = -1;
int initialMathBlockCount = -1;
int exitCode = -1;
try
{
initialUserLimitCount = controller->UserLimitCountGet();
initialMathBlockCount = controller->MathBlockCountGet();
const int multiAxisIndex = controller->AxisCountGet();
controller->MotionCountSet(multiAxisIndex + 1);
const int userLimitIndex = initialUserLimitCount;
controller->UserLimitCountSet(initialUserLimitCount + 1);
const int mathBlockIndex = initialMathBlockCount;
controller->MathBlockCountSet(initialMathBlockCount + 1);
Axis *axisX = controller->AxisGet(AXIS_X_INDEX);
Axis *axisY = controller->AxisGet(AXIS_Y_INDEX);
MultiAxis *multiAxis = controller->MultiAxisGet(multiAxisIndex);
controller->MathBlockConfigSet(mathBlockIndex, mathBlockConfig);
controller->SampleWait(1);
std::cout << "MathBlock configured to subtract the position of the second axis from the position of the first axis." << std::endl;
uint64_t mathBlockProcessValueAddress =
controller->UserLimitConditionSet(
);
controller->UserLimitConfigSet(
USER_LIMIT_DURATION
);
std::cout << "UserLimit configured to trigger when the absolute position difference is greater than " << MAX_POSITION_DIFFERENCE
<< " and abort motion." << std::endl;
std::cout << "Moving the axes to trigger the UserLimit..." << std::endl;
axisX->
MoveRelative(RELATIVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PCT);
controller->UserLimitDisable(userLimitIndex);
{
std::cout << "Both axes are in the error state after the UserLimit triggered (This is the intended behavior)." << std::endl;
exitCode = 0;
}
else
{
std::cout << "Error: The axes should be in an error state after the UserLimit triggers, but they are not." << std::endl;
std::cout <<
"First Axis State: " << RSIStateMap.at(axisX->
StateGet()) << std::endl;
std::cout <<
"Second Axis State: " << RSIStateMap.at(axisY->
StateGet()) << std::endl;
exitCode = -1;
}
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
if (initialUserLimitCount != -1) { controller->UserLimitCountSet(initialUserLimitCount); }
if (initialMathBlockCount != -1) { controller->MathBlockCountSet(initialMathBlockCount); }
controller->Delete();
return exitCode;
}
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
void AxisRemoveAll()
Remove all axes from a MultiAxis group.s.
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.
RSIState StateGet()
Get the Axis or MultiAxis state.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
@ RSIMathBlockOperationSUBTRACT
Subtraction operation.
@ RSIControllerAddressTypeMATHBLOCK_PROCESS_VALUE
the processed value of a math block (must specify object index)
@ RSIDataTypeDOUBLE
double (64-bit floating point)
@ RSIUserLimitLogicABS_GT
Absolute value is greater than.
RSIAction
Action to perform on an Axis.
@ RSIActionABORT
Abort - disable the amplifier, zero filter output, leave in error state.
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
@ RSIAxisAddressTypeCOMMAND_POSITION
Command Position.
@ RSIAxisAddressTypeACTUAL_POSITION
Actual Position.
@ RSIUserLimitTriggerTypeSINGLE_CONDITION
Only one condition is evaluated.
@ RSIStateSTOPPING
Stopping, on its way to stopped. Note: Cannot use Axis::PositionSet() or Axis::CommandPositionSet() i...
@ RSIStateSTOPPING_ERROR
Stopping with an error.
@ RSIStateSTOPPED
Stopped (resumable). Note: Cannot use Axis::PositionSet() or Axis::CommandPositionSet() in this state...
@ RSIStateMOVING
Moving (without any errors). Note: Cannot use Axis::PositionSet() or Axis::CommandPositionSet() in th...
@ RSIStateIDLE
Idle, ready for anything.
void SetupController(MotionController *controller, int numAxes=0)
Setup the controller and check if the network is in the correct state for the configuration.
MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
void Cleanup(MotionController *controller)
[SetupController]
constexpr bool USE_HARDWARE
Flag for whether to use hardware or phantom axes.
void CheckErrors(RapidCodeObject *rsiObject, const std::source_location &location=std::source_location::current())
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
void PrintHeader(std::string sampleAppName)
[NetworkShutdown]
void PrintFooter(std::string sampleAppName, int exitCode)
[PrintHeader]
CreationParameters for MotionController::Create.
RSIDataType ProcessDataType
Data type for processing.
MathBlock configuration structure.
uint64_t InputAddress0
Host memory address for Input0. Represents the left-hand side operand in math operations.
RSIDataType InputDataType0
Data type for Input0. This is the data type of the left-hand side operand in math operations.
uint64_t InputAddress1
Host memory address for Input1. Represents the right-hand side operand in math operations.
RSIDataType InputDataType1
Data type for Input1. This is the data type of the right-hand side operand in math operations.
RSIMathBlockOperation Operation
Math operation to be performed. (+, -, *, /, etc) use RSIMathBlockOperationNONE to disable a MathBloc...