APIs, concepts, guides, and more
SingleAxisSyncOutputs.cpp
1
22#include "rsi.h" // Import our RapidCode Library.
23#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
24#include "SampleApps.h"
25
26using namespace RSI::RapidCode; // Import the RapidCode namespace
27
29int SingleAxisSyncOutputs::Run()
30{
32 /* CONSTANTS */
33 // *NOTICE* The following constants must be configured before attempting to run with hardware.
34
35 // Axis configuration parameters
36 const int AXIS_COUNT = 1; // Specify how many axes you have.
37 const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
38
39 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)
40
41 // IO configuration parameters
42 const int NODE_INDEX = 0; // Specify which EtherCat Node will be used
43 const int OUTPUT_INDEX = 0;
44
45 const int OUTPUT_ENABLE_ID = 2; // The motion element ID at which to set the output
46 const int OUTPUT_DISABLE_ID = 3; // The motion element ID at which to set the output
47
48 // Motion parameters
49 const int TOTAL_POINTS = 4; // total number of points
50 const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
51 const double POSITIONS[] = { 0.25, 0.50, 0.75, 1.0 }; // These will be the streaming motion 5 positions.
52 const double TIMES[] = { 0.5, 1.0, 1.5, 2.0 }; // These will be the streaming motion 5 positions' time.
53
54 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
55 USE_HARDWARE = false;
56
57 // The rmpPath only needs to be set if the project directory is different than the rapid setup directory.
58 // *NOTICE* When setting the rmpPath, be sure to uncomment the rmpPath arguement in MotionController::CreateFromSoftware() in the Run() function.
59 char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
60
61 // Initialize MotionController class.
62 MotionController* controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
63 SampleAppsHelper::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
64
65 // Setup the controller for the appropriate hardware configuration.
66 if (USE_HARDWARE)
67 {
69 }
70 else
71 {
72 SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
73 }
74
75 try
76 {
77 Axis* axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
78 SampleAppsHelper::CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
79
80 axis->PositionSet(0); // Make sure motor starts at position 0 everytime.
81 axis->UserUnitsSet(USER_UNITS); // Change your user units.
82 axis->ErrorLimitActionSet(RSIAction::RSIActionNONE); // Set Error Limit Action.
83 axis->Abort(); // If there is any motion happening, abort it.
84 axis->ClearFaults(); // Clear faults.>
85 axis->AmpEnableSet(true); // Enable the motor.
86
87 // Set up the inputs
88 // Ensure the digital out is set low.
89 //IOPoint *output0 = IOPoint::CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
90 IOPoint* output0 = IOPoint::CreateDigitalOutput(controller->IOGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
91 output0->Set(false);
92
93 // Set up Sync Outputs
94 axis->StreamingOutputsEnableSet(true); // Enable streaming output.
95
96 // ENABLE the Sync Output(s)
97 axis->StreamingOutputAdd(output0, true, OUTPUT_ENABLE_ID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
98 axis->StreamingOutputAdd(output0, false, OUTPUT_DISABLE_ID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
99
100 // DISABLE the Sync Output(s)
101 //axis->StreamingOutputAdd(output0, false, outPutEnableID);
102
103 axis->MovePT(RSIMotionType::RSIMotionTypePT, POSITIONS, TIMES, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
104 printf("Motion started. Waiting to complete.\n");
105
106 axis->MotionDoneWait(); // What for Streaming Motion to be done.
107 printf("Motion Complete. The outputs should have been set\n");
108
109 axis->StreamingOutputsEnableSet(false); // Disable Sync Outputs.
110 axis->AmpEnableSet(false); // Disable the motor.
111
112 }
113 catch (RsiError const& err)
114 {
115 printf("%s\n", err.text); // If there are any exceptions/issues this will be printed out.
116 return -1;
117 }
118 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
119 return 0;
121}
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:5549
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:10964
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: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 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:107
@ RSIMotionTypePT
Position-Time algorithm with continuous position but discontinuous velocity. Best for short time inte...
@ RSIActionNONE
None - do not perform any action.
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.