APIs, concepts, guides, and more
PhantomAxis.cpp
1
10#include "SampleAppsHelper.h" // Import our helper functions.
11#include "rsi.h" // Import our RapidCode Library.
12
13using namespace RSI::RapidCode; // Import the RapidCode namespace
14
15int main()
16{
17 const std::string SAMPLE_APP_NAME = "Axis Configuration: Phantom Axis";
18
19 // Print a start message to indicate that the sample app has started
20 SampleAppsHelper::PrintHeader(SAMPLE_APP_NAME);
21
22 /* RAPIDCODE INITIALIZATION */
23
24 // Create the controller
26 MotionController *controller = MotionController::Create(&params);
27
28 int exitCode = -1; // Set the exit code to an error value.
29 try // Ensure that the controller is deleted if an error occurs.
30 {
32
33 // Prepare the controller and axes as defined in SampleAppsHelper.h
35
36 /* SAMPLE APP BODY */
37
39 // Add an axis to the controller
41 int axisIndex = SampleAppsConfig::AXIS_COUNT;
42
43 // Get the axis
44 Axis *axis = controller->AxisGet(axisIndex);
46
47 // Configure the axis as a phantom axis
48 // These limits are not meaningful for a Phantom Axis (e.g., a phantom axis has no actual position so a position error trigger is not necessary)
49 // Therefore, you must set all of their actions to "NONE".
50 axis->PositionSet(0); // Set the position to 0
51 axis->ErrorLimitActionSet(RSIAction::RSIActionNONE); // Set Error Limit Action.
52 axis->AmpFaultActionSet(RSIAction::RSIActionNONE); // Set Amp Fault Action.
53 axis->AmpFaultTriggerStateSet(1); // Set Amp Fault Trigger State.
54 axis->HardwareNegLimitActionSet(RSIAction::RSIActionNONE); // Set Hardware Negative Limit Action.
55 axis->HardwarePosLimitActionSet(RSIAction::RSIActionNONE); // Set Hardware Positive Limit Action.
56 axis->SoftwareNegLimitActionSet(RSIAction::RSIActionNONE); // Set Software Negative Limit Action.
57 axis->SoftwarePosLimitActionSet(RSIAction::RSIActionNONE); // Set Software Positive Limit Action.
58 axis->HomeActionSet(RSIAction::RSIActionNONE); // Set Home Action.
59
60 // Reduce from max slightly, so XML to string serialization and deserialization works without throwing System.OverflowException
61 const double positionToleranceMax = std::numeric_limits<double>::max() / 10.0;
62 axis->PositionToleranceCoarseSet(positionToleranceMax); // Set Settling Coarse Position Tolerance to max value
63
64 // Set Settling Fine Position Tolerance to max value (so Phantom axis will get immediate MotionDone when target is reached)
65 axis->PositionToleranceFineSet(positionToleranceMax);
66
67 axis->MotorTypeSet(RSIMotorType::RSIMotorTypePHANTOM); // Set the MotorType to phantom
69
70 std::cout << "Phantom Axis created with index: " << axisIndex << std::endl;
71
72 exitCode = 0; // Set the exit code to success.
73 }
74 catch (const std::exception &ex)
75 {
76 std::cerr << ex.what() << std::endl;
77 exitCode = -1;
78 }
79 // Delete the controller as the program exits to ensure memory is deallocated in the correct order
80 controller->Delete();
81
82 // Print a message to indicate the sample app has finished and if it was successful or not
83 SampleAppsHelper::PrintFooter(SAMPLE_APP_NAME, exitCode);
84
85 return exitCode;
86}
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
void AmpFaultActionSet(RSIAction action)
Set the Amp Fault action.
void AmpFaultTriggerStateSet(bool state)
Set the trigger state of the Amp Fault input.
void HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MotorTypeSet(RSIMotorType type)
Set the motor type.
void PositionSet(double position)
Set the Command and Actual positions.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5518
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * Create()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:795
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static void SetupController(MotionController *controller)
Setup the controller with user defined axis counts and configuration.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.
Definition rsi.h:856
static constexpr int AXIS_COUNT
Number of axes to configure on the controller.