APIs, concepts, guides, and more
Motion: Hold

Learn how to use motion hold in C#.

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.


In this page:


📜 Motion Hold: via Position

Learn how to use Motion Hold 📖 based on another axis reaching a specified position. One axis controls when another axis's motion is released, useful for synchronized operations.

/* 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");
int exitCode = 0;
// 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);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller, minRequiredSampleAxisCount: 2);
// 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, Constants.AMP_ENABLE_MS);
// configure motion hold - holdingAxis will be held until movingAxis reaches trigger position
bool movingAxisIsHardware = movingAxis.MotorTypeGet() != RSIMotorType.RSIMotorTypePHANTOM;
RSIMotionHoldType motionHoldType = movingAxisIsHardware ?
RSIMotionHoldType.RSIMotionHoldTypeAXIS_ACTUAL_POSITION : // AXIS_ACTUAL_POSITION for hardware axes
RSIMotionHoldType.RSIMotionHoldTypeAXIS_COMMAND_POSITION; // AXIS_COMMAND_POSITION for phantom axes
holdingAxis.MotionHoldTypeSet(motionHoldType);
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);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
Constants used in the C# sample apps.
Definition _constants.cs:3
const int EXIT_FAILURE
Exit code for failed execution.
Definition _constants.cs:69
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:20
const int AMP_ENABLE_MS
Default: 750.
Definition _constants.cs:35
const int EXIT_SUCCESS
Exit code for successful execution.
Definition _constants.cs:68
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:21
RSIMotorType MotorTypeGet()
Get the motor type.
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:5921
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.
void MotionHoldTypeSet(RSIMotionHoldType type)
Set the motion hold type.
void MotionHoldAxisNumberSet(int32_t number)
Sets the Axis number for Motion Hold.
int32_t MotionDoneWait(int32_t waitTimeoutMilliseconds=WaitForever)
Waits for a move to complete.
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:651
RSIMotorType
Motor Type.
Definition rsienums.h:1318
RSIMotionAttrMask
Attribute masks for motion. You cannot mix RSIMotionAttrMaskDELAY and RSIMotionAttrMaskAPPEND.
Definition rsienums.h:1067
RSIMotionHoldType
Types for MotionHold attribute.
Definition rsienums.h:1102
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21


📜 Motion Hold: via Digital Input

Learn how to use Motion Hold 📖 triggered by a digital input signal. Motion is held until the specified digital input pattern is detected.

/* This sample demonstrates how to hold motion until a digital input signal is received.
Uses a digital input to trigger motion release, useful for external sensor-based control.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Motion Hold: via Digital Input");
int exitCode = 0;
// set sample config params
const int DIGITAL_INPUTS_PDO_INDEX = 3; // pdo inputs index for digital inputs
// get rmp objects
try
{
Helpers.CheckErrors(controller);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// check is network is started
{
Console.WriteLine("Phantom axes do not have digital inputs. Please enable USE_HARDWARE to run this sample.");
}
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
}
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
// configure axis
// get host address using the pdo input index of digital inputs
ulong inputAddress = controller.NetworkInputAddressGet(DIGITAL_INPUTS_PDO_INDEX);
// configure motion hold for digital input
axis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeCUSTOM); // use custom type to hold based on bit pattern
axis.MotionHoldUserAddressSet(inputAddress); // specify the digital inputs host address
axis.MotionHoldUserMaskSet(0x20000); // specify the bit to watch (logic AND)
axis.MotionHoldUserPatternSet(0x20000); // bit value that will release the motion hold
// enable motion hold
axis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);
// command motion - will be held until digital input condition is met
axis.MoveRelative(3);
Console.WriteLine("\tFirst motion commanded (held until digital input triggers)");
// subsequent moves will also be held with same condition
axis.MoveRelative(3);
Console.WriteLine("\tSecond motion commanded (held until digital input triggers)");
// disable motion hold
axis.MotionAttributeMaskOffSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);
// this motion will execute immediately without hold
axis.MoveRelative(3);
Console.WriteLine("\tThird motion commanded (no hold, executes immediately)");
Console.WriteLine($"\tFinal position: {axis.CommandPositionGet()}");
// cleanup
Helpers.AbortMotionObject(axis);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
const bool USE_HARDWARE
Default: false.
Definition _constants.cs:10
void MotionHoldUserMaskSet(int32_t holdMask)
Sets the Motion Hold User bit mask.
void MotionHoldUserPatternSet(int32_t pattern)
Sets the Motion Hold User pattern bit mask.
void MotionAttributeMaskOffSet(RSIMotionAttrMask maskOff)
Turn off a particular motion attribute mask.
void MotionHoldUserAddressSet(uint64_t address)
Sets the Motion Hold User Address.
RSINetworkState
State of network.
Definition rsienums.h:573


📜 Motion Hold: via Address

Learn how to use Motion Hold 📖 controlled by a software address. Motion is held until a specific bit pattern is written to a memory location.

/* This sample demonstrates how to hold motion using a software address (memory location).
Motion is held until a specific bit pattern is written to the address, useful for custom logic.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
using System.Threading;
Console.WriteLine("📜 Motion Hold: via Address");
int exitCode = 0;
// set sample config params
const int MOVE_DISTANCE = 2;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
// configure phantom axis
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis);
axis.PositionSet(0);
// get available software address from user buffer
ulong softwareAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 1);
// configure motion hold on software address
axis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeCUSTOM); // use custom type to hold based on bit pattern
axis.MotionHoldUserAddressSet(softwareAddress); // specify the host address
axis.MotionHoldUserMaskSet(0x1); // specify the bit to watch (logic AND)
axis.MotionHoldUserPatternSet(0x1); // bit value that will release the motion hold
// ensure condition is false initially
if (controller.MemoryGet(softwareAddress) != 0x0)
controller.MemorySet(softwareAddress, 0x0);
// enable motion hold
axis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);
// command motion - will be held
axis.MoveRelative(MOVE_DISTANCE);
Console.WriteLine($"\tFirst motion commanded to move {MOVE_DISTANCE} (held)");
Thread.Sleep(100);
double positionWhileHeld = axis.CommandPositionGet();
Console.WriteLine($"\tPosition while held: {positionWhileHeld} (should be 0)");
// release motion hold by setting the address
controller.MemorySet(softwareAddress, 0x1);
Console.WriteLine("\tReleasing hold via address...");
controller.MemorySet(softwareAddress, 0x0); // reset to false
Console.WriteLine($"\tPosition after release: {axis.CommandPositionGet()} (expected: {MOVE_DISTANCE})");
// command motion again - will be held again
axis.MoveRelative(MOVE_DISTANCE);
Console.WriteLine($"\tSecond motion commanded to move {MOVE_DISTANCE} (held)");
Thread.Sleep(100);
// release motion hold again
controller.MemorySet(softwareAddress, 0x1);
Console.WriteLine("\tReleasing hold via address...");
controller.MemorySet(softwareAddress, 0x0); // reset to false
// disable motion hold
axis.MotionAttributeMaskOffSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);
// this motion will execute immediately
axis.MoveRelative(MOVE_DISTANCE);
Console.WriteLine($"\tThird motion commanded to move {MOVE_DISTANCE} (no hold)");
Console.WriteLine($"\tFinal position: {axis.CommandPositionGet()} (expected: {MOVE_DISTANCE * 3})");
// clean up
Helpers.AbortMotionObject(axis);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
const double AXIS_0_USER_UNITS
Default: 1.
Definition _constants.cs:26
double CommandPositionGet()
Get the current command position.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void PositionSet(double position)
Set the Command and Actual positions.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:405