12#include "SampleAppsHelper.h"
18static const std::map<RSIState, std::string> RSIStateMap = {
19 {RSIState::RSIStateIDLE,
"RSIStateIDLE"},
20 {RSIState::RSIStateMOVING,
"RSIStateMOVING"},
21 {RSIState::RSIStateSTOPPING,
"RSIStateSTOPPING"},
22 {RSIState::RSIStateSTOPPED,
"RSIStateSTOPPED"},
23 {RSIState::RSIStateSTOPPING_ERROR,
"RSIStateSTOPPING_ERROR"},
24 {RSIState::RSIStateERROR,
"RSIStateERROR"}
30 const std::string SAMPLE_APP_NAME =
"Math Blocks: Difference of Position User Limit";
36 const int NUM_AXES = 2;
37 const int AXIS_X_INDEX = 0;
38 const int AXIS_Y_INDEX = 1;
41 const double MAX_POSITION_DIFFERENCE = 0.5;
42 const RSIAction USER_LIMIT_ACTION = RSIAction::RSIActionABORT;
43 const int USER_LIMIT_DURATION = 0;
46 const double RELATIVE_POSITION = 2 * MAX_POSITION_DIFFERENCE;
47 const double VELOCITY = 1;
48 const double ACCELERATION = 10;
49 const double DECELERATION = 10;
50 const double JERK_PCT = 0;
58 int initialUserLimitCount = -1;
59 int initialMathBlockCount = -1;
83 const int userLimitIndex = initialUserLimitCount;
86 const int mathBlockIndex = initialMathBlockCount;
112 : (RSIAxisAddressType::RSIAxisAddressTypeCOMMAND_POSITION);
120 mathBlockConfig.
Operation = RSIMathBlockOperation::RSIMathBlockOperationSUBTRACT;
127 std::cout <<
"MathBlock configured to subtract the position of the second axis from the position of the first axis." << std::endl;
130 uint64_t mathBlockProcessValueAddress =
131 controller->
AddressGet(RSIControllerAddressType::RSIControllerAddressTypeMATHBLOCK_PROCESS_VALUE, mathBlockIndex);
135 userLimitIndex, 0, RSIUserLimitLogic::RSIUserLimitLogicABS_GT, mathBlockProcessValueAddress, MAX_POSITION_DIFFERENCE
140 userLimitIndex, RSIUserLimitTriggerType::RSIUserLimitTriggerTypeSINGLE_CONDITION, USER_LIMIT_ACTION, AXIS_X_INDEX,
143 std::cout <<
"UserLimit configured to trigger when the absolute position difference is greater than " << MAX_POSITION_DIFFERENCE
144 <<
" and abort motion." << std::endl;
147 std::cout <<
"Moving the axes to trigger the UserLimit..." << std::endl;
149 axisX->
MoveRelative(RELATIVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PCT);
157 if ((axisX->
StateGet() == RSIState::RSIStateERROR) && (axisY->
StateGet() == RSIState::RSIStateERROR))
159 std::cout <<
"Both axes are in the error state after the UserLimit triggered (This is the intended behavior)." << std::endl;
164 std::cout <<
"Error: The axes should be in an error state after the UserLimit triggers, but they are not." << std::endl;
165 std::cout <<
"First Axis State: " << RSIStateMap.at(axisX->
StateGet()) << std::endl;
166 std::cout <<
"Second Axis State: " << RSIStateMap.at(axisY->
StateGet()) << std::endl;
170 catch (
const std::exception &ex)
172 std::cerr << ex.what() << std::endl;
176 if (initialUserLimitCount != -1) { controller->
UserLimitCountSet(initialUserLimitCount); }
177 if (initialMathBlockCount != -1) { controller->
MathBlockCountSet(initialMathBlockCount); }
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,...
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
int32_t UserLimitCountGet()
Get the number of UserLimits processing in the firmware.
void MathBlockCountSet(int32_t mathBlockCount)
Set the number of processed MathBlocks in the MotionController.
void UserLimitConditionSet(int32_t number, int32_t conditionNumber, RSIUserLimitLogic logic, uint64_t addressOfUInt32, uint32_t userLimitMask, uint32_t limitValueUInt32)
Set the conditions for a User Limit with a 32-bit integer trigger value.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
static MotionController * Create()
Initialize and start the RMP EtherCAT controller.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
int32_t MathBlockCountGet()
Get the number of MathBlocks processing in the firmware.
void Delete(void)
Delete the MotionController and all its objects.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
MathBlockConfig MathBlockConfigGet(int32_t mathBlockNumber)
Get a MathBlock configuration.
void MathBlockConfigSet(int32_t mathBlockNumber, MathBlockConfig &config)
Set a MathBlock configuration.
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 AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
RSIState StateGet()
Get the Axis or MultiAxis state.
RSIAction
Action to perform on an Axis.
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static void Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
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...
static constexpr bool USE_HARDWARE
Flag for whether to use hardware or phantom axes.