ABB Motion Contact Us  

Example MINT application

This MINT example demonstrates a simple tool changer which determines the shortest path to the next tool. The tool is selected from the digital inputs. The complete application description is available for download by clicking here.


' File Name: tool_picker.mnt 

' Description: 
' Example program showing how an axis may be used to move to a range 
' of discrete positions using the smallest move possible. 

'Constant declarations
Const _nNoOfTools = 12 'Number of tools in the machine
Const _nDistanceBetweenTools = 1000 'Distance between each tool (counts) 
Const _mkToolMask = 01111 'Mask for digital inputs 0-3

'Macro declarations
Define ipTrigger = INX.4 'Define the trigger input
Define opInMotion = OUTX.1 'Output for in motion flag to PLC

'Clear any outstanding errors and enable the drive

'Number of encoder counts per rev of the tool changer
ENCODERWRAP.0 = _nNoOfTools * _nDistanceBetweenTools

'Wait here in a loop to allow the program to run
  Pause ipTrigger              'Wait for a trigger to activate
  subPickTool IN & _mkToolMask 'Pick tool based on digital inputs 0-3
  Pause !ipTrigger             'Wait for trigger to deactivate
End Loop


'Place the drive configuration parameters here 
'This will be called on program start-up 

  SCALE = 1         'Assume scaling is in counts
  INPUTMODE = 0     'Setup the I/O - all level triggered
  HOMEINPUT.0 = 5   'The digital input used to mark the home position
  HOMESPEED.0 = 500
  HOMEBACKOFF.0 = 2 'Back-off at half the home speed

End Startup

'This subroutine serves two purposes, firstly to home the tool picker
'when a tool index of zero is supplied, and secondly to pick tools
'when supplied with a non-zero tool index.

Sub subPickTool(ByVal nToolIndex As Integer)
Dim nDistanceToMove

'Check that the tool index is within range
If nToolIndex > _nNoOfTools Then Exit Sub

opInMotion = 1 'Turn on the "in motion" signal

If nToolIndex = 0 Then

  Pause IDLE.0
  POS.0 = 0
  ENCODER.0 = 0


  nDistanceToMove = (nToolIndex * _nDistanceBetweenTools) - ENCODER.0

  'The required move distance need never be greater than half a
  'revolution, so add or subtract 1/2 a tool revolution

  If nDistanceToMove > (_nDistanceBetweenTools * _nNoOfTools) / 2 Then
     nDistanceToMove = _

          nDistanceToMove - (_nDistanceBetweenTools * _nNoOfTools)
  Else If nDistanceToMove < -(_nDistanceBetweenTools * _nNoOfTools) / 2 _

     nDistanceToMove = _

          nDistanceToMove + (_nDistanceBetweenTools * _nNoOfTools)
  End If

  'Perform a relative move to the tool location and wait for completion
  MOVER.0 = nDistanceToMove
End If

opInMotion = 0 'Turn off the "in motion" signal

End Sub 

'Onerror handler
'Should handle following errors, etc.

Event OnError
Print "Error ", Err, " on line ", Erl
End Event