Tutorial 3-2: Motion profiles

Most motion functions require a motion profile input to be specified. The motion profile determines the shape of the velocity, acceleration, and jerk as an axis moves from its current position to the target position.

The most basic type of motion profile is the Trapezoidal profile. In this profile, the axis accelerates at a constant rate until the velocity becomes equal to the target velocity. When the axis approaches the target position, the axis starts to decelerate at a constant rate at a timing that allows the axis to stop exactly at the target.

The Trapezoidal profile requires the velocity, acceleration, and deceleration inputs. The starting velocity and end velocity may optionally be specified (0 indicates no starting velocity or end velocity; the constructor of the Profile class automatically initializes these values to 0).

Other available profile types and their required inputs may be found at Motion Profiles.

The following code executes a trapezoidal profile and a S-curve profile.

Motion::PosCommand pos;

//Set position command parameters
pos.axis = 0;
pos.profile.type = ProfileType::Trapezoidal;
pos.profile.velocity = 10000;
pos.profile.acc = 10000;
pos.profile.dec = 10000;

//Execute trapezoidal profile
pos.target = 20000;
err = wmxlib_cm.motion->StartMov(&pos);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to execute motion. Error=%d (%s)\n", err, errString);
    goto exit;
}

//Block execution until motion is finished
err = wmxlib_cm.motion->Wait(0);

//Change profile to S-curve
pos.profile.type = ProfileType::SCurve;

//Execute S-curve profile
pos.target = 20000;
err = wmxlib_cm.motion->StartMov(&pos);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to execute motion. Error=%d (%s)\n", err, errString);
    goto exit;
}

//Block execution until motion is finished
err = wmxlib_cm.motion->Wait(0);

The position and velocity plots of the axis during this motion are shown below.

../_images/WMXDOC_TUTORIAL_SEC3_image1.png