'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 S