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");
40 const std::string SAMPLE_APP_NAME =
"Motion: Point-to-Point";
46 const int NUM_AXES = 1;
47 const int AXIS_INDEX = 0;
50 const double POSITION_0 = 0;
51 const double POSITION_1 = 0.5;
52 const double VELOCITY = 1;
53 const double ACCELERATION = 10;
54 const double DECELERATION = 10;
55 const double JERK_PERCENT = 50;
56 const double FINAL_VELOCITY = 0.5;
83 const int32_t TIMEOUT = 10000;
91 std::cout <<
"Absolute (Trapezoidal) Motion:" << std::endl;
92 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
93 axis->
MoveTrapezoidal(POSITION_1, VELOCITY, ACCELERATION, DECELERATION);
95 std::cout <<
"Motion Complete" << std::endl;
97 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
98 axis->
MoveTrapezoidal(POSITION_0, VELOCITY, ACCELERATION, DECELERATION);
100 std::cout <<
"Motion Complete\n" << std::endl;
105 std::cout <<
"Relative Motion:" << std::endl;
106 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
107 axis->
MoveRelative(POSITION_1 - POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
109 std::cout <<
"Motion Complete" << std::endl;
111 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
112 axis->
MoveRelative(POSITION_0 - POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
114 std::cout <<
"Motion Complete\n" << std::endl;
119 std::cout <<
"SCurve Motion:" << std::endl;
120 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
123 std::cout <<
"Motion Complete" << std::endl;
125 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
128 std::cout <<
"Motion Complete\n" << std::endl;
133 std::cout <<
"SCurve Motion with Final Velocity:" << std::endl;
134 std::cout <<
"Moving to position: " << POSITION_1 << std::endl;
135 std::cout <<
"Final Velocity: " << FINAL_VELOCITY << std::endl;
136 axis->
MoveSCurve(POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, FINAL_VELOCITY);
137 HelperAtVelocityWait(controller, axis, TIMEOUT);
138 std::cout <<
"Motion Complete" << std::endl;
140 std::cout <<
"Moving back to position: " << POSITION_0 << std::endl;
141 std::cout <<
"Final Velocity: " << 0 << std::endl;
142 axis->
MoveSCurve(POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, 0);
144 std::cout <<
"Motion Complete\n" << std::endl;
149 std::cout <<
"Velocity Move:" << std::endl;
150 std::cout <<
"Accelerating to velocity: " << VELOCITY << std::endl;
152 HelperAtVelocityWait(controller, axis, TIMEOUT);
153 std::cout <<
"Motion Complete" << std::endl;
155 std::cout <<
"Decelerating to velocity: " << 0 << std::endl;
157 HelperAtVelocityWait(controller, axis, TIMEOUT);
158 std::cout <<
"Motion Complete" << std::endl;
162 axis->
MoveTrapezoidal(POSITION_0, VELOCITY, ACCELERATION, DECELERATION);
170 catch (
const std::exception &ex)
172 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.
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 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.