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 /* CONSTANTS */
23 // *NOTICE* The following constants must be configured before attempting to run with hardware.
24 const int NUM_AXES = 1; // The number of axes to configure, default is 0 for this template
25 const int AXIS_INDEX = 0; // The index of the axis to configure
26
27 /* RAPIDCODE INITIALIZATION */
28
29 // Create the controller
31 MotionController *controller = MotionController::Create(&params);
32
33 // Set the exit code to an error value.
34 int exitCode = -1;
35 try // Ensure that the controller is deleted if an error occurs.
36 {
37 // Prepare the controller as defined in SampleAppsHelper.h depending on the configuration
39 SampleAppsHelper::SetupController(controller, NUM_AXES);
40
41 /* SET CONTROLLER OBJECT COUNTS HERE*/
42 // Normally you would set the number of axes here, but for samples that is handled in the SampleAppsHelper::SetupController function
43 // controller->AxisCountSet(NUM_AXES);
44
45 /* SAMPLE APP BODY */
46
48 // Get the axis
49 Axis *axis = controller->AxisGet(AXIS_INDEX);
51
52 // Configure the axis as a phantom axis
53 // 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)
54 // Therefore, you must set all of their actions to "NONE".
55 axis->PositionSet(0); // Set the position to 0
56 axis->ErrorLimitActionSet(RSIAction::RSIActionNONE); // Set Error Limit Action.
57 axis->AmpFaultActionSet(RSIAction::RSIActionNONE); // Set Amp Fault Action.
58 axis->AmpFaultTriggerStateSet(1); // Set Amp Fault Trigger State.
59 axis->HardwareNegLimitActionSet(RSIAction::RSIActionNONE); // Set Hardware Negative Limit Action.
60 axis->HardwarePosLimitActionSet(RSIAction::RSIActionNONE); // Set Hardware Positive Limit Action.
61 axis->SoftwareNegLimitActionSet(RSIAction::RSIActionNONE); // Set Software Negative Limit Action.
62 axis->SoftwarePosLimitActionSet(RSIAction::RSIActionNONE); // Set Software Positive Limit Action.
63 axis->HomeActionSet(RSIAction::RSIActionNONE); // Set Home Action.
64
65 // Reduce from max slightly, so XML to string serialization and deserialization works without throwing System.OverflowException
66 const double positionToleranceMax = std::numeric_limits<double>::max() / 10.0;
67 axis->PositionToleranceCoarseSet(positionToleranceMax); // Set Settling Coarse Position Tolerance to max value
68
69 // Set Settling Fine Position Tolerance to max value (so Phantom axis will get immediate MotionDone when target is reached)
70 axis->PositionToleranceFineSet(positionToleranceMax);
71
72 axis->MotorTypeSet(RSIMotorType::RSIMotorTypePHANTOM); // Set the MotorType to phantom
74
75 std::cout << "Phantom Axis created with index: " << AXIS_INDEX << std::endl;
76
77 exitCode = 0; // Set the exit code to success.
78 }
79 catch (const std::exception &ex)
80 {
81 std::cerr << ex.what() << std::endl;
82 exitCode = -1;
83 }
84 // Clean up the controller and any other objects as needed
85 SampleAppsHelper::Cleanup(controller);
86
87 // Delete the controller as the program exits to ensure memory is deallocated in the correct order
88 controller->Delete();
89
90 // Print a message to indicate the sample app has finished and if it was successful or not
91 SampleAppsHelper::PrintFooter(SAMPLE_APP_NAME, exitCode);
92
93 return exitCode;
94}
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:5643
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.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
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 Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
CreationParameters for MotionController::Create.
Definition rsi.h:857