Tutorial 3-7: Axis modes

A servo axis is commonly controlled by sending a position command to the servo every communication cycle. During each cycle, the axis will attempt to move to the specified target position.

It is also possible to control an axis by sending a velocity command or torque command to the servo every communication cycle. During each cycle, the axis will attempt to move at the specified velocity or output the specified amount of torque.

The Axis Command Mode parameter determines the command mode of the axis. Axes in Velocity command mode may execute functions in the Velocity class and axes in Torque command mode may execute functions in the Torque class.

The Axis Command Mode may be changed with functions such as SetAxisCommandMode and SetAxisParam.

The following code sets an axis to velocity mode and executes a velocity command, and then sets an axis to torque mode and executes a torque command.

Velocity::VelCommand vel;
Torque::TrqCommand trq;

//Set axis to velocity command mode
err = wmxlib_cm.axisControl->SetAxisCommandMode(0, AxisCommandMode::Velocity);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to set axis command mode to velocity. Error=%d (%s)\n", err, errString);
    goto exit;
}

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

//Execute a velocity command
err = wmxlib_cm.velocity->StartVel(&vel);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to execute velocity command. Error=%d (%s)\n", err, errString);
    goto exit;
}

Sleep(2000); //Wait for 2 seconds

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

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

//Set axis to torque command mode
err = wmxlib_cm.axisControl->SetAxisCommandMode(0, AxisCommandMode::Torque);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to set axis command mode to torque. Error=%d (%s)\n", err, errString);
    goto exit;
}

//Set torque command parameters
trq.axis = 0;
trq.torque = 100;

//Execute a torque command
err = wmxlib_cm.torque->StartTrq(&trq);
if (err != ErrorCode::None) {
    wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
    printf("Failed to execute torque command. Error=%d (%s)\n", err, errString);
    goto exit;
}

Sleep(2000); //Wait for 2 seconds

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