APIs, concepts, guides, and more
MotionHoldReleasedBySoftwareAddress.cpp
Attention
See the following Concept pages for a detailed explanation of this sample: Motion Hold.
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.
#include <thread>
#include "rsi.h" // Import our RapidCode Library.
#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
#include "SampleApps.h"
using namespace RSI::RapidCode; // Import the RapidCode namespace
int MotionHoldReleasedBySoftwareAddress::Run()
{
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
// Axis configuration parameters
const int AXIS_COUNT = 1;
const int AXIS_NUMBER = 0;
const double USER_UNITS = 1048576;
// Index for the address in the user buffer to use for the motion hold
const int USER_BUFFER_INDEX = 0;
// Motion parameters
const double MOTION_DISTANCE = 0.25;
const std::chrono::duration HOLD_TIME = std::chrono::milliseconds(2000);
// To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
USE_HARDWARE = false;
// The rmpPath only needs to be set if the project directory is different than the rapid setup directory.
// *NOTICE* When setting the rmpPath, be sure to uncomment the rmpPath arguement in MotionController::CreateFromSoftware() in the Run() function.
const char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)"
/* SAMPLE APP BODY */
// Initialize MotionController class.
MotionController* controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
SampleAppsHelper::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
}
try
{
Axis* axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsHelper::CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
// GET AXIS READY
axis->UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
axis->PositionSet(0); // Make sure motor starts at position 0 every time.
axis->ErrorLimitTriggerValueSet(1); // Set the position error trigger value
axis->Abort(); // If there is any motion happening, abort it.
axis->ClearFaults(); // Clear faults.>
axis->AmpEnableSet(true); // Enable the motor.
// GET AN AVAILABLE MEMORY ADDRESS
uint64_t userBufferAddress = controller->AddressGet(RSIControllerAddressType::RSIControllerAddressTypeUSER_BUFFER, USER_BUFFER_INDEX);
// SET MOTION HOLD ON AVAILABLE SOFTWARE ADDRESS
axis->MotionHoldTypeSet(RSIMotionHoldType::RSIMotionHoldTypeCUSTOM); // Use TypeCUSTOM to hold execution based on a particular bit turning ON or OFF.
axis->MotionHoldUserAddressSet(userBufferAddress); // Specify the available hostAddress . This address' value will be used to evaluate the motion hold condition.
axis->MotionHoldUserMaskSet(0x1); // Specify the bit you want to mask/watch from the MotionHoldUserAddressSet' address value (this evaluates using a logic AND)
axis->MotionHoldUserPatternSet(0x1); // Specify the bit value that will release the motion hold. (When this value is met, motion hold will be released)
// Check the condition to be false at first
if (controller->MemoryGet(userBufferAddress) != 0x0) // Check Available host address value is mask to be false (in this case 0x0)
{
controller->MemorySet(userBufferAddress, 0x0); // if not, mask it to false value/condition (in this case 0x0)
}
// COMMAND MOTION (NO HOLD YET)
printf("\nCommanding Motion...\n");
axis->MoveRelative(MOTION_DISTANCE); // Command simple relative motion. (This motion will have no HOLD)
// SET MOTION HOLD
printf("\nSetting Motion Hold...\n");
axis->MotionAttributeMaskOnSet(RSIMotionAttrMask::RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
// COMMAND MOTION AGAIN (MOTION WILL BE HELD)
printf("Commanding Motion...\n");
axis->MoveRelative(MOTION_DISTANCE); // Command simple relative motion. (This motion will be HOLD by the condition above)
std::this_thread::sleep_for(HOLD_TIME); // Sleep for 3 second before releasing motion hold.
// RELEASE MOTION HOLD (MOTION WILL START)
printf("Releasing Motion Hold...\n");
controller->MemorySet(userBufferAddress, 0x1); // Release Motion Hold by specifying the host address value to SET Condition (in this case 0x10000)
axis->MotionDoneWait(); // Wait for motion to be done
controller->MemorySet(userBufferAddress, 0x0); // Specify host address value back to false value/condition (in this case 0x0)
// CLEAR MOTION HOLD
printf("\nClearing Motion Hold...\n");
axis->MotionAttributeMaskOffSet(RSIMotionAttrMask::RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask OFF. (This will clear any motion HOLDS that were set on this Axis)
// COMMAND MOTION AGAIN (NO HOLD)
printf("Commanding Motion...\n");
axis->MoveRelative(-2 * MOTION_DISTANCE); // This motion will have no HOLD since the previous line has set the motion attribute mask OFF.
axis->MotionDoneWait(); // Wait for Motion to be completed.
// Abort and Clear Faults
axis->Abort();
axis->ClearFaults();
}
catch (RsiError const& err)
{
printf("%s\n", err.text); // If there are any exceptions/issues this will be printed out.
return -1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.
void PositionSet(double position)
Set the Command and Actual positions.
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:5643
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.
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:796
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.
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.
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:107
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.