Tutorial 3-4: Stopping motion

All motion commands can be stopped using the stop function for the motion command. For most motion functions, the stop function is Stop. Most motion functions can also be stopped with ExecQuickStop and ExecTimedStop.

How the axis is stopped depends on the motion command the axis is stopping from, the type of stop function that is called, and axis parameters. If the StartPos function is stopped using the basic Stop function, the axis will stop using the profile type and deceleration that was specified to the StartPos profile.

The following code executes a position command to a very large position, and stops the position command after five seconds.

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 motion to position 1000000
pos.target = 1000000;
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;
}

Sleep(5000); //Wait for 5 seconds

//Stop the position command
err = wmxlib_cm.motion->Stop(0);
if (err != ErrorCode::None) {
    wmxlib.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to stop motion. Error=%d (%s)\n", err, errString);
    goto exit;
}

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

../_images/WMXDOC_TUTORIAL_SEC3_image3.png