The RMP Motion Controller APIs
MotionHoldReleasedBySoftwareAddress.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
#include <thread> // std::this_thread::sleep_for
void MotionHoldReleasedBySoftwareAddressMain()
{
using namespace RSI::RapidCode;
// Constants
const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
const int USER_UNITS = 1048576; // Specify USER UNITS
unsigned int SOFTWARE_ADDRESS = 0x026000B4; // Specify Avaiable firmware address (starting from 0x026000B4 to 0x027FFFFF) can be checked in VM3.In VM3, look for Address without label which are available/free.
char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
// Initialize MotionController class.
MotionController *controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
HelperFunctions::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
try
{
HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
Axis *axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
HelperFunctions::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 everytime.
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.
// SET MOTION HOLD ON AVAILABLE SOFTWARE ADDRESS
unsigned long hostAddress = controller->HostAddressGet(SOFTWARE_ADDRESS); // Get host address from software address
axis->MotionHoldTypeSet(RSIMotionHoldType::RSIMotionHoldTypeCUSTOM); // Use TypeCUSTOM to hold execution based on a particular bit turning ON or OFF.
axis->MotionHoldUserAddressSet(hostAddress); // 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(hostAddress) != 0x0) // Check Available host address value is mask to be false (in this case 0x0)
{
controller->MemorySet(hostAddress, 0x0); // if not, mask it to false value/condition (in this case 0x0)
}
// SET MOTION HOLD
axis->MotionAttributeMaskOnSet(RSIMotionAttrMask::RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
axis->MoveRelative(10); // Command simple relative motion. (This motion will be HOLD by the condition above)
std::this_thread::sleep_for(std::chrono::seconds(3)); // Sleep for 3 second before releasing motion hold.
// RELEASE MOTION HOLD
controller->MemorySet(hostAddress, 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(hostAddress, 0x0); // Specify host address value back to false value/condition (in this case 0x0)
// COMMAND MOTION AGAIN
axis->MoveRelative(10); // Command simple relative motion again. (This motion will be HOLD by the condition above)
std::this_thread::sleep_for(std::chrono::seconds(3)); // Sleep for 3 second before releasing motion hold.
// RELEASE MOTION HOLD
controller->MemorySet(hostAddress, 0x1); // Release Motion Hold by specifying the host address value to SET Condition (in this case 0x1)
axis->MotionDoneWait(); // Wait for motion to be done
controller->MemorySet(hostAddress, 0x0); // Specify host address value back to false value/condition (in this case 0x0)
// CLEAR MOTION HOLD
axis->MotionAttributeMaskOffSet(RSIMotionAttrMask::RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask OFF. (This will clear any motion HOLDS that were set on this Axis)
axis->MoveRelative(10); // 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.
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
system("pause"); // Allow time to read Console.
}
RSI::RapidCode::RapidCodeMotion::MotionHoldUserPatternSet
void MotionHoldUserPatternSet(int32_t pattern)
Sets the Motion Hold User pattern bit mask.
RSI::RapidCode::RapidCodeMotion::ClearFaults
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
RSI::RapidCode::MotionController::MemoryGet
int32_t MemoryGet(uint64_t address)
Read controller memory.
RSI::RapidCode::RsiError
The RsiError object contains information about any RapidCode API object's error/exception.
Definition: rsi.h:100
RSI::RapidCode::MotionController::Delete
void Delete(void)
Delete the MotionController and all its objects.
RSI::RapidCode::Axis::MoveRelative
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
RSI::RapidCode::MotionController::CreateFromSoftware
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
RSI::RapidCode::RSIMotionHoldType::RSIMotionHoldTypeNONE
@ RSIMotionHoldTypeNONE
RSI::RapidCode
RSI::RapidCode::Axis::ErrorLimitTriggerValueSet
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.
RSI::RapidCode::MotionController::MemorySet
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
RSI::RapidCode::RapidCodeMotion::MotionAttributeMaskOffSet
void MotionAttributeMaskOffSet(RSIMotionAttrMask maskOff)
Turn off a particular motion attribute mask.
RSI::RapidCode::MotionController::AxisGet
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSI::RapidCode::Axis::PositionSet
void PositionSet(double position)
Set the Command and Actual positions.
RSI::RapidCode::RapidCodeMotion::Abort
void Abort()
Abort an axis.
RSI::RapidCode::RapidCodeMotion::MotionHoldUserMaskSet
void MotionHoldUserMaskSet(int32_t holdMask)
Sets the Motion Hold User bit mask.
RSI::RapidCode::Axis::UserUnitsSet
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
RSI::RapidCode::MotionController
The MotionController object represents the RMP INtime soft motion controller.
Definition: rsi.h:765
RSI::RapidCode::Axis
The Axis object manages a single physical axis on a motion controller.
Definition: rsi.h:6079
RSI::RapidCode::RapidCodeMotion::AmpEnableSet
void AmpEnableSet(bool enable)
Enable all amplifiers.
RSI::RapidCode::RapidCodeMotion::MotionHoldUserAddressSet
void MotionHoldUserAddressSet(uint64_t address)
Sets the Motion Hold User Address.
RSI::RapidCode::RapidCodeMotion::MotionHoldTypeSet
void MotionHoldTypeSet(RSIMotionHoldType type)
Set the motion hold type.
HelperFunctions.CheckErrors
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCode Object has any errors.
Definition: HelperFunctions.cs:64
HelperFunctions.StartTheNetwork
static void StartTheNetwork(MotionController controller)
Start the controller communication/network.
Definition: HelperFunctions.cs:109
RSI::RapidCode::RapidCodeMotion::MotionDoneWait
int32_t MotionDoneWait()
Waits for a move to complete.
RSI::RapidCode::MotionController::HostAddressGet
uint64_t HostAddressGet(uint32_t firmwareAddress)
Convert a firmware address to a host controller address.
RSI::RapidCode::RapidCodeMotion::MotionAttributeMaskOnSet
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.