APIs, concepts, guides, and more
axis-motion-hold-via-position.cs
Note
See Motion: Hold 📜 for a detailed explanation of this sample code.
Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
/* This sample demonstrates how to hold motion based on another axis reaching a specified position.
Uses one axis to control when another axis's motion is released, useful for synchronized operations.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Motion Hold: via Position");
// set sample config params
const double TRIGGER_POSITION = 1;
const int MOVING_AXIS_TARGET = 10;
const int HOLDING_AXIS_TARGET = 2;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// get axes
Axis holdingAxis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(holdingAxis);
Axis movingAxis = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(movingAxis);
// configure phantom axes
Helpers.PhantomAxisReset(holdingAxis);
Helpers.PhantomAxisReset(movingAxis);
holdingAxis.AmpEnableSet(true);
movingAxis.AmpEnableSet(true);
// configure motion hold - holdingAxis will be held until movingAxis reaches trigger position
holdingAxis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeAXIS_COMMAND_POSITION); // use AXIS_ACTUAL_POSITION for real axes
holdingAxis.MotionHoldAxisNumberSet(movingAxis.NumberGet()); // specify which axis position to monitor
holdingAxis.MotionHoldAxisPositionSet(TRIGGER_POSITION); // position that will release the hold
holdingAxis.MotionHoldAxisLogicSet(RSIUserLimitLogic.RSIUserLimitLogicGE); // release when position >= trigger position
// enable motion hold and command motion
holdingAxis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);
holdingAxis.MoveRelative(HOLDING_AXIS_TARGET); // this motion will be held
Console.WriteLine($"\tHolding axis commanded to move to {HOLDING_AXIS_TARGET}, but motion is held");
// move the trigger axis to release the hold
movingAxis.MoveRelative(MOVING_AXIS_TARGET);
Console.WriteLine($"\tMoving axis to {MOVING_AXIS_TARGET} to release hold...");
movingAxis.MotionDoneWait();
holdingAxis.MotionDoneWait();
Console.WriteLine($"\tHolding axis final position: {holdingAxis.CommandPositionGet()} (expected: {HOLDING_AXIS_TARGET})");
Console.WriteLine($"\tMoving axis final position: {movingAxis.CommandPositionGet()} (expected: {MOVING_AXIS_TARGET})");
// cleanup
Helpers.AbortMotionObject(holdingAxis);
Helpers.AbortMotionObject(movingAxis);
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
Constants used in the C# sample apps.
Definition _constants.cs:3
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:11
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:12
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,...
Definition rsi.h:5863
static MotionController * Get()
Get an already running RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void MotionHoldAxisPositionSet(double position)
Sets the Axis position.
int32_t MotionDoneWait()
Waits for a move to complete.
void MotionHoldTypeSet(RSIMotionHoldType type)
Set the motion hold type.
void MotionHoldAxisNumberSet(int32_t number)
Sets the Axis number for Motion Hold.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
int32_t NumberGet()
Get the axis number.
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
void MotionHoldAxisLogicSet(RSIUserLimitLogic logic)
Set the logic when holding for Axis ActualPosition.
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:646
RSIMotionAttrMask
Attribute masks for motion. You cannot mix RSIMotionAttrMaskDELAY and RSIMotionAttrMaskAPPEND.
Definition rsienums.h:1060
RSIMotionHoldType
Types for MotionHold attribute.
Definition rsienums.h:1095
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21