Click or drag to resize

11.2 Stepper Motor Control

The SP-ICE-3 Card supports up to 4 stepper motors using step and direction inputs.

Motor movements can be made either in synchronism with list execution, by using Motor List Commands, or asynchronously, by using the RAYLASE.SPICE3.ClientLibMotorAPI.

Configuration

For each of the four supported stepper motors, the SP-ICE-3 Card provides two output and two input pins on both Port A and Port B connectors. The input pins on Port C can also be used.

  • The output pins provide step and direction signals.

  • A limit sensor and either a home sensor or a second limit sensor can be connected to the input pins.

  • The correct functions must be mapped to the pins in order to use them for stepper motor control. Please see 10.4.2 GPIO Port Configuration Procedures for details of how to configure the ports correctly.

Basic configuration for each motor axis can be set up using the MotorConfig.
Further configuration can be performed by setting properties of the MotorVariables directly, or by using the appropriate Motor List Commands.

Origins and Ordinates
Machine Origin

The origin of the machine ordinates for an axis.

Immediately after booting, the machine origin is simply the current position of the axis.

After homing the axis, the machine origin is at the mechanically fixed position defined by the Home Sensor.

User Origin

The origin of the user ordinates which are used when specifying positions in MotorAPI calls and List Commands.

The user origin is defined relative to the Machine Origin by the value of MotorAxisVariablesOriginPosition, which may be zero (meaning that the machine and user origins are coincident.)

Limits

The SP-ICE-3 Card allows use of Hard Limits and Soft Limits for each axis.

Soft limits can be specified with MotorAxisParameterSetMinimumSoftLimit and MotorAxisParameterSetMaximumSoftLimit.

  • Attempting a move to a position outside the limits will result in an error, and the move will not be performed.

  • Soft limit positions are relative to the Machine Origin.

  • Please make sure that the current motor axis position is inside the soft limits before enabling them.

For hard limits, a maximum of two limit sensors per axis can be used.

  • When using a hard limit, movement will be stopped if a limit sensor is triggered.

  • To resume movement:

    1. The alarm must be cleared by calling MotorAPIClearAlarm.

    2. If the axis has come to rest beyond the sensor's trigger range, the sensor must be temporarily disabled in the MotorConfig in order to move back to a position that is inside the hard limit without re-triggering the sensor.

Homing

Homing can be performed by executing MotorAPIHome after setting HomingMethod appropriately to select the current axis position, or a home sensor, or a limit sensor.

When using the current position for homing, the Machine Origin for the axis is simply set at the current position.

For homing at a sensor, the search procedure works as follows:

  1. If either HomingMethodMinimumHome or HomingMethodMinimumLimit is specified, the search is initially made in the positive direction; otherwise, initially in the negative direction.

  2. The search starts by driving the axis in the initial direction at HomingFastSpeed until the sensor is triggered; if the maximum distance is exceeded before the trigger occurs, an exception is thrown.

  3. Then the axis is backed off the sensor using the HomingFastSpeed until the sensor is no longer triggered.

  4. Now the axis is driven in the initial direction again, this time using the HomingSlowSpeed, and also until the sensor is triggered.

  5. At this point the home trigger position has been identified.

    Note  Note
    • Even at HomingSlowSpeed, the axis cannot stop instantly, and will generally have come to rest just beyond the mechanical trigger point.

    • When using a limit sensor for homing, it is particularly important to ensure that the axis is left at a position which is not beyond that limit.

    In both cases the axis can be moved, if required, to a position within the limits in the final step of the homing procedure. This position is specified by setting a suitable HomeOffset.

  6. The Home method allows the caller to choose between:

    • Simply searching for the home position sensor, without affecting the axis origin.

      It may be desirable to do this, for instance, in order to check the mechanical stability of the sensor itself.

      • In this case, the whole homing procedure is finished at this point.

    • Using the discovered home position to define the Machine Origin of the axis.

      • After that, the axis is moved to the position specified by HomeOffset.

Homing must be started independently for each axis, but it is possible to start homing a further axis before the previous one has finished.

Moving

Moves can be performed using control commands (MotorAPI) or list commands.

Movement using list commands has the advantage of being synchronized with the movement of the scan head mirrors.
Note, however, that execution of the list can be finished before movement of the motor axes has completed, if the movement takes longer than the marking.

