SMRamp

Description

The SMRamp library provides a clean interface for controlling stepper motors using ramp mode.

The interface supports basic motion control functionality such as powering, homing, basic moves, and reading back status information. This significantly reduces development time for motion applications using stepper motors.

Usage

The SMRamp functionality can be integrated into any project using a data structure and a function call.

Initialization

To use SMRamp, a SMR_Axis_typ variable must be declared and initialized. The variable should be initialized in the program INIT routine similar to the example shown below. This initialization consists of setting the configuration and initial motion parameters.

SMRAxis.IN.CFG.DisableAcyclicWrite := 0;
SMRAxis.IN.CFG.ModuleINADeviceName := 'IF6.ST1'; // This should be replace with your stepper module device name
SMRAxis.IN.CFG.MotorIndex := 1;

SMRAxis.IN.CFG.UnderCurrentDetection := 0;
SMRAxis.IN.CFG.ABRCtrSyncAsync := 0;
SMRAxis.IN.CFG.StallDetection := 0;

SMRAxis.IN.CFG.InvertDirection := 0;

SMRAxis.IN.CFG.SpeedEstimator.tf := 0;
SMRAxis.IN.CFG.SpeedEstimator.deadband := 0;
SMRAxis.IN.CFG.SpeedEstimator.K := 0;

SMRAxis.IN.PAR.HomingPosition := 0;
SMRAxis.IN.PAR.HomingMode := SMR_HOMEMODE_DIRECT;
SMRAxis.IN.PAR.HomingVelocity := REAL_TO_UINT(1 * SMR_RPM2VEL);
SMRAxis.IN.PAR.HomingStartDir := SMR_POS;
SMRAxis.IN.PAR.HomingEdgeSw := SMR_POS;
SMRAxis.IN.PAR.HomingTriggDir := SMR_POS;

SMRAxis.IN.PAR.Position := 0;
SMRAxis.IN.PAR.Direction := SMR_DIR_POS;
SMRAxis.IN.PAR.Velocity := REAL_TO_UINT(10 * SMR_RPM2VEL);
SMRAxis.IN.PAR.Acceleration := REAL_TO_UINT(100 * SMR_RPMPS2ACC);
SMRAxis.IN.PAR.Deceleration := REAL_TO_UINT(100 * SMR_RPMPS2ACC);

SMRAxis.IN.PAR.JogVelocity := REAL_TO_UINT(1 * SMR_RPM2VEL);

SMRAxis.IN.PAR.StopDeceleration := REAL_TO_UINT(100 * SMR_RPMPS2ACC);

The SMRAxis.IOMap structure must be mapped to the stepper module IO for the appropriate motor. The SMRAxis.IOMap naming matches the IO mapping names for a stepper module.

The IOMap structure also contains digital inputs for a home switch, limit switches, and a quick stop. These inputs are assumed to have the most common active levels. The home switch is active when TRUE (active high). The limit switches and quick stop are active when FALSE (active low). These inputs can be inverted on the input module to change their active levels.

Info

If no hardware switches are present, then the limit switch and quick stop inputs should be set to TRUE to allow motion.

Cyclic Operation

To control the axis, the SMR_AxisFn_Cyclic() function must be called in the CYCLIC routine of your program, once every scan, unconditionally. This function should not be called on the same SMRAxis variable more than once per scan.

SMR_AxisFn_Cyclic( SMRAxis );

The SMRAxis can then be used as an interface for higher level motion programs. The sample state machine below powers, homes, and then jogs a single axis.

Note

Variable and type declarations are not shown.

CASE State OF

	ST_IDLE:

		SMRAxis.IN.CMD.Power := FALSE;

		IF (Start) THEN

  			Start := FALSE;

  			IF (SMRAxis.OUT.STAT.DriveStatus.RdyToSwOn AND NOT SMRAxis.OUT.STAT.DriveStatus.SwOn) THEN

				State := ST_POWERON;

			END_IF

		END_IF
		
	ST_POWERON:
	
		SMRAxis.IN.CMD.Power := TRUE;
				
		IF (SMRAxis.OUT.STAT.DriveStatus.OpEnabled) THEN
  
			State := ST_HOME;
			
		END_IF
		
	ST_HOME:
	
		SMRAxis.IN.CMD.Home := TRUE;
		
		IF (SMRAxis.OUT.STAT.Done AND SMRAxis.OUT.STAT.DriveStatus.HomingOk) THEN
		
			SMRAxis.IN.CMD.Home := FALSE;
		
			State := ST_JOG;
			
		END_IF
	
	ST_JOG:
	
		SMRAxis.IN.CMD.JogForward := TRUE;
			
		IF (Stop) THEN
  			
			Stop := FALSE;
  			SMRAxis.IN.CMD.JogForward := FALSE;
		
			State := ST_IDLE;
			
		END_IF

