***program start*** 100 '---------- Rover Move ------------ 110 gosub 10000 : ' init 115 out 16,1 120 AmountOfMove=7000:DirectionToMove=0:gosub 11000: ' Go straight 70mm 130 out 16,0 140 AmountOfMove=90000:DirectionToMove=1:gosub 11000: ' Turn right 90 degree 150 out 16,1 160 AmountOfMove=7000:DirectionToMove=3:gosub 11000: ' Go backwards 70mm 170 out 16,0 180 AmountOfMove=90000:DirectionToMove=1:gosub 11000: ' Turn right 90 degree 190 out 16,1 200 AmountOfMove=7000:DirectionToMove=0:gosub 11000: ' Go straight 70mm 210 out 16,0 220 AmountOfMove=90000:DirectionToMove=2:gosub 11000: ' Turn left 90 degree 230 out 16,1 240 AmountOfMove=7000:DirectionToMove=0:gosub 11000: ' Go straight 70mm 250 out 16,0 260 AmountOfMove=90000:DirectionToMove=2:gosub 11000: ' Turn left 90 degree 500 end 10000 '-------- StepperMotor Init ------------ 10010 ' 4 phase unipolar 10020 ' 2-2 excitation 10025 ' Right and left are set based on the direction of travel 10030 ' Left: 0:io0 - x 10040 ' 1:io1 - ~x 10050 ' 2:io2 - y 10060 ' 3:io3 - ~y 10070 ' Right:4:io4 - x 10080 ' 5:io5 - ~x 10090 ' 6:io6 - y 10095 ' 7:io7 - ~y 10100 ' 10110 dim PatternL[4],PatternR[4] 10120 PatternL[0]=10:PatternL[1]=11:PatternL[2]=1:PatternL[3]=0 10125 PatternR[0]=0:PatternR[1]=1:PatternR[2]=11:PatternR[3]=10 10130 return 11000 '--------------- Move Rover ----------------- 11005 ' input: DirectionToMove,AmountOfMove 11006 ' DirectionToMove 0-Go straight 11007 ' 1-Turn right 11008 ' 2-Turn left 11009 ' 3-Go backwards 11010 ' AmountOfMove When DirectionToMove 0 or 3 11011 ' Distance mm x 100 ex. 100mm -> 10000 11012 ' When DirectionToMove 1 or 2 11013 ' Angle degree x 1000 ex. 90degree->90000 11014 ' The rover moves 0.36mm by one step. 11015 ' The rover turns 0.536 degree by one step. 11020 if DirectionToMove=0 || DirectionToMove=3 then 11021 StepToMove=AmountOfMove/36 11022 else 11023 StepToMove=AmountOfMove/536 11024 end if 11230 for I=1 to StepToMove 11231 SS=I-I/4*4 11232 if DirectionToMove=0 then 11233 SSL=SS:SSR=SS 11234 else 11235 if DirectionToMove=1 then 11236 SSL=SS:SSR=3-SS 11237 else 11238 if DirectionToMove=2 then 11239 SSL=3-SS:SSR=SS 11240 else 11241 SSL=3-SS:SSR=3-SS 11242 endif 11243 endif 11244 end if 11250 PAT=PatternL[SSL] 11260 if PAT>=10 then out 0,1:out 1,0:PAT=PAT-10 else out 0,0:out 1,1 11270 if PAT>=1 then out 2,1:out 3,0 else out 2,0:out 3,1 11280 PAT=PatternR[SSR] 11290 if PAT>=10 then out 4,1:out 5,0:PAT=PAT-10 else out 4,0:out 5,1 11300 if PAT>=1 then out 6,1:out 7,0 else out 6,0:out 7,1 11305 sleep 10 11310 next 11340 return ***program end***