Moves can be performed independently by each axis, in which case the corresponding velocity and acceleration of each individual axis are used for the moves.

Synchronized movements, where all axes start and stop moving at the same time, are also possible by using the appopriate control and list commands.

  • In this case the common CoordinatedVelocity and CoordinatedAcceleration are used instead of the per-axis values.

    The coordinated velocity is then the maximum possible for any axis, but the velocity of a particular axis may be slower in order to arrive on the target position at the same time as the others.

Example

The following example shows how configuration of the motor axes can be performed by an application program, and how homing and moving (using a control and a list command) works.

Motor API usage.
using ( ClientAPI client = new ClientAPI( cardIP ) )
{
    client.System.ResetToDefaults();

    MotorAxis axis = MotorAxis.M0;

    MotorConfig motorConf = new MotorConfig();
    motorConf.Axes[0].UnitsPerStep = 1;
    motorConf.Axes[0].MinimumVelocity = 0;
    motorConf.Axes[0].EnableLimitSensor = true;
    motorConf.Axes[0].StepWidth = 1;
    client.Motor.SetConfig( motorConf );

    MotorVariables motorVar = new MotorVariables();
    motorVar.Axes[0].Acceleration = 0.25 * 1e-6;
    motorVar.Axes[0].Velocity = 0.1 * 1e-5;
    motorVar.Axes[0].HomingMethod = HomingMethod.MinimumHome;
    motorVar.Axes[0].HomingAcceleration = 0.25 * 1e-6;
    motorVar.Axes[0].HomingFastSpeed = 0.1 * 1e-5;
    motorVar.Axes[0].HomingSlowSpeed = 0.4 * 1e-6;
    motorVar.Axes[0].OriginPosition = 10;
    client.Motor.SetVariables( motorVar );

    // Configuration of pins for Motor0 on PortA
    PortConfig portA = client.Gpio.GetConfig().Ports[IOPort.PortA];
    portA.IOLevel = IOVoltage.ThreePointThree;
    portA.Directions[0] = IODirection.Output; // First 8 pins of PortA as Input
    portA.Directions[1] = IODirection.Input; // Seconf 8 pins of PortA as Output

    portA.Functions[0] = 2; // Motor0 Direction
    portA.Functions[1] = 2; // Motor0 Step
    portA.Polarities[0] = Polarity.ActiveHigh;
    portA.Polarities[1] = Polarity.ActiveHigh;

    portA.Functions[8] = 2; // Motor0 Home Sensor
    portA.Functions[9] = 2; // Motor0 Limit Sensor
    portA.Polarities[8] = Polarity.ActiveHigh;
    portA.Polarities[9] = Polarity.ActiveHigh;

    GpioConfig gpio = new GpioConfig();
    gpio.Ports.Add( IOPort.PortA, portA );
    client.Gpio.SetConfig( gpio );

    if ( client.Motor.HasAlarm( axis ) )
        client.Motor.ClearAlarm( axis );

    // Since HomingMethod is set to MinimumHome, the home sensor will be
    // searched by moving into negative direction for a maximum of 1000 units.
    // If the sensor is not triggered before the maximum distance is reached,
    // an exception will be thrown.
    client.Motor.Home( axis, HomeInput.Home, 1000, true );

    MotorAxis? doneAxis;
    client.Motor.WaitForHomeDone( out doneAxis, 20000 );
    if ( doneAxis != axis )
        throw new ExecutionException( "Unexpected axis!" );

    // Moving using a control command
    client.Motor.MoveAbs( axis, 500 );

    client.Motor.WaitForMoveDone( out doneAxis, 10000 );
    if ( doneAxis != axis )
        throw new ExecutionException( "Unexpected axis!" );

    // Moving using a list command
    int listId = 123;
    CommandList list = new CommandList();
    list.AppendMotorMoveRel( axis, -200 );
    client.List.Set( listId, list );
    client.List.Execute( listId );

    int? doneId;
    client.List.WaitForListDone( out doneId );
    if ( doneId != listId )
        throw new ExecutionException( "Unexpected list!" );

    client.Motor.WaitForMoveDone( out doneAxis );
    if ( doneAxis != axis )
        throw new ExecutionException( "Unexpected axis!" );
}
See Also