MDrive MCodeLiberty* MCode - hMT On
MDrive Plus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 'MDRIVE DEMO PROGRAM 'Last modified 08/25/2016 'Sample test program for demonstration purposes only 'Not tested or verified for safety or any function 'Test routine for homing to a hard stop. 'Intended for sample purposes only 'The concept is to drive continually toward the hard stop while 'continually testing C2 for A lower value than previously 'found. That value, (not the final rest position), is 'the position of the hard stop. Then move A set distance from 'that position (since moving to the hard stop is impossible). 'Note: To change direction: 'Change sign on both slews 'Change BR G3, C2>=R1 to BR G3, C2<=R1 'Change MA R1-50 to MA R1+50 'Adjust parameter values to suit your particular systems needs. Ee=1 'Enable encoder mode (Best done early in code) Sm=1 'Set stall mode to keep running on a stall Rc=20 'use a good low value for run current Sf=22 'Set the stall factor PG 1 'Enter program mode R1=0 'Initialize R1 to zero R2=0 'Initialize R2 to zero R3=0 'Initialize R3 to zero LB G1 'Home to stop routine St=0 'Clear the stall flag Er=0 'Clear the error flag SL -300 'First find the stop at a good speed St=0 'Clear stall flag LB G2 'First loop PR St," Waiting for 1st Stall" 'Print status BR G2,St=0 'Repeat the first loop if no stall yet SL 0 'Slew to zero speed (stop) Er=0 'Clear the error flag SL -50 'Drive toward the stop slowly LB G3 'Loop start point R2=R2+1 'Increment counter PR St," 2nd Stall: Loop Count= ",R2 'Print status BR G4, R2>=30 'Exit the loop on count of 30 BR G3, C2>=R1 'Test for new lowest value R1=C2 'Store the lowest value found PR "New MAX/MIN reached R1=",R1 'Print status BR G3 'Repeat the loop LB G4 'Loop exit point SL 0 'Slew to zero speed (stop) St=0 'Clear the stall flag H 'Wait until motion completes PR "Last minimum R1=",R1 'Print status MA R1 + 50 'Move to a fixed offset from minimum H 'Wait until motion completes P 0 'Set postion to zero PR "At Home, 50 Counts from stop P=",P E 'End program PG 'Exit program mode |
Liberty MDrive Closed Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 'LIBERTY* DEMO PROGRAM 'Last modified 08/25/2016 'Sample test program for demonstration purposes only 'Not tested or verified for safety or any function '*** Parameters *** Vi=100000 'Set init vel A=4500000 'Accel and Decel D=A '*** Program *** PG 1 LB G1 mu=0,1 'Set makeup, clear LL reg. As=1 'Set AccuStep mode to fixed current LD=5000 'Lead Limit LG=5000 'Lag Limit Rc=20 'Use a low value of run current for hard stop Er=0 'Clear any errors SL -25000 'Slew in CCW direction LB K2 'User defined label H 100 'Hold 100mS BR Z1, Er=107 'Branch to Z1 if Lag Limit reached BR K2 'Branch to K2 LB Z1 'After error 107 occurs set position and do offset A=1000 'Change accel and decel D=A SL 0 'Slew to 0 H 100 'Delay Er=0 'Clear error P=0 'Reset position C1=0 'Reset counters C2=0 PR "Homing Complete" MA 51200 'Offset position one turn CW H 'Hold until motion complete PR "Offset Complete" E 'Program end PG |