14#include "SampleAppsHelper.h"
23 const int WAIT_SAMPLES = 100;
25 int samplesWaited = 0;
26 while (axis->
StatusBitGet(RSIEventType::RSIEventTypeMOTION_AT_VELOCITY) == 0)
29 samplesWaited += WAIT_SAMPLES;
30 if (samplesWaited > timeout)
32 throw std::runtime_error(
"Timeout waiting for motion to reach velocity");
39 const std::string SAMPLE_APP_NAME =
"Motion: Point-to-Point";
47 const double POSITION_0 = 0;
48 const double POSITION_1 = 0.5;
49 const double VELOCITY = 1;
50 const double ACCELERATION = 10;
51 const double DECELERATION = 10;
52 const double JERK_PERCENT = 50;
53 const double FINAL_VELOCITY = 0.5;
80 const int32_t TIMEOUT = 10000;
88 std::cout <<
"Absolute (Trapezoidal) Motion:" << std::endl;
89 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
90 axis->
MoveTrapezoidal(POSITION_1, VELOCITY, ACCELERATION, DECELERATION);
92 std::cout <<
"Motion Complete" << std::endl;
94 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
95 axis->
MoveTrapezoidal(POSITION_0, VELOCITY, ACCELERATION, DECELERATION);
97 std::cout <<
"Motion Complete\n" << std::endl;
102 std::cout <<
"Relative Motion:" << std::endl;
103 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
104 axis->
MoveRelative(POSITION_1 - POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
106 std::cout <<
"Motion Complete" << std::endl;
108 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
109 axis->
MoveRelative(POSITION_0 - POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
111 std::cout <<
"Motion Complete\n" << std::endl;
116 std::cout <<
"SCurve Motion:" << std::endl;
117 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
120 std::cout <<
"Motion Complete" << std::endl;
122 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
125 std::cout <<
"Motion Complete\n" << std::endl;
130 std::cout <<
"SCurve Motion with Final Velocity:" << std::endl;
131 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
132 std::cout <<
"Final Velocity: " << FINAL_VELOCITY << std::endl;
133 axis->
MoveSCurve(POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, FINAL_VELOCITY);
134 HelperAtVelocityWait(controller, axis, TIMEOUT);
135 std::cout <<
"Motion Complete" << std::endl;
137 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
138 std::cout <<
"Final Velocity: " << 0 << std::endl;
139 axis->
MoveSCurve(POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, 0);
141 std::cout <<
"Motion Complete\n" << std::endl;
146 std::cout <<
"Velocity Move:" << std::endl;
147 std::cout <<
"Accelerating to velocity: " << VELOCITY << std::endl;
149 HelperAtVelocityWait(controller, axis, TIMEOUT);
150 std::cout <<
"Motion Complete" << std::endl;
152 std::cout <<
"Decelerating to velocity: " << 0 << std::endl;
154 HelperAtVelocityWait(controller, axis, TIMEOUT);
155 std::cout <<
"Motion Complete" << std::endl;
159 axis->
MoveTrapezoidal(POSITION_0, VELOCITY, ACCELERATION, DECELERATION);
167 catch (
const std::exception &ex)
169 std::cerr << ex.what() << std::endl;
void MoveVelocity(double velocity)
void MoveTrapezoidal(double position, double vel, double accel, double decel)
Point-to-point trapezoidal move.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
void MoveSCurve(double position, double vel, double accel, double decel, double jerkPct)
Command a point-to-point S-Curve motion.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
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 * Create()
Initialize and start the RMP EtherCAT controller.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
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...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
int32_t MotionDoneWait()
Waits for a move to complete.
bool StatusBitGet(RSIEventType bitMask)
Return the state of a status bit.
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.
static constexpr int AXIS_COUNT
Number of axes to configure on the controller.
static constexpr int AXIS_X_INDEX
Index of the first axis to use in the sample apps.