Relative move
The way Relative moves an axis is "distance." You decide the distance your axis moves. The starting point is the axis' current position, and the distance is how far your axis moves.
Functions
MoveAxisRelative: moves an axis a specified distance.
MoveAxisContinuousRelative: moves an axis a specified distance. After that, the axis keeps moving using the EndVelocity.
WaitForCommand: waits for a command to be finished.
GetAnAxisPosition: displays the set and actual positions of an axis. For further details, see Get and set values.
MoveAxisRelative
MoveAxisRelative moves an axis from the starting point. The axis stops after it travels the specified distance.
Starting point: this is where your axis is now. It is zero.
Distance: the relative distance your axis travels. It is 10000.
Notice the following parameters:
Distance: the distance an axis travels.
Code
In SingleAxisMotion.cpp
, add the following code:
MoveAxisRelative
VOID MoveRelative(int Index, double Distance)
{
RtPrintf("Make a relative move.\n\n");
//Start a relative move.
KsCommandStatus status = WaitForCommand(30, TRUE, MoveAxisRelative(Index, Distance,
MAXIMUM_VELOCITY, MAXIMUM_ACCELERATION, MAXIMUM_DECELERATION, MAXIMUM_JERK, mcAborting));
if (status.Error)
RtPrintf("MoveAxisRelative failed: %d\n", status.ErrorId);
//Wait a few cycles to get the correct end positions.
Sleep(5);
RtPrintf("End position:\n");
GetAnAxisPosition(Index);
}
MoveAxisContinuousRelative
MoveAxisContinuousRelative is the function that makes a continuous relative move, for which an axis continues to travel using the end velocity after it travels the specified distance. Since MoveAxisContinuousRelative keeps moving an axis, you need to use HaltAxis or StopAxis to stop its move. For more information about how to stop an axis, see Stop a movement.
Notice the following parameters:
- Distance: the distance an axis travels.
- EndVelocity: the end velocity. If EndVelocity is less than Velocity, the axis will use EndVelocity to move after the commanded distance has been traveled; if EndVelocity is greater than Velocity, the axis will use Velocity to move.
Code
In SingleAxisMotion.cpp
, add the following code. Notice that we don't use WaitForCommand for MoveAxisContinuousRelative. If you use it, MoveAxisContinuousRelative will act like MoveAxisRelative because the axis won't keep moving after it reaches the target. To stop a continuous move, we use HaltAxis, which is written in another function. See Stop a movement > Normal stop.
MoveAxisContinuousRelative
VOID MoveContinuousRelative(int Index, double Distance)
{
RtPrintf("Make a continuous relative move.\n\n");
//Start a continuous relative move.
KsCommandStatus status = MoveAxisContinuousRelative(Index, Distance, MAXIMUM_VELOCITY,
END_VELOCITY, MAXIMUM_ACCELERATION, MAXIMUM_DECELERATION, MAXIMUM_JERK, mcAborting);
if (status.Error)
RtPrintf("MoveContinuousRelative failed: %d\n", status.ErrorId);
Sleep(6000);
RtPrintf("End position:\n");
GetAnAxisPosition(Index);
}
Output:
MoveAxisRelative Distance: 9000
MoveAxisContinuousRelative Distance: 11000
We reset the starting position to zero after MoveAxisRelative is completed. For MoveAxisContinuousRelative, an axis continues to move after it travels the distance, so the end position is not the same as the distance.