#ClearOutput
k
opmode 2
#Var $unitsPos
#Var $TestCurrent
#Var $IntervalTime
#Var $Pos1
#Var $Pos2
#Var $CurrentVel
#Var $CurrnetMphase
#Var $MphaseMod ;for mphase mod 360
#Var $Increment
#Var $MaxVel
#Var $MphaseWinner
#Var $MaxFound
#Var $StopCondition
#Var $NegVelAfterMax
#Var $UpperCurrentLimit
#Var $Rounder ; for rounding procedure
;Check and save units
$unitsPos = unitsrotpos
#If $unitsPos == 1 UnitsOK
unitsrotpos 1
#Label UnitsOK
;intitalize Variables
$TestCurrent=micont * 0.025 ;2.5% of motor icont
$UpperCurrentLimit=10 * $TestCurrent ;limits the current level allowed by the
procedure;
;#Message $UpperCurrentLimit
$IntervalTime=250
$Increment=10
$MaxFound=0
$StopCondition=360
k
opmode 2
mphase 0
$CurrnetMphase=0
#Label Process
#Print TestingCurrent $TestCurrent
#Print IntervalTime $IntervalTime
#Print IncrementingBy $Increment
#While $CurrnetMphase < $StopCondition
; Modifying mphase to range of 0 - 359
$MphaseMod=$CurrnetMphase
#If $CurrnetMphase<=359 CheckNegativeMphase
$MphaseMod=$CurrnetMphase - 360
#Label CheckNegativeMphase
#If $CurrnetMphase>=0 AssignMphase
$MphaseMod=$CurrnetMphase + 360
#Label AssignMphase
;#Message $MphaseMod
mphase $MphaseMod
; Outputing current and meauring velocity in terms of position change
en
t $TestCurrent
$pos1=pfb
#Delay $IntervalTime
$pos2=pfb
;#Print $pos2
k
#Delay $IntervalTime
$CurrentVel=$pos2 - $pos1
#Print mphase $CurrentVel
$NegVelAfterMax=$CurrentVel * $MaxFound ;This Var will be negative only if max was
found and negative velocity was measured
#If $NegVelAfterMax < 0 BigIncrement
#If $CurrentVel <= $MaxVel KeepIncrement ;checking if maximum value exceeded
$MaxVel=$CurrentVel
$MphaseWinner=mphase
#Print NewMaxFound
$MaxFound=1
#Goto KeepIncrement ;jump over the big increment
#Label BigIncrement ;for when we encouter negative velocity first time after
finding best mphase
$CurrnetMphase=$CurrnetMphase + 180
#Goto ContinueProcess ; skeeping normal increment
#Label KeepIncrement
$CurrnetMphase=$CurrnetMphase + $Increment
#Label ContinueProcess
#End_While
#Label EndProcess
#If $MaxVel>10 ProccessSucceeded ;checking if current need to be increased
$MaxVel=0
$MphaseWinner=0
$MaxFound=0
$TestCurrent=$TestCurrent * 1.1 ;increasing current by 10%
#If $TestCurrent>$UpperCurrentLimit ProcedureFailed
#Print Increasing Current
$CurrnetMphase=0
#Goto Process
#Label ProccessSucceeded
#Print Proccess Done
#Print Winner $MphaseWinner
#If $Increment==5 Finished ;checking if this is the first or second round of
testing
$Increment=5 ;second round of testing with smaller
incremetns in mphase
$CurrnetMphase=$MphaseWinner - 10 ;start second test at winner - 10 degrees
$StopCondition=$MphaseWinner +15 ;stop second test at winner + 10 degrees
$MaxVel=0
$MaxFound=0
#Goto Process
#Label Finished
#Print Recommending $MphaseWinner
#Goto End
#Label ProcedureFailed
#Print Procedured Failed
#Label End
unitsrotpos $unitsPOs
mphase 0