END_CASE
Warning

The sample state machine above will prevent setting IN.CMD.Power in a watch window. You can use the test interface to override this behavior. See section below.

Reference

SMR_Axis_typ

The main data structure of the SMRamp library is the SMRAxis structure (SMR_Axis_typ). It is the interface for high level motion commands and outputs essential axis information. It is divided into inputs (SMRAxis.IN), outputs (SMRAxis.OUT), a test interface (SMRAxis.TEST), IO points (SMRAxis.IOMap) and internals (SMRAxis.Internal).

Inputs

The SMRAxis inputs are divided into commands (IN.CMD), parameters (IN.PAR), and configuration (IN.CFG). Commands initiate operations while parameters and configuration determine how the commands will be processed. Configuration variables are generally set once, while parameters might be set any time a command is issued.

Info

The SMRAxis.IN.CMD.Power must be left TRUE as long as the axis is powered.

Commands

  • Power - Power the axis. TRUE powers and FALSE depowers.
  • Home - Home the axis using the Homing parameters.
  • MoveAbsolute - Move to IN.PAR.Position.
  • MoveAdditive - Move additive by IN.PAR.Position. IN.PAR.Position is added to the current target position (NOT the current actual position).
  • MoveVelocity - Move at velocity. The axis accelerates to IN.PAR.Velocity and continues until another command is issued. To change velocity, the command must be toggled.
  • JogForward - Jog the axis forward. The axis will stop when this command is reset. Uses IN.PAR.JogVelocity.
  • JogReverse - Jog the axis backward. The axis will stop when this command is reset. Uses IN.PAR.JogVelocity.
  • TrackSetPosition - Track the input position. When set to TRUE, the axis will continuously move to the input position.
  • Stop - Stop the axis. When set to TRUE, all other motion commands will be ignored and the axis will remain stopped. Uses IN.PAR.StopDeceleration.
  • AcknowledgeError - Acknowledge any errors on the axis.
Info

Unless otherwise noted, motion commands use IN.PAR.Velocity, IN.PAR.Acceleration, and IN.PAR.Deceleration when doing a movement.

Parameters

  • HomingPosition - Actual position after homing the axis. All position parameters are in microsteps. The SMR_REV2POS constant can be used to convert from revolutions to microsteps. This constant assumes that the motor has 200 full steps per revolution. [microsteps]
  • HomingMode - Mode with which to home the axis. Possible values are SMR_HOMEMODE_DIRECT, SMR_HOMEMODE_SWITCH_GATE, SMR_HOMEMODE_ABS_SWITCH, and SMR_HOMEMODE_LIMIT_SWITCH. These homing modes replicate some of the homing modes possible via the acp10mc PLC Open motion control library. For details on these homing modes and the following homing parameters, please see the AS help for the MC_Home function block in the acp10mc library.
  • HomingVelocity - Velocity for homing moves. All velocity parameters are in microsteps/25ms. The SMR_RPM2VEL constant can be used to convert from RPM to microsteps/25ms. This constant assumes that the motor has 200 full steps per revolution. [microsteps/25ms]
  • HomingStartDir - Direction in which to start searching for the home switch. Possible values are SMR_POS and SMR_NEG.
  • HomingEdgeSw - Edge of the home switch to home to. Possible values are SMR_POS and SMR_NEG.
  • HomingTriggDir - Side of the home switch edge to home to. Possible values are SMR_POS and SMR_NEG.
  • Position - Position for MoveAbsolute, MoveAdditive, and TrackSetPosition. [microsteps]
  • Direction - Direction for MoveVelocity. Possible values are SMR_DIR_POS and SMR_DIR_NEG.
  • Velocity - Velocity for MoveAbsolute, MoveAdditive, MoveVelocity, and TrackSetPosition. [microsteps/25ms]
  • Acceleration, Deceleration - Acceleration and deceleration for MoveAbsolute, MoveAdditive, MoveVelocity, jogging, and TrackSetPosition. All acceleration parameters are in microsteps/25ms/25ms. The SMR_RPMPS2ACC constant can be used to convert from RPM/s to microsteps/25ms/25ms. This constant assumes that the motor has 200 full steps per revolution. [microsteps/25ms/25ms]
  • JogVelocity - Velocity for jogging. [microsteps/25ms]
  • StopDeceleration - Deceleration for stopping. [microsteps/25ms/25ms]

