APIs, concepts, guides, and more
axis-motion-hold-via-address.cs
/* 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");
// set sample config params
const int MOVE_DISTANCE = 2;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
// configure phantom axis
axis.AmpEnableSet(true);
// 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)");
// clean up
Console.WriteLine($"\tFinal position: {axis.CommandPositionGet()} (expected: {MOVE_DISTANCE * 3})");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
static void AbortMotionObject(RapidCodeMotion motionObject)
Aborts motion on the given RapidCodeMotion object (Axis or MultiAxis), waits for motion to stop,...
Definition _helpers.cs:186
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
static void PhantomAxisReset(Axis phantomAxis)
Configures a phantom axis on the controller.
Definition _helpers.cs:144
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
double CommandPositionGet()
Get the current command position.
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:5862
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
int32_t MemoryGet(uint64_t address)
Read controller memory.
void Delete(void)
Delete the MotionController and all its objects.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
int32_t MotionDoneWait()
Waits for a move to complete.
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 MotionHoldTypeSet(RSIMotionHoldType type)
Set the motion hold type.
void MotionHoldUserAddressSet(uint64_t address)
Sets the Motion Hold User Address.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:405
RSIMotionAttrMask
Attribute masks for motion. You cannot mix RSIMotionAttrMaskDELAY and RSIMotionAttrMaskAPPEND.
Definition rsienums.h:1060
RSIMotionHoldType
Types for MotionHold attribute.
Definition rsienums.h:1095