#include <cmath>
#include "SampleAppsHelper.h"
#include "rsi.h"
{
const int WAIT_SAMPLES = 100;
int samplesWaited = 0;
while (axis->
StatusBitGet(RSIEventType::RSIEventTypeMOTION_AT_VELOCITY) == 0)
{
samplesWaited += WAIT_SAMPLES;
if (samplesWaited > timeout)
{
throw std::runtime_error("Timeout waiting for motion to reach velocity");
}
}
}
int main()
{
const std::string SAMPLE_APP_NAME = "Motion: Point-to-Point";
const double POSITION_0 = 0;
const double POSITION_1 = 0.5;
const double VELOCITY = 1;
const double ACCELERATION = 10;
const double DECELERATION = 10;
const double JERK_PERCENT = 50;
const double FINAL_VELOCITY = 0.5;
int exitCode = -1;
try
{
const int32_t TIMEOUT = 10000;
std::cout << "Absolute (Trapezoidal) Motion:" << std::endl;
std::cout << "Moving to position: " << POSITION_1 << std::endl;
std::cout << "Motion Complete" << std::endl;
std::cout << "Moving back to position: " << POSITION_0 << std::endl;
std::cout << "Motion Complete\n" << std::endl;
std::cout << "Relative Motion:" << std::endl;
std::cout << "Moving to position: " << POSITION_1 << std::endl;
axis->
MoveRelative(POSITION_1 - POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
std::cout << "Motion Complete" << std::endl;
std::cout << "Moving back to position: " << POSITION_0 << std::endl;
axis->
MoveRelative(POSITION_0 - POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
std::cout << "Motion Complete\n" << std::endl;
std::cout << "SCurve Motion:" << std::endl;
std::cout << "Moving to position: " << POSITION_1 << std::endl;
std::cout << "Motion Complete" << std::endl;
std::cout << "Moving back to position: " << POSITION_0 << std::endl;
std::cout << "Motion Complete\n" << std::endl;
std::cout << "SCurve Motion with Final Velocity:" << std::endl;
std::cout << "Moving to position: " << POSITION_1 << std::endl;
std::cout << "Final Velocity: " << FINAL_VELOCITY << std::endl;
axis->
MoveSCurve(POSITION_1, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, FINAL_VELOCITY);
HelperAtVelocityWait(controller, axis, TIMEOUT);
std::cout << "Motion Complete" << std::endl;
std::cout << "Moving back to position: " << POSITION_0 << std::endl;
std::cout << "Final Velocity: " << 0 << std::endl;
axis->
MoveSCurve(POSITION_0, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, 0);
std::cout << "Motion Complete\n" << std::endl;
std::cout << "Velocity Move:" << std::endl;
std::cout << "Accelerating to velocity: " << VELOCITY << std::endl;
HelperAtVelocityWait(controller, axis, TIMEOUT);
std::cout << "Motion Complete" << std::endl;
std::cout << "Decelerating to velocity: " << 0 << std::endl;
HelperAtVelocityWait(controller, axis, TIMEOUT);
std::cout << "Motion Complete" << std::endl;
exitCode = 0;
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
return exitCode;
}
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.
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.