MDrive/MForce – Turntable program

Enter desired position in .01 deg (180 deg = 18000) into 'V1 variable (V1=18000) Execute program at address 1 (EX 1)

This program sets up a matrix to find distance and Direction 'It compares whether the Current Position is > than the Requested Position and Whether the requested move is '>180 deg.

 

'*****Turntable Program*****
'Find shortest route to absolute position

'Move < 180 deg AND CurPos>ReqPos = CCW
'Move < 180 deg AND CurPos<ReqPos = CW
'Move > 180 deg AND CurPos>ReqPos = CW
'Move > 180 deg AND CurPos<ReqPos = CCW

'****Variable Declarations****
Ms=180 'Set to 36000 steps/rev (.01 deg)
VA V1 'Requested Position Setpoint
VA V2 'Move Amount
VA V3 'Move Direction
VA V4
VA V5 'Final Move Setpoint
VA V6 'Current Pos VS Requested Pos Matrix value
VA V7 'Move Amount >180 deg Matrix value
VA V8 'Matrix Resolution Value

'****Program****
PG 1 ' Start program
LB L1
V2=P-V1 'Find the Move Distance
'PR "v2="v2
BR L2,V2<0 'Branch if Current Pos<Requested Pos
V6=1 'Set Matrix Value if CurPos>ReqPos

LB L3 'Move Routine
BR L5, V2>18000 'Branch if move is > 180 deg
V7=0 'Set Matrix Value if Move < 180 deg
LB L10
BR L8 'Branch to Matrix resolution
LB L6
V5=V3*V2 'Final Move = Distance*Polarity
MR V5 'Mave Move
CL L7 'Wait until Move Complete
P=V1 'Set Current Position to Absolute
BR L4 'Go to finish

LB L2 'Current Position>Requested Position
V2=V2*-1 'ABS Move distance
V6=0 'Set Matrix Value
BR L3 'Branch back to Move Routine

LB L5 'Shortest Distance Routine
V2=36000-V2 'Set Shortest distance if move > 180 deg
V7=1 ' Set >180 deg Matrix value
BR L10 ' Return to Move Routine

LB L8 'Matrix Resolution
V8=V6+V7 'Find sum of Matrix Values
BR L9,V8=1 'Branch if move should be CCW
V3=1 'Set move flag to be CW
BR L6 'Return to Move Routine

LB L9 'Set CCW Move
V3=-1 'Set move flag to be CCW
BR L6 'Return to Move Routine

LB L7 'Wait for Move Complete
H 10 '10ms Hold
BR L7, Mv=1 'Loop if still Moving
RT 'Return

LB L4 'Finish

E
PG


Download turntable.mxt file
(color-coded in IMS Terminal)

 

> Motion Control Code Index