版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
15CUSTOMMACRO
15.1VARIABLES15.2SYSTEMVARIABLES15.3ARITHMETICANDLOGICOPERATION15.4MACROSTATEMENTSANDNCSTATEMENTS15.5BRANCHANDREPETITION15.6MACROCALL
Althoughsubprogramsareusefulforrepeatingthesameoperation,thecustommacrofunctionalsoallowsuseofvariables,arithmeticandlogicoperations,andconditionalbranchesforeasydevelopmentofgeneralprogramssuchaspocketinganduserdefinedcannedcycles.Amachiningprogramcancallacustommacrowithasimplecommand,justlikeasubprogram.Fig.15.0Custommacro15.1VARIABLES
AnordinarymachiningprogramspecifiesaGcodeandthetraveldistancedirectlywithanumericvalue;examplesareG100andX100.0.
Withacustommacro,numericvaluescanbespecifieddirectlyorusingavariablenumber.Whenavariablenumberisused,thevariablevaluecanbechangedbyaprogramorusingoperationsontheMDIpanel.#1=#2+100;
G01X#1F300;Explanation·Variablerepresentation
Whenspecifyingavariable,specifyanumbersign(#)followedbyavariablenumber.Personalcomputersallowanametobeassignedtoavariable,butthiscapabilityisnotavailableforcustommacros.[Example]#1
Anexpressioncanbeusedtospecifyavariablenumber.Insuchacase,theexpressionmustbeenclosedinbrackets.[Example]#[#1+#2-12]
·Typesofvariables
Variablesareclassifiedintofourtypesbyvariablenumber.NOTE
Commonvariables#150to#199and#532to#999areoptional.·Rangeofvariablevalues
Localandcommonvariablescanhavevalue0oravalueinthefollowingranges:
-10E47to-10E-29
10E-29to10E47
Iftheresultofcalculationturnsouttobeinvalid,anP/SalarmNo.111isissued.
·Omissionofthedecimalpoint
Whenavariablevalueisdefinedinaprogram,thedecimalpointcanbeomitted.[Example]
When#1=123;isdefined,theactualvalueofvariable#1is123.000.·Referencingvariables
Toreferencethevalueofavariableinaprogram,specifyawordaddressfollowedbythevariablenumber.Whenanexpressionisusedtospecifyavariable,enclosetheexpressioninbrackets.[Example]G01X[#1+#2]F#3;
Areferencedvariablevalueisautomaticallyroundedaccordingtotheleastinputincrementoftheaddress.[Example]
WhenG00X#1;isexecutedona1/1000mmCNCwith12.3456assignedtovariable#1,theactualcommandisinterpretedasG00X12.346;.
Toreversethesignofareferencedvariablevalue,prefixaminussign(-)to#.[Example]G00X-#1;
Whenanundefinedvariableisreferenced,thevariableisignoreduptoanaddressword.[Example]
Whenthevalueofvariable#1is0,andthevalueofvariable#2isnull,executionofG00X#1Y#2;resultsinG00X0;.·Commoncustommacrovariablesfortowpaths(twopathcontrol)
Fortwopathcontrol,macrovariablesareprovidedforeachpath.Somecommonvariables,however,canbeusedforbothpaths,bysettingparametersNo.6036and6037accordingly.·Undefinedvariable
Whenthevalueofavariableisnotdefined,suchavariableisreferredtoasa“null”variable.Variable#0isalwaysanullvariable.Itcannotbewrittenin,butitcanberead.
Ⅰ.Quotation
Whenanundefinedvariableisquotated,theaddressitselfisalsoignored.[Example]When#1is0and#2isnull,theresultofexecutingG00X#1Y#2;willbethesameaswhenG00X0;isexecuted.
Ⅱ.Operation<vacant>isthesameas0exceptwhenreplacedby<vacant>Ⅲ.Conditionalexpressions<vacant>differsfrom0onlyforEQandNEFig.15.1VariablesonCRTpage
(ⅰ)Whenthevalueofavariableisblank,thevariableisnull.
(ⅱ)Themark********indicatesanoverflow(whentheabsolutevalueofavariableisgreaterthan99999999)oranunderflow(whentheabsolutevalueofavariableislessthan0.0000001).Limitations
Programnumbers,sequencenumbers,andoptionalblockskipnumberscannotbereferencedusingvariables.[Example]Variablescannotbeusedinthefollowingways:
O#1;
/#2G00X100.0;
N#3Y200.0;15.2SYSTEMVARIABLES
SystemvariablescanbeusedtoreadandwriteinternalNCdatasuchastoolcompensationvaluesandcurrentpositiondata.Note,however,thatsomesystemvariablescanonlyberead.Systemvariablesareessentialforautomationandgeneralpurposeprogramdevelopment.Explanations·Interfacesignals
Signalscanbeexchangedbetweentheprogrammablemachinecontroller(PMC)andcustommacros.
Fordetailedinformation,refertotheconnectionmanual.·Toolcompensationvalues
Toolcompensationvaluescanbereadandwrittenusingsystemvariables.Usablevariablenumbersdependonthenumberofcompensationpairs,whetheradistinctionismadebetweengeometriccompensationandwearcompensation,andwhetheradistinctionismadebetweentoollengthcompensationandcuttercompensation.Whenthenumberofcompensationpairsisnotgreaterthan200,variables#2001to#2400canalsobeused.·Macroalarms·Timeinformation[Example]#3000=1(TOOLNOTFOUND);
Thealarmscreendisplays“3001TOOLNOTFOUND.”
Timeinformationcanbereadandwritten.15.3ARITHMETICANDLOGICOPERATION
TheoperationslistedinTable15.8canbeperformedonvariables.Theexpressiontotherightoftheoperatorcancontainconstantsand/orvariablescombinedbyafunctionoroperator.Variables#jand#kinanexpressioncanbereplacedwithaconstant.Variablesontheleftcanalsobereplacedwithanexpression.Explanations·Angleunits
TheunitsofanglesusedwiththeSIN,COS,TAN,andATANfunctionsaredegrees.Forexample,90degreesand30minutesisrepresentedas90.5degrees.·ATANfunction
AftertheATANfunction,specifythelengthsoftwosidesseparatedbyaslash.Aresultisfoundwhere0-result-360.[Example]When#1=ATAN[1]/[-1],thevalueof#1is135.0.·ROUNDfunction
(ⅰ)WhentheROUNDfunctionisincludedinanarithmeticorlogicoperationcommand,IFstatement,orWHILEstatement,theROUNDfunctionroundsoffatthefirstdecimalplace.[Example]When#1=ROUND[#2];isexecutedwhere#2holds1.2345,thevalueofvariable#1is1.0.
(ⅱ)WhentheROUNDfunctionisusedinNCstatementaddresses,theROUNDfunctionroundsoffthespecifiedvalueaccordingtotheleastinputincrementoftheaddress.[Example]Creationofadrillingprogramthatcutsaccordingtothevaluesofvariables#1and#2,thenreturnstotheoriginalposition.
Supposethattheincrementsystemis1/1000mm,variable#1holds1.2345,andvariable#2holds2.3456.Then,
G00G91X-#1;Moves1.235mm
G01X-#2F300;Moves2.346mm
G00X[#1+#2];Since1.2345+2.3456=3.5801,
thetraveldistanceis3.580,which
doesnotreturnthetooltothe
originalposition
Thisdifferencecomesfromwhetheradditionisperformedbeforeorafterroundingoff.
G00X-[ROUND[#1]+ROUND[#2]]mustbespecifiedtoreturnthetooltotheoriginalposition.·Roundingupanddowntoaninteger
WithCNC,whentheabsolutevalueoftheintegerproducedbyanoperationonanumberisgreaterthantheabsolutevalueoftheoriginalnumber,suchanoperationisreferredtoasroundinguptoaninteger.
Conversely,whentheabsolutevalueoftheintegerproducedbyanoperationonanumberislessthantheabsolutevalueoftheoriginalnumber,suchanoperationisreferredtoasroundingdowntoaninteger.
Beparticularlycarefulwhenhandlingnegativenumbers.[Example]Supposethat#1=1.2and#2=-1.2.
When#3=FUP[#1]isexecuted,2.0isassignedto#3.
When#3=FIX[#1]isexecuted,1.0isassignedto#3.
When#3=FUP[#2]isexecuted,-2.0isassignedto#3.
When#3=FIX[#2]isexecuted,-1.0isassignedto#3.·Abbreviationsofarithmeticandlogicoperationcommands
Whenafunctionisspecifiedinaprogram,thefirsttwocharactersofthefunctionnamecanbeusedtospecifythefunction.[Example]
ROUND→RO
FIX→FI·Priorityofoperations
Ⅰ.Functions
Ⅱ.Operationssuchasmultiplicationanddivision(*,/,AND)
Ⅲ.Operationssuchasadditionandsubtraction(+,-,OR,XOR)Fig.15.3(a)Priorityofoperations·Bracketnesting
Bracketsareusedtochangetheorderofoperations.Bracketscanbeusedtoadepthoffivelevelsincludingthebracketsusedtoencloseafunction.
Whenadepthoffivelevelsisexceeded,P/SalarmNo.118occurs.Fig.15.3(b)BracketnestingLimitations·Brackets
Brackets([,])areusedtoencloseanexpression.Notethatparenthesesareusedforcomments.·Operationerror
Errorsmayoccurwhenoperationsareperformed.NOTE
(*1)Therelativeerrordependsontheresultoftheoperation.
(*2)Smallerofthetwotypesoferrorsisused.
(*3)Theabsoluteerrorisconstant,regardlessoftheresultoftheoperation.
(*4)FunctionTANperformsSIN/COS.
(ⅰ)Theprecisionofvariablevaluesisabout8decimaldigits.Whenverylargenumbersarehandledinanadditionorsubtraction,theexpectedresultsmaynotbeobtained.[Example]Whenanattemptismadetoassignthefollowingvaluestovariables:#1and#2:#1=9876543210123.456#2=9876543277777.777
thevaluesofthevariablesbecome:#1=9876543200000.000#2=9876543300000.000
Inthiscase,when#3=#2-#1;iscalculated,#3=100000.000results.
(Theactualresultofthiscalculationisslightlydifferentbecauseitisperformedinbinary.)
(ⅱ)AlsobeawareoferrorsthatcanresultfromconditionalexpressionsusingEQ,NE,GE,GT,LE,andLT.[Example]IF[#1EQ#2]iseffectedbyerrorsinboth#1and#2,possiblyresultinginanincorrectdecision.Therefore,insteadfindthedifferencebetweenthetwovariableswithIF[ABS[#1-#2]LT0.001].
Then,assumethatthevaluesofthetwovariablesareequalwhenthedifferencedoesnotexceedanallowablelimit(0.001inthiscase).
(ⅲ)Also,becarefulwhenroundingdownavalue.[Example]When#2=#1*1000;iscalculatedwhere#1=0.002;,theresultingvalueofvariable#2isnotexactly2but1.99999997.
Here,when#3=FIX[#2];isspecified,theresultingvalueofvariable#1isnot2.0but1.0.
Inthiscase,rounddownthevalueaftercorrectingtheerrorsothattheresultisgreaterthantheexpectednumber,orrounditoffasfollows:#3=FIX[#2+0.001]#3=ROUND[#2]
·Divisor
WhenadivisorofzeroisspecifiedinadivisionorTAN[90],P/SalarmNo.112occurs.15.4MACROSTATEMENTSANDNCSTATEMENTS
Thefollowingblocksarereferredtoasmacrostatements:
(ⅰ)Blockscontaininganarithmeticorlogicoperation(=).
(ⅱ)Blockscontainingacontrolstatement(suchasGOTO,DO,END).
(ⅲ)Blockscontainingamacrocallcommand(suchasmacrocallsbyG65,G66,G67,orotherGcodes,orbyMcodes).
AnyblockotherthanamacrostatementisreferredtoasanNCstatement.EXPLANATIONS·DifferencesfromNCstatements
(ⅰ)Evenwhensingleblockmodeison,themachinedoesnotstop.Note,however,thatthemachinestopsinthesingleblockmodewhenbit5ofparameterSBMNo.6000is1.
(ⅱ)Macroblocksarenotregardedasblocksthatinvolvenomovementinthecuttercompensationmode.·NCstatementsthathavethesamepropertyasmacrostatements
(ⅰ)NCstatementsthatincludeasubprogramcallcommand(suchassubprogramcallsbyM98orotherMcodes,orbyTcodes)andnotincludeothercommandaddressesexceptanO,NorLaddresshavethesamepropertyasmacrostatements.
(ⅱ)TheblocksnotincludeothercommandaddressesexceptanO,N,PorLaddresshavethesamepropertyasmacrostatements.15.5BRANCHANDREPETITION
Inaprogram,theflowofcontrolcanbechangedusingtheGOTOstatementandIFstatement.Threetypesofbranchandrepetitionoperationsareused.Fig.15.5(a)Branchandrepetition15.5.1UnconditionalBranch(GOTOStatement)
Abranchtosequencenumbernoccurs.Whenasequencenumberoutsideoftherange1to99999isspecified,P/SalarmNo.128occurs.Asequencenumbercanalsobespecifiedusinganexpression.
GOTOn;n:Sequencenumber(1to99999)[Example]
GOTO1;
GOTO#10;15.5.2ConditionalBranch(IFStatement)
SpecifyaconditionalexpressionafterIF.Ifthespecifiedconditionalexpressionissatisfied,abranchtosequencenumbernoccurs.Ifthespecifiedconditionisnotsatisfied,thenextblockisexecuted.Fig.15.5(b)Conditionalbranch(IFstatement)EXPLANATIONS·Conditionalexpression
Aconditionalexpressionmustincludeanoperatorinsertedbetweentwovariablesorbetweenavariableandconstant,andmustbeenclosedinbrackets([,]).Anexpressioncanbeusedinsteadofavariable.·Operators
Operatorseachconsistoftwolettersandareusedtocomparetwovaluestodeterminewhethertheyareequaloronevalueissmallerorgreaterthantheothervalue.Notethattheinequalitysigncannotbeused.Sampleprogram
Thesampleprogrambelowfindsthetotalofnumbers1to10.
O9500;#1=0;Initialvalueofthevariabletoholdthesum#2=1;Initialvalueofthevariableasanaddend
N1IF[#2GT10]GOTO2;BranchtoN2whentheaddendisgreaterthan10#1=#1+#2;Calculationtofindthesum#2=#2+1;Nextaddend
GOTO1;BranchtoN1
N2M30;Endofprogram15.5.3Repetition(WHILEStatement)
SpecifyaconditionalexpressionafterWHILE.Whilethespecifiedconditionissatisfied,theprogramfromDOtoENDisexecuted.Ifthespecifiedconditionisnotsatisfied,programexecutionproceedstotheblockafterEND.Fig.15.5(c)Repetition(WHILEstatement)EXPLANATIONS
Whilethespecifiedconditionissatisfied,theprogramfromDOtoENDafterWHILEisexecuted.Ifthespecifiedconditionisnotsatisfied,programexecutionproceedstotheblockafterEND.ThesameformatasfortheIFstatementapplies.AnumberafterDOandanumberafterENDareidentificationnumbersforspecifyingtherangeofexecution.Thenumbers1,2,and3canbeused.Whenanumberotherthan1,2,and3isused,P/SalarmNo.126occurs.·Nesting
Theidentificationnumbers(1to3)inaDOENDloopcanbeusedasmanytimesasdesired.Note,however,whenaprogramincludescrossingrepetitionloops(overlappedDOranges),P/SalarmNo.124occurs.Fig.15.5(d)NestingLIMITATIONS·Infiniteloops
WhenDOmisspecifiedwithoutspecifyingtheWHILEstatement,aninfinitelooprangingfromDOtoENDisproduced.·Processingtime
WhenabranchtothesequencenumberspecifiedinaGOTOstatementoccurs,thesequencenumberissearchedfor.Forthisreason,processinginthereversedirectiontakesalongertimethanprocessingintheforwarddirection.UsingtheWHILEstatementforrepetitionreducesprocessingtime.·Undefinedvariable
InaconditionalexpressionthatusesEQorNE,a<vacant>andzerohavedifferenteffects.Inothertypesofconditionalexpressions,a<vacant>isregardedaszero.Sampleprogram
Thesampleprogrambelowfindsthetotalofnumbers1to10.
O0001;#1=0;#2=1;
WHILE[#2LE10]DO1;#1=#1+#2;#2=#2+1;
END1;
M30;15.6MACROCALL
Amacroprogramcanbecalledusingthefollowingmethods.Fig.15.6(a)MacrocallLIMITATIONS·Differencesbetweenmacrocallsandsubprogramcalls
Macrocall(G65)differsfromsubprogramcall(M98)asdescribedbelow.(ⅰ)WithG65,anargument(datapassedtoamacro)canbespecified.M98doesnothavethiscapability.
(ⅱ)WhenanM98blockcontainsanotherNCcommand(forexample,G01X100.0M98Pp),thesubprogramiscalledafterthecommandisexecuted.Ontheotherhand,G65unconditionallycallsamacro.
(ⅲ)WhenanM98blockcontainsanotherNCcommand(forexample,G01X100.0M98Pp),themachinestopsinthesingleblockmode.Ontheotherhand,G65doesnotstopsthemachine.
(ⅳ)WithG65,theleveloflocalvariableschanges.WithM98,theleveloflocalvariablesdoesnotchange.Sampleprogram(boltholecircle)
AmacroiscreatedwhichdrillsHholesatintervalsofBdegreesafterastartangleofadegreesalongtheperipheryofacirclewithradiusI.
Thecenterofthecircleis(X,Y);Commandscanbespecifiedineithertheabsoluteorincrementalmode.Todrillintheclockwisedirection,specifyanegativevalueforB.Fig.15.6(b)Sampleprogram(boltholecirc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 三年級數(shù)學(xué)計(jì)算題專項(xiàng)練習(xí)及答案集錦
- 五年級數(shù)學(xué)(小數(shù)乘除法)計(jì)算題專項(xiàng)練習(xí)及答案
- 陽光學(xué)院《礦井通風(fēng)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024年度個(gè)人經(jīng)營性抵押貸款委托擔(dān)保合同3篇
- 2025關(guān)于房屋買賣意向合同范本
- 2024年汽車維修業(yè)務(wù)員提成及激勵合同3篇
- 2024年02月招商銀行南寧分行2024春季校園招考筆試歷年參考題庫附帶答案詳解
- 2024年地方特色農(nóng)產(chǎn)品采購代理合同協(xié)議書3篇
- 2024年度制片人影視作品主題展覽合作合同3篇
- 2024年度房地產(chǎn)開發(fā)項(xiàng)目連帶責(zé)任借款擔(dān)保合同范本3篇
- 水利工程承包人常用的表格(51個(gè))
- 專題01:基礎(chǔ)知識綜合(解析版)-2022-2023學(xué)年七年級語文下學(xué)期期中專題復(fù)習(xí)(江蘇專用)
- 日結(jié)工協(xié)議書日結(jié)工用工協(xié)議
- 行政管理能力提升培訓(xùn)
- 全新聘用項(xiàng)目經(jīng)理勞務(wù)協(xié)議
- 浙江省金華市東陽市 2024 年初中學(xué)業(yè)水平考試模擬試卷 科學(xué)試題
- 【人教版】九年級化學(xué)上冊期末試卷(匯編)
- 中國歷史地理智慧樹知到期末考試答案章節(jié)答案2024年泰山學(xué)院
- 2023年檢驗(yàn)檢測機(jī)構(gòu)質(zhì)量手冊(依據(jù)2023年版評審準(zhǔn)則編制)
- 2023年玻璃廠年終工作總結(jié)
- 專題06 習(xí)作-2023-2024學(xué)年統(tǒng)部編版語文六年級上冊期末備考真題分類匯編
評論
0/150
提交評論