The RMP Motion Controller APIs
SingleAxisSyncOutputs.cpp
1
17#include "rsi.h" // Import our RapidCode Library.
18#include "HelperFunctionsCpp.h" // Import our SampleApp helper functions.
19#include "SampleApps.h"
20
21using namespace RSI::RapidCode;
22
24int SingleAxisSyncOutputs::Run()
25{
26 /* CONSTANTS */
27 // *NOTICE* The following constants must be configured before attempting to run with hardware.
28
29 // Axis configuration parameters
30 const int AXIS_COUNT = 1; // Specify how many axes you have.
31 const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
32
33 const double USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
34
35 // IO configuration parameters
36 const int NODE_INDEX = 0; // Specify which EtherCat Node will be used
37 const int OUTPUT_INDEX = 0;
38
39 const int OUTPUT_ENABLE_ID = 2; // The motion element ID at which to set the output
40 const int OUTPUT_DISABLE_ID = 3; // The motion element ID at which to set the output
41
42 // Motion parameters
43 const int TOTAL_POINTS = 4; // total number of points
44 const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
45 const double POSITIONS[] = { 0.25, 0.50, 0.75, 1.0 }; // These will be the streaming motion 5 positions.
46 const double TIMES[] = { 0.5, 1.0, 1.5, 2.0 }; // These will be the streaming motion 5 positions' time.
47
48 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
49 USE_HARDWARE = false;
50
51 // The rmpPath only needs to be set if the project directory is different than the rapid setup directory.
52 // *NOTICE* When setting the rmpPath, be sure to uncomment the rmpPath arguement in MotionController::CreateFromSoftware() in the Run() function.
53 char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
54
55 // Initialize MotionController class.
56 MotionController* controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
57 HelperFunctionsCpp::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
58
59 // Setup the controller for the appropriate hardware configuration.
60 if (USE_HARDWARE)
61 {
63 }
64 else
65 {
66 HelperFunctionsCpp::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
67 }
68
69 try
70 {
71 Axis* axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
72 HelperFunctionsCpp::CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
73
74 axis->PositionSet(0); // Make sure motor starts at position 0 everytime.
75 axis->UserUnitsSet(USER_UNITS); // Change your user units.
76 axis->ErrorLimitActionSet(RSIAction::RSIActionNONE); // Set Error Limit Action.
77 axis->Abort(); // If there is any motion happening, abort it.
78 axis->ClearFaults(); // Clear faults.>
79 axis->AmpEnableSet(true); // Enable the motor.
80
81 // Set up the inputs
82 // Ensure the digital out is set low.
83 //IOPoint *output0 = IOPoint::CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
84 IOPoint* output0 = IOPoint::CreateDigitalOutput(controller->IOGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
85 output0->Set(false);
86
87 // Set up Sync Outputs
88 axis->StreamingOutputsEnableSet(true); // Enable streaming output.
89
90 // ENABLE the Sync Output(s)
91 axis->StreamingOutputAdd(output0, true, OUTPUT_ENABLE_ID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
92 axis->StreamingOutputAdd(output0, false, OUTPUT_DISABLE_ID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
93
94 // DISABLE the Sync Output(s)
95 //axis->StreamingOutputAdd(output0, false, outPutEnableID);
96
97 axis->MovePT(RSIMotionType::RSIMotionTypePT, POSITIONS, TIMES, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
98 printf("Motion started. Waiting to complete.\n");
99
100 axis->MotionDoneWait(); // What for Streaming Motion to be done.
101 printf("Motion Complete. The outputs should have been set\n");
102
103 axis->StreamingOutputsEnableSet(false); // Disable Sync Outputs.
104 axis->AmpEnableSet(false); // Disable the motor.
105
106 }
107 catch (RsiError const& err)
108 {
109 printf("%s\n", err.text); // If there are any exceptions/issues this will be printed out.
110 return -1;
111 }
112 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
113 return 0;
114}
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.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void PositionSet(double position)
Set the Command and Actual positions.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5664
void Set(bool state)
Set the state of a Digital Output.
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11319
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
IO * IOGet(int32_t nodeNumber)
IOGet returns a pointer to an IO object using its node number and initializes its internals.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:762
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 StreamingOutputAdd(int32_t onMask, int32_t offMask, uint64_t address)
void StreamingOutputsEnableSet(bool enable)
Sets whether Streaming Output is enabled (true) or disabled (false).
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:105
@ RSIMotionTypePT
simple Position and Time algorithm
@ RSIActionNONE
None - do not perform any action.