Tutorial 3-1: Absolute and relative motion
Many motion functions allow the target position to be specified as an absolute position or a relative position. When the target is specified as an absolute position, the axis command position will change to the specified position in the coordinates of the axis.
When the target is specified as a relative position, the axis command position will increase by the specified distance. If the motion is an override motion, the target position will become the target position of the current motion plus the specified distance.
The following code demonstrates the difference between absolute and relative position commands:
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 absolute position command to 10000
pos.target = 10000;
err = wmxlib_cm.motion->StartPos(&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);
//Execute relative position command of 10000
pos.target = 10000;
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);
After the above code is executed, the axis will move to position 10000, and then to position 20000.
The position and velocity plots of the axis during this motion are shown below.
