The RMP Motion Controller APIs
MultiaxisMotion.cpp
1
22#include "rsi.h" // Import our RapidCode Library.
23#include "HelperFunctionsCpp.h" // Import our SampleApp helper functions.
24#include <conio.h>
25#include "SampleApps.h"
26
27using namespace RSI::RapidCode;
28
29/*This function will print all the results to the screen*/
31void PrintResult(Axis* axisX, Axis* axisY)
32{
33 printf("Motion Done \n AxisX position-> Commanded: %f \tActual: %f\n",
34 axisX->CommandPositionGet(),
35 axisX->ActualPositionGet());
36
37 printf(" AxisY position-> Commanded: %f \tActual: %f\n",
38 axisY->CommandPositionGet(),
39 axisY->ActualPositionGet());
40}
41
43int MultiaxisMotion::Run()
44{
45 /* CONSTANTS */
46 // *NOTICE* The following constants must be configured before attempting to run with hardware.
47
48 // Axis configuration parameters
49 const int AXIS_COUNT = 2;
50 const int AXIS_X = 0;
51 const int AXIS_Y = 1;
52
53 const int MOTION_COUNT = 1;
54
55 const double USER_UNITS = 1048576;
56
57 // Motion parameters
58 const double START_POSITION[AXIS_COUNT] = { 0, 0 };
59 const double END_POSITION[AXIS_COUNT] = { 1, 2 };
60 const double VELOCITY[AXIS_COUNT] = { 1, 2 };
61 const double ACCELERATION[AXIS_COUNT] = { 10, 20 };
62 const double DECELERATION[AXIS_COUNT] = { 10, 20 };
63 const double JERK_PERCENTAGE[AXIS_COUNT] = { 0, 0 };
64
65 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
66 USE_HARDWARE = false;
67
68 /* SAMPLE APP BODY */
69
70 // Create and initialize RsiController class
73
74 // Setup the controller for the appropriate hardware configuration.
75 if (USE_HARDWARE)
76 {
78 }
79 else
80 {
81 HelperFunctionsCpp::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_X, AXIS_Y });
82 }
83
84 try
85 {
86 // enable one MotionSupervisor for the MultiAxis
87 controller->MotionCountSet(controller->AxisCountGet() + 1);
88
89 // Get Axis X and Y respectively.
90 Axis* axisX = controller->AxisGet(AXIS_X);
92 axisX->UserUnitsSet(USER_UNITS);
93 axisX->PositionSet(0);
95
96 Axis* axisY = controller->AxisGet(AXIS_Y);
98 axisY->UserUnitsSet(USER_UNITS);
99 axisY->PositionSet(0);
101
102 // Initialize a MultiAxis, using the last MotionSupervisor.
103 MultiAxis* multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
105 multiAxisXY->AxisAdd(axisX);
106 multiAxisXY->AxisAdd(axisY);
107
108 // make sure all axes are enabled and ready
109 multiAxisXY->Abort();
110 multiAxisXY->ClearFaults();
111 multiAxisXY->AmpEnableSet(true);
112
113 // Set SYNC_START motion attribute mask.
115 printf("\nMotionStart...");
116
117 // Commanding motion using Syncpptart to start motion for both the axis at the same time.
118 multiAxisXY->MoveSCurve(END_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE);
119 multiAxisXY->MotionDoneWait();
120
121 // Calling function created on top.
122 PrintResult(axisX, axisY);
123
124 // Set SYNC_END motion attribute mask
126 printf("\nMotionStart...");
127
128 // Commanding motion using SyncEnd to end motion for both the axis at the same time.
129 multiAxisXY->MoveSCurve(START_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE);
130 multiAxisXY->MotionDoneWait();
131
132 // Calling function created on top
133 PrintResult(axisX, axisY);
134
135 printf("\nTrapezoidal Motion Done\n");
136
137 // Disable the all the axes
138 multiAxisXY->AmpEnableSet(false);
139 }
140 catch (RsiError const& err)
141 {
142 printf("\n%s\n", err.text);
143 return -1;
144 }
145 controller->Delete();
146 return 0;
147}
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.
double CommandPositionGet()
Get the current command position.
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.
double ActualPositionGet()
Get the current actual position.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5664
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:762
void MoveSCurve(const double *const position, const double *const vel, const double *const accel, const double *const decel, const double *const jerkPct)
Point-to-point S-Curve Move.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10564
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 MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:105
@ RSIActionNONE
None - do not perform any action.
@ RSIMotionAttrMaskSYNC_START
Synchronize start of motion for all axes.
@ RSIMotionAttrMaskSYNC_END
Synchronize end of motion for all axes.