############# # PLC multi-position motion sequence # # Motion parameters # var VEL := 2; var ACC := 3; var DEC := 3; var INTERMEDIATE_DWELL_TIME := 2; var DWELL_TIME := 12; var N_POS := 10; # number of calibrated measurement positions var MAX_CYCLES := 5; VAR myAxis : ax${AX_ID=1}; step : static.seqStep; cycles : static.cycleCounter; doMotion : static.doMotion; doMotionOld : static.doMotionOld; posIndex : static.posIndex; direction : static.direction; dwellCnt : static.dwellCnt; END_VAR var errorCode := 0; var intermediatePos := 0; var pos := 0; # -------------------------------------------------- # Initialization # -------------------------------------------------- if(${SELF}.firstscan){ step := 0; cycles := 0; posIndex := 0; direction := 1; dwellCnt := 0; }; # -------------------------------------------------- # Trigger start # -------------------------------------------------- if(doMotion and not(doMotionOld)){ println('PLC position sequence started'); step := 1; posIndex := 0; direction := 1; }; # -------------------------------------------------- # Position lookup # -------------------------------------------------- # For every posIndex, in forward and backward travel: # 1. Move to intermediatePos. # 2. Move to pos and measure/dwell only at pos. # intermediatePos is always smaller than pos. intermediatePos := 0; pos := 0; if(posIndex==0){intermediatePos:=0.8000;pos:=1.0000;} if(posIndex==1){intermediatePos:=10.6900;pos:=10.8900;} if(posIndex==2){intermediatePos:=20.5775;pos:=20.7775;} if(posIndex==3){intermediatePos:=30.4675;pos:=30.6675;} if(posIndex==4){intermediatePos:=40.3550;pos:=40.5550;} if(posIndex==5){intermediatePos:=50.2450;pos:=50.4450;} if(posIndex==6){intermediatePos:=60.1325;pos:=60.3325;} if(posIndex==7){intermediatePos:=70.0225;pos:=70.2225;} if(posIndex==8){intermediatePos:=79.9100;pos:=80.1100;} if(posIndex==9){intermediatePos:=89.8000;pos:=90.0000;} # -------------------------------------------------- # STEP 1 - move to intermediate position # -------------------------------------------------- if(step==1 and doMotion){ errorCode := mc_move_abs(${AX_ID=1},1,intermediatePos,VEL,ACC,DEC); if(errorCode){ println('mc_move_abs error:',errorCode); ${SELF}.error := errorCode; }; if(not(mc_get_busy(${AX_ID=1})) and myAxis.mon.attarget){ mc_move_abs(${AX_ID=1},0,intermediatePos,VEL,ACC,DEC); dwellCnt := 0; step := 2; println('Intermediate move done, index:',posIndex); }; }; # -------------------------------------------------- # STEP 2 - dwell at intermediate position # -------------------------------------------------- if(step==2 and doMotion){ dwellCnt := dwellCnt + 1; if(dwellCnt >= INTERMEDIATE_DWELL_TIME){ step := 3; }; }; # -------------------------------------------------- # STEP 3 - move to measurement position # -------------------------------------------------- if(step==3 and doMotion){ errorCode := mc_move_abs(${AX_ID=1},1,pos,VEL,ACC,DEC); if(errorCode){ println('mc_move_abs error:',errorCode); ${SELF}.error := errorCode; }; if(not(mc_get_busy(${AX_ID=1})) and myAxis.mon.attarget){ mc_move_abs(${AX_ID=1},0,pos,VEL,ACC,DEC); dwellCnt := 0; step := 4; println('Measurement position reached, index:',posIndex); }; }; # -------------------------------------------------- # STEP 4 - dwell at measurement position # -------------------------------------------------- if(step==4 and doMotion){ dwellCnt := dwellCnt + 1; if(dwellCnt >= DWELL_TIME){ posIndex := posIndex + direction; # reached end of list if(posIndex >= N_POS){ direction := -1; posIndex := N_POS - 2; }; # reached start of list if(posIndex < 0){ direction := 1; posIndex := 1; cycles := cycles + 1; println('Cycle completed:',cycles); if(cycles >= MAX_CYCLES){ println('Sequence completed'); doMotion := 0; step := 0; }; }; if(step<>0){ step := 1; }; }; }; doMotionOld := doMotion; # -------------------------------------------------- # Safety # -------------------------------------------------- if(not(myAxis.drv.enabled)){ return []; }; if(((not(ax1.mon.lowlim) or not(ax1.mon.highlim))) or errorCode){ mc_power(${AX_ID=1},0); println('Sequence ended by limit switch violation or errorcode:', errorCode); step := 0; ${SELF}.enable := 0; };