Parameterized Programming: Macro Variables for Fanuc

文章推薦指數: 80 %
投票人數:10人

Fanuc Macro B is by far the most common Macro Programming Dialect. Not all controllers support full Macro B, and there are variations supported by some ... ParameterizedProgramming:MacroVariablesforFanuc CNCCookbook’sG-CodeTutorial IntroductiontoFanucMacroSystemVariables,ParameterizedProgrammingandFanucMacroB FanucMacroSystemVariables,ParameterizedProgramming,andFanucMacroB. Itallsoundsprettyarcane,doesn’tit? It’sreallynot. They’rejustbuzzwordsandjargonthatstandforsomeprettysimpleconcepts. Masteringthemisprettyeasyandthey’llgiveyoutremendouspowerandcontrolinyourg-codeprogramming. ThenextseverallessonsinthetutorialstandtogetherasaMini-TutorialonMacroProgrammingandFanucMacroB.Inmanyways,MacroProgrammingisthehighestlevelofG-codeProgramming.ItoffersthemostflexibilityandthegreatestpotentialpowerofanyoftheG-CodeProgrammingTechniques.WithoutMacroProgramming,G-Codeisnotreallyafullfledgedcomputerlanguage,it’smorearecordingofaseriesofmanualsteps.That’suseful,butcomputersandCNCcontrollersarecapableofalotmore. AwordaboutFanucMacroB FanucMacroBisbyfarthemostcommonMacroProgrammingDialect.NotallcontrollerssupportfullMacroB,andtherearevariationssupportedbysomenon-Fanuccontrollers.Wecan’tdocumenteveryG-CodeDialecthere,buttheconceptsofferedinMacroBwillbesimilartowhatyouseeelsewhere,andthereforeapplicabletothosecaseswithslightlydifferentsyntaxesandcapabilities.Ifyoudon’thaveacontrollerwithMacroB,it’sstillworthcheckingitout.JustuseaourG-WizardCNCSimulatorandEditortoplaywiththeMacroBcapabilities. ParameterizedProgramming Untilnow,allofourg-codinghasbeendonewithoutanyrecoursetovariablesorformulas.Ifwewantedtogotoaparticularcoordinate,wehadtoenterthatcoordinate,eitherabsoluteorrelative,togetthere.Atremendousamountcanbeaccomplishedinthatway,butjustasalgebraismorepowerfulthanarithmetic,soparameterizedprogrammingismorepowerfulthanbasicg-code,andforthesamereasons. Onceyouhavevariables,youcanstarttoparameterizeyourprogramming.You’llbeabletocreategeneralpurposeroutinesthatuseparameterstotiethemtospecificusesyouwanttomake.Imaginebeingabletocreateyourowncustomcannedcyclesthatcandoalmostanything.Acustomdrillingcycle,orperhapsaroutinetoautomaticallyserialnumberyourparts.Almostanythingispossible. Coveringthewholeofparameterizedprogrammingwillinvolvethreechaptersinourtutorial.Inthischapter,we’llbedealingwithvariablesandformulas.Thenextchapterwilldelveintohowtodivideyourcodeupintosubprogramsandaccessthesubprograms.Lastly,we’lldealwithmacrocontrolstructures. Notallcontrolssupportparameterizedprogramming.We’llbedealingwiththeFanucMacroBdialectforit,andwe’llthrowinmentionofMach3andLinuxCNC’sparameterizedprogrammingfeaturesaswell. ParameterstoCustomizetheMachinetotheController(akaWhyWe’reGoingtoQuitSaying“Parameters”) YoumayhavenoticedthatdifferentcompaniesoftenmaketheCNCControllerversustheactualmachinetool.Infact,thisisnearlyalwaysthecase.Thereareacollectionofsettingsinsidethecontrollerthatarecalledparametersthatareusedtoperformthatconfigurationofthecontrollertothemachinetool.Forexample,thetravels,spindlespeedrange,rapidtraverserate,andmanyothertypesofinformationthatarecriticaltomakingthecontrolworkrightwiththemachine. Forthatreason,youdon’twanttogopokingaroundwithparameterstoomuch,oryoucanscramblesomeofthosesettings.Readingasystemvariableisokay,butdon’tassignanyvaluestothemunlessyouknowforsurewhattheydo.Youshouldmakesureyouhaveagoodbackupofallyourparametersincasethebatteryfailsonthecontrollerortheygetinadvertentlychanged.TypicallythereisaprocedureavailableforyourcontrollertouseDNCtoperformabackup. Nowhereisthetrickypart:ParametersandMacroVariablesareTwoDifferentThings! Idon’tknowwhyweliketocallit“ParameterizedProgramming”andthenimmediatelyquittalkingaboutParameters,whichhavelittletodowithParameterizedProgramming.It’stemptingtothinkParametersarejustSystemVariables(moreonwhataSystemVariableisinamoment),butthey’recompletelydifferent. TherearewaystosetsomeParametersfromapartprogram,butthisisnotthemostcommonwaytodealwiththem–usuallyit’sdoneviathecontrolpanel.Therefore,we’llbestickingtotheterm“variables”andwillleave“parameters”forafuturechapter. WhatAreVariables? Firstthingisfirst,whatarevariables?Simplyput,theyarejustlikealgebravariablesthatyoucanuseinyourg-code.Theycanbeassignedvalues,andwhenyourefertothem,theygivebackthelastvaluetheywereassigned. Thesyntaxforavariableisthepoundsignfollowedbyanumberuptohowevermanydigitsyourcontrollersupportsthatidentifiesthevariable.Forexample,wecanwrite“#1=100”toassignthevalue“100”tothevariable“#1”.There’sevenaspecial“null”valuethatsaysthevariableneverhadavalueassigned.Thevariable#0alwayshasanullvalue,andyoucangiveanyothervariableanullvaluejustbyassigning#0toit.Forexample: #100=#0(Make#100’svalue“null”) Thesevariablesfallintorangesthataffecttheirmeaningandhowtheycanbeused.HereishowFanucthinksoftheseranges,forexample: VariableNumber TypeofVariable Function #0 Null Youcanneverassignavalueto#0,it’svalueisalways“null”,whichmeans“novalue.” #1–#33 LocalVariables Localvariablesareusedtopassargumentstomacrosandastemporaryscratchstorage.Yourcontrollerwon’trememberthevalueofanylocalvariableswhenthepoweristurnedoff.Localvariablesnestwhenusedwithsuprograms,sobesureyouunderstandhowthatworks. #100–#199 #500–#999 CommonVariables CommonVariablesaresharedbyallyourmacroprograms.Whenthepoweristurnedoffonthecontroller,#100–#199areclearedtonull.#500–#999remembertheirvaluesforthenexttimepoweristurnedon. #1000andup System Variables Systemvariablescanbeusedtotellthingsaboutwhatthecontrollerisdoing,suchasthecurrentposition.Don’tassignanythingtotheseunlessyouknowwhattheydo! FanucMacroVariables:Notethattheserangesmayvaryacrosscontrollersandespeciallyfornon-Fanuccontrollers! Mach3has10,320variablesavailable,from#0to#10320.There’snotquitethevarietyfoundinFanuc,butstill,plentyofsystemvariablesareaccessiblesoyoucangetatthingslikeworkoffsets.Mach3’svariablesaresavedfromonecontrolbootuptothenext,sobesuretoresetthemifyouaren’texpectingthemtohaveavalue. WhatAreVariablesGoodFor? Usevariableswheneveryouthinkyoumightwanttochangeavalueindifferentsituations.Forexample,supposeyouhaveamacroorsubprogramthatcutsasquarepocket.Youprobablywanttohavevariablesthatletyoudefinethesizeofthesquareandthefeedsandspeedssotheymayvaryasthematerialchanges.Dependingonthesubprogram,youmightwantavariableforthetopleftcornerofthesquare,oryoumightsimplyletthatcornerbethecurrentpositionwhentheroutineiscalled.Youmaywantavariabledefiningthedepthofthesquarepocket.Andlastly,youmaywantavariablethatdefinesthediameterofthetool. WhichVariablesShouldIUseinMyPrograms? SystemVariablesandLocalVariableshavesomespecialbehaviors,sosteerclearofthoseunlessyouspecificallywantthosebehaviors.Systemvariablesrefertospecificthingsgoingoninthecontroller,soarenotusableasgeneralpurposevariables.LocalVariablesexhibit“nesting”behaviorwithmacros,sowaituntilyouhavereadaboutmacrosubprogramsandunderstandthembeforedecidingtouseaLocalVariable. CommonVariablesarethereforthetaking,sotrytosticktousingthosevariablesforgeneralpurposeprogramming. WhenVariablesCan’tBeUsed Mostaddresses(rememberwordaddressformat?)canbevariables,butnotall.Forexample,Ican’thaveasequencenumberthatisavariable.N#10isnotallowed.Hereisashortlistofthe“notalloweds”: –ProgramNumbers:O#10isnotallowed.Neitheris:#10forcontrolsthatallow“:”forprogramnumbers. –SequenceNumbers:N#10isnotallowed. –BlockSkipAddress:/1isokaybut/#1isnotallowed. –WHILE..DO..ENDAddresses:DO1isallowed,DO#1isnot.   SystemVariables Asmentionedinthetableabove,FanucMacroSystemVariablesrunfrom#1000andup. That’salotofvariables,whatdotheyalldo? SystemVariablesletyoureadandwritethevaluesofvariouscriticalthingsgoingoninsidetheCNCControl. Youcanaccessandmodifyworkoffsets,forexample. Youcanseewhatmodesareineffect. Youcangenerateuser-definedalarms. Youcanquerypositionalinformation. AreyoubeginningtoseehowpowerfulFanucMacroSystemVariablescanbe? Lookedatanotherway,usingSystemVariables,youcandoalotofthingsing-codethatwouldnormallyrequiretheoperatorlookingatthemachine’scontrolpanel. Coolbeans! Note:ThereareaLOTofsystemvariables,sojustscanoverthesethefirsttimesoyouhaveanideaofwhat’spossible. Noneedtomemorizethem,thishandyreferencewillbehereifyouneedtolookthemup. Forfulldetails,consultyourcontrollermanual’s,astherearedifferencesacrossmodelsanddefinitelyacrosscontrolmanufacturers. Butingeneral,FanucMacroSystemVariablesworklikethis(describedinnumericalorder): InterfaceSignals(#1000–#1135) ToolCompensationValues(#10000–#13400) Readandwritetoolcompensationvaluesusingthesesystemvariables. Notehoweachvariablecorrespondstoarange. Forexample,forToolCompensationvalue200,herearethevariables: ToolLengthGeometricCompensation:#11201or#2400 ToolLengthWearCompensation:#10201or#2200 CutterGeometricCompensation:#13201 CutterWearCompensation:#12201 MacroAlarms(#3000and#3006) Thisisaverycoolfeature. Itletsyouassignupto201customalarmstonotifytheoperatorofvariousconditions. Justbecauseit’scalledan“Alarm”doesn’tmeanithastosignalaproblem. Thinkofthemasmessagesyourg-codeprogramcansendtotheoperator. Forexampleyoucouldhavethislineinyourg-codeprogram: #3000=1(ToolNotFound); Whenthatlineisexecuted,thecontrolwilldisplayanalarmsaying“ToolNotFound”. So,theactualmessage,whichcanbeupto26characters,iscontainedinthecommentfollowingtheassignmentto#3000. #3006worksthesamewaybutitalsostopstheprogram. TimeFunctions(#3001,#3002,#3011,and#3012) Beingabletoaccesstimersorreadthecurrentdateandtimeareveryusefulwheng-codeprogramming. Forexample,maybeyouwanttocomparehowlongaprogramtakestorunversushistoricalaverages. Youcantimetheprogram’sruntimebyaccessingatimerandstorethatinaglobalvariableforcomparison. Ifitgetsoffthehistoricalaveragesbytoomuch,perhapsyouwanttousetheAlarmoptionstotelltheoperatortosummontheirsupervisortocomeseewhattheproblemis. NumberofMachinedParts(#3901༾) #3901isthenumberofmachinedpartscompletedsofar,while#3902isthetargetnumberofpartstomake. ModalInformation(#4001–#4130) G-codeisverymodal,sobeingabletoaccesswhatmodesarecurrentlyineffectcanbeveryimportantwheng-coding. Asamatteroffact,wehaveawholechapteronjustthattopic. We’llpresentthereferenceinfoheretoo: CurrentPosition(#5001–5104) Alwayshandytobeabletoaccessthecurrentposition. Thesevariablescanberead,butnowritten: Somethingstonote: Thefirstdigit(1to4)tellsyoutheaxis. X=1,Y=2,Z=3,A=4. Thetoollengthoffsetvaluecurrentlyinuseisheldin#5081to#5084. ThetoolpositionwheretheskipsignalisturnedonviaG31isheldin#5061to#5068. Whenskipisnotturnedon,thosevariablesholdtheendpointofthespecifiedblock. Whenvariablesaremarked“disabled”duringmovement,it’sbecausetheycan’tbereadduetolookahead. WorkpieceCoordinateSystem(#5201–#7944) Thefollowingvariablescanalsobeused: Okay,Ijustwanttostatetheobvious–that’saLOTofinformation! Givesmeaheadachejustthinkingaboutit. Butthethingis,Ineverhavetothinkaboutit. There’saneasierway. Keepreading,becauseourG-WizardEditorsoftwarehasallthatinformationbuiltinsoyoudon’thavetorememberit. It’salldescribedbelow. Butfirst,let’skeeplearningabitmore. Let’slearndodoarithmeticonthevariables. Expressions:Formulas FormulasusedinparameterizedprogrammingarecalledExpressions.Theyworkprettymuchasyou’dexpectalgebraicformulastoworkwithafewthingstokeepinmind: –G-Codeusessquarebrackets(“[”and“]”)insteadofparenthesis,sinceparenthesisareusedforcomments.Itlookskindofstrange,butyougetusedtoitprettyfast.So,insteadof: #1=(#2*#3)+#4 youneedtouse: #1=[#2*#3]+#4 –Thestandardoperatorsareadd(“+”),subtract(“-“),multiply(“*”asteriskandnot“x”!),anddivide(“/”). –Theminussignisalsousedfornegation.Thinkofitasmultiplyingwhateverfollowsby-1. –Thereisalistofotheroperatorsandfunctionsthatmaybesomewhatcontrol-dependant.Makesureyoucheckyourmanualtoseeifyourcontrolsupportsthemandifsojusthowtheywork.HereisalistofoperatorsandfunctionsforFanucandMach3: Operation FanucUses Mach3Uses Function ArithmeticFunctions Power   #1**#2 #1**#2raises#1tothepower#2.Powertakesprecedenceovertheotheroperators. Modulus   MOD Modulusdividesandreturnstheremainder.So5MOD2istheremainderof5dividedby2,whichis1.Themodulesof4dividedby2is0.Modisaconvenientwaytokeepavaluewitharangeof0totheMODdivisor. AbsoluteValue ABS ABS Absolutevalue.ABS(1)=1.ABS(-1)=1. RoundingDown FIX FIX Roundsdowntothenextsmallerinteger.FIX(2.8)=2,FIX(-2.8)=-3. RoundingUp FUP FUP Roundsuptothenextlargerinteger.FUP(2.8)=3.FUP(-2.8)=-2. RoundingOff ROUND   WhenusedinamacrofunctionlikeIF,ROUNDroundsdownbyslicingoffthefractionaldecimalplaces.ROUND(1.1)=1.0.ROUND(-1.1)=-1.0. Whenusedasacoordinateaddress,ROUNDroundsofftotheleastinputincrementoftheaddress=0.001formmand0.0001forinches. SquareRoot SQRT SQRT   NaturalLogarithm LN     Exponential EXP             TrigFunctions (UnitsareDegrees,90degrees30seconds=90.5) Cosine COS COS   Sine SIN SIN   Tangent TAN TAN   ArcCosine ACOS ACOS   ArcSine ASIN ASIN   ArcTangent ATAN ATAN           LogicalFunctions LogicalOR OR OR   LogicalAND AND AND   LogicalXOR XOR XOR           OtherFunctions     ConvertfromBCDtoBIN BIN   SeeyourFanucmanualsformoredetailsonthesespecializedfunctions. ConvertfromBINtoBCD BCD   SeeyourFanucmanualsformoredetailsonthesespecializedfunctions.         FanucandMach3ExpressionOperatorsandFunctions… Tip:Whenindoubtabouttheorderaformulawillbecalculatedin,useextrabrackets Mostofuslearnedtricksingrammarschoolforhowtorememberwhatordertoperformarithmeticoperationsin.TheoneIlearnedwas“MyDearAuntSally”,whichtranslatesto“MultiplicationthenDivisionthenAdditionthenSubtraction.”Becauseofthatorder(calledanorderofprecedence),thesetwoformulashaveanidenticalresult: #1=[#2*#3]+#4 #1=#2*#3+#4 Butthiscangetconfusing.Alwaysuseextrabracketstomaketheorderclearerataglance. CalculatingWhichVariabletoAccess Thisiskindofatrick,butyoucancalculatewhichvariabletoaccess.Insteadofretrieving#107,youcouldwrite#[100+7],oranyotherexpressioninsidethesquarebrackets.Thisisoftenusefulwhenyouwanttoloopthroughvariablesthataregroupedtogetherinacertainway.Youcanevenwrite#[#2],whichisthevariablewhoseidentityisthevaluestoredinvariable#2.So,ifthevalueof#2was“10”andwewrite“#[#2]”,itisthesameaswriting“#10”.Somecontrolswilltolerate“##2”,butmostwon’t,sogetinthehabitofusingthesquarebrackets. MacroVariablesandExpressionsinG-WizardEditor OurG-WizardCNCSimulatorandEditorunderstandsmacrovariablesandexpressions,soyoucanuseittoexperimentwiththemabit.Justbringitupandtypeintheexpressionsyouwanttosee.UsetheSimulator/Debuggertostepthroughandseetheresults. Forexample: DebuggingMacroVariablesandExpressionswithG-WizardEditor… Justtypeyourexpressionsontheleft.Inthiscase,wehaveaprettysimpleset: #100=10#101=#100*2#102=[[#101/3]+6] Now,putthedebuggerinSingleBlockbyselectingthebuttonjustleftoftheTortoise. Asyoustepthroughablockatatime,thevariablesvaluesareshowintheboxrightbelowthebackplot: Macrovariablevaluesareshownbelowthebackplot… Thislittlewindowshowsallthemodalactivity,forexample,we’reinG00–Rapidsmode.ThevaluesofMacroVariablesarealsomodesofsorts,sothey’reshowntoo.Yougettoseevaluesforthelastnvariableswhosevaluechanged,andthey’resortedbyvariable#.Notehowitalsogivesyoualittlehintaboutwhatthevariabledoes.Forexample,itsays#100,#101,and#102are“VolatileCommonVariables”.“Volatile”meanstheirvaluesarenotrememberedwhenthecontrollerisswitchedoff,andaswesawfromthetableupnearthetopofthispage,variablesinthisrangeareCommonVariables.G-Wizarddoesn’thaveallthevariablevalues,butishasanawfullotofthemanditwilltrytousethisinformationtohelpyouunderstandwhat’sgoingon. YoucanseethefulllistofwhatitunderstandsbylookingunderSetup,Post,Variables: Thisscreenisusefulforanumberofpurposes.Youcanimmediatelyseethecurrentvalueofanyvariable,forexample(anyoneseethebuginthescreenabove?GWEhasmadeamistakeononeofthevariables).Youcanchangethevalueofanyvariablejustbydoubleclickingittoo.Andyoucanseethedifferentgroupingsforthevariableswiththerowofbuttonsrightabovethetable.Thegroupingswillhelpyounarrowthingsdowntoaparticularthingyou’relookingfor,suchasaWorkOffsetvariable. Conclusion Thatwasalotofinformation,butyou’renowequippedtostartparameterizingyourg-codeprogramsinwaysthatshouldmakeitpossibletoreusetheg-codeinmultiplesituationsinsteadofalwayshavingtorewritethecodeforeachindividualsituation.GoodCNCprogrammersstarttoaccumulatealibraryofusefulg-codesubprogramsthataretestedandreadytogothenexttimeasimilartaskisathand. Exercises 1.PulloutyourCNCcontrollermanualandseewhatdifferencesexistbetweenyourcontrollerandwhat’sdescribedhere. 2.UseGWEtoexperimentwithMacroVariablesandExpressionsuntilyou’vegotagoodgraspofthem. 3.ModifyoneofyourexistingG-codeprogramstousesomevariablesandexpressions.Verifythatitstillproducesthecorrectresultswhenyou’vefinished. NextArticle:SubprogramandMacros   RelatedPosts:CNCMacroProgrammingwithFanucMacroBG-WizardEditor:CustomizingPostsG-WizardG-CodeEditor(GWE)ChangeLogandReleaseNotesG-WizardEditor:Setup6WaysG-WizardEditorCanSaveYouTimeandMoneyWith…AccessingModalDatainG-Code



請為這篇文章評分?