Configuration Settings

  • DisableAcyclicWrite - Specifies whether or not the Velocity, Acceleration, and Deceleration parameters should be written to the stepper module acyclically. If DisableAcyclicWrite is set to TRUE, these parameters cannot be changed during runtime, and must be set in the module IO configuration. If the stepper module is behind a bus controller, acyclic writes should be disabled. For more information on access to acyclic registers on IO modules, please see the help for the AsIOAcc library and the register description for the module in question. For modules behind bus controllers, please see the documentation for the bus controller you are using.
  • ModuleINADeviceName - INA device name of the stepper module. This is used to address the module during acyclic writes. The INA device name can be found by right clicking the stepper module in the Physical View and selecting Properties. The INA device name is listed as the Address in the resulting window. Alternatively, the IODBLib library can be used to look up the INA device name based on a connected IO point. For details on this, please see the documentation for the IODBLib library. If acyclic writes are disabled, then this parameter does not need to be set.
  • MotorIndex - Index of the motor to control. Possible values are 1 and 2, depending on which channel should be controlled (for X67SM4320 modules, please contact ARG for support). If acyclic writes are disabled, then this parameter does not need to be set.
  • UnderCurrentDetection - Enables under current detection when set to TRUE.
  • ABRCtrSyncAsync - Specifies which motor position should be reported. If set to FALSE, then the internal step counter is reported as the current position in microsteps; if set to TRUE, then a connected encoder position is reported as the current position in counts. Note, these units are hardly ever equivalent, so conversion will be required if the encoder position is reported. This may also cause issues with homing.
  • StallDetection - Enables motor stall detection when set to TRUE. Since stall detection requires configuration based on motor parameters, it is not recommended to enable this feature without appropriate cause and expertise.
  • InvertDirection - Inverts the motor rotation direction when set to TRUE. THIS SETTING SHOULD NOT BE CHANGED WHILE THE MOTOR IS POWERED, OR UNEXPECTED MOTION COULD RESULT!
  • SpeedEstimator - These settings configure the internal speed estimator used to report the current motor speed. If motor speed feedback is not desired, these parameters can be set to 0. Otherwise, they can be used to tune the response of the speed estimator. For details on these parameters, please see the documentation for the SpdEstLib library.

Outputs

The SMRAxis outputs contain status information (OUT.STAT).

  • ReadyForCMD - The SMRAxis is ready for a new command.
  • Busy - Operation is currently being processed.
  • Done - Operation completed successfully. Done is reset when the input command is reset.
  • Error - An error exists for the axis. Error is reset with the AcknowledgeError command.
  • ErrorID - Current error ID number.
  • ErrorString - Current error text.
  • ErrorState - State in which the error occurred.
  • ActualPosition - Current axis position. [microsteps or counts]
  • ActualVelocity - Current axis velocity. [microsteps/s or counts/s]
  • DriveStatus - Extended drive status information. See the ramp mode help for details.
  • State - Current axis state.
Info

Errors from the physical axis must be read off using the AsIOAcc library for non-X20 stepper modules.

Test Interface

The test interface gives direct access to axis commands and parameters, interrupting any commands from higher level programs. This allows for easy testing of the axis during machine commissioning or servicing. The test commands and parameters are intended for use in an Automation Studio watch window and SHOULD NOT BE SET IN PROGRAMS.

  • Enable - If set to TRUE, TEST.CMD and TEST.PAR take priority over IN.CMD and IN.PAR. If set to FALSE, then TEST.CMD and TEST.PAR are ignored.
  • CMD - Test commands. See above for a full list of commands.
  • PAR - Test parameters. See above for a full list of parameters.
  • STAT - A reduced set of status information that is always available whether test mode is enabled or not.

Error ID Numbers

  • 30190 - 30196 - These errors are passed on from the AsIOAcc library used to write to acyclic registers on the stepper module. Check that the ModuleINADeviceName and MotorIndex configuration settings are correct. If you are using an X67SM4320 module, please contact ARG for support. For further information, please see the AS online help.
  • 50000 - SMR_ERR_INVALIDPAR_ACC - Acceleration is 0.
  • 50001 - SMR_ERR_INVALIDPAR_DEC - Deceleration is 0.
  • 50002 - SMR_ERR_INVALIDPAR_STOPDEC - StopDeceleration is 0.
  • 50003 - SMR_ERR_INVALIDPAR_DIR - Direction is invalid. Valid values are SMR_DIR_POS and SMR_DIR_NEG.
  • 50004 - SMR_ERR_HOME_INVALIDPAR - One or more homing parameters are invalid.
  • 50005 - SMR_ERR_HOME_ERR - An error occurred while homing. Check wiring of switches and homing configuration.
  • 50006 - SMR_ERR_POSLIMSW - Positive limit switch is active. Movement in the positive direction is not allowed.
  • 50007 - SMR_ERR_NEGLIMSW - Negative limit switch is active. Movement in the negative direction is not allowed.