MACROLOOP >> MACRO B VARS Populate for UCCNC

Here is where you can drop off Examples of WORKING macros,plugins,Gcode programs , macro Wizards etc.
Please give a brief description of what it is and how it works.

MACROLOOP >> MACRO B VARS Populate for UCCNC

Postby Robertspark » Sat Jan 12, 2019 10:18 pm

MACRO B VARS MACROLOOP for UCCNC

This is just my interpretation of what may be useful from the Fanuc Macro B variables (vars) which also follow Mach3/4 {YMMV}

My intention is to use it with Macro wizards to keep track of and reset the machine back to the original machine and work co-ordinates (allows you to use G92 and also G91 for the wizard gcode and go back to the same machine and work co-ordinates, spindle speed {if you need or are using it} or feedrate, rotation etc should you change it.

Word of CAUTION.... it will ONLY work with the current development release which incorporates exec.Modalcodes and makes it easier (IMO) to extract the modal modes than using
Code: Select all
AS3.Getfield(877); // Field 877: Activemodal;


As per discussed here
viewtopic.php?f=11&t=1734

It WILL throw an error if you run it on anything prior to the current development release (2.108).... but hey that's where all the new + good stuff is at the cutting edge of the release

Code: Select all
// MACRO B VARS MACROLOOP for UCCNC
// 12/01/2019
//Robertspark


double Rx, Ry, RAngle; // Rotation coordinates

while(loop)
{
   if (AS3.Getbuttonstate(144)) // if machine is in reset no point in trying to update the variables
   {
      Thread.Sleep(50);
   }
   else // MACHINE NOT IN RESET / E-STOP, UPDATE VALUES.
   {
   
   if (!exec.IsMoving())  // no point updating on the fly as the frontend does not actually know where the machine tool actually is because of the comms buffer, and macroloop timing.  These values are not updated in macroB during motion either.
      {
         exec.Code("#5021=" + exec.GetXmachpos() ); // Machine (ABS) X coordinate
         exec.Code("#5022=" + exec.GetYmachpos() ); // Machine (ABS) Y coordinate
         exec.Code("#5023=" + exec.GetZmachpos() ); // Machine (ABS) Z coordinate
         exec.Code("#5024=" + exec.GetAmachpos() ); // Machine (ABS) A coordinate
         exec.Code("#5025=" + exec.GetBmachpos() ); // Machine (ABS) B coordinate
         exec.Code("#5026=" + exec.GetCmachpos() ); // Machine (ABS) C Ccoordinate

         exec.Code("#5041=" + exec.GetXpos() ); // Work X coordinate
         exec.Code("#5042=" + exec.GetYpos() ); // Work Y coordinate
         exec.Code("#5043=" + exec.GetZpos() ); // Work Z coordinate
         exec.Code("#5044=" + exec.GetApos() ); // Work A coordinate
         exec.Code("#5045=" + exec.GetBpos() ); // Work B coordinate
         exec.Code("#5046=" + exec.GetCpos() ); // Work C Ccoordinate
      }

      exec.Code("#4109=" + AS3.Getfield(867) ); // Set FeedRate {F CODE}
      exec.Code("#4119=" + AS3.Getfield(869) ); // Set SpindleRate {S CODE}
      
      //exec.Code("#4113=" + AS3.Getfield(867) ); // Set FeedRate {M CODE}
      exec.Code("#4114=" + exec.Getcurrgcodelinetext()); // Sequence Number (LINE) {N CODE}
      //exec.Code("#4114=" + AS3.Getfield(869) ); // Program Number {O CODE}
      
      
      exec.Code("#4001=" + exec.Modalcodes[1] ); // Modal Group 1 - MOTION
      exec.Code("#4002=" + exec.Modalcodes[2] ); // Modal Group 2 - PLANE SELECTION
      exec.Code("#4003=" + exec.Modalcodes[3] ); // Modal Group 3 - DISTANCE MODE
      exec.Code("#4005=" + exec.Modalcodes[5] ); // Modal Group 5 - FEEDRATE MODE
      exec.Code("#4007=" + exec.Modalcodes[7] ); // Modal Group 7 - CUTTER DIA COMP MODE
      exec.Code("#4008=" + exec.Modalcodes[8] ); // Modal Group 8 - TOOL LEN OFFSET
      exec.Code("#4010=" + exec.Modalcodes[10] ); // Modal Group 10 - CANNED CYCLE RTN
      exec.Code("#4012=" + exec.Modalcodes[12] ); // Modal Group 12 - WORK COORDS
      exec.Code("#4013=" + exec.Modalcodes[13] ); // Modal Group 13 - CONTROL MODE
      exec.Code("#4016=" + exec.Modalcodes[16] ); // Modal Group 16 - SCALE
      exec.Code("#4017=" + exec.Modalcodes[17] ); // Modal Group 17 - COORD ROTATION

      // ODD BALL {NON MACRO B} ONES
      exec.Code("#4209=" + AS3.Getfield(232) ); // FeedRate Over-Ride
      exec.Code("#4219=" + AS3.Getfield(233) ); // SpindleRate Over-Ride

      exec.GetRotate(out Rx, out Ry, out RAngle); // returns values into the defined variables Rx, Ry and Angle

      exec.Code("#4400=" + Rx ); // Current  Rotation Co-ordinate Centre Rx
      exec.Code("#4401=" + Ry ); // Current  Rotation Co-ordinate Centre Ry
      exec.Code("#4402=" + RAngle ); // Current  Rotation Angle

      Thread.Sleep(50);
   }
}
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: MACROLOOP >> MACRO B VARS Populate for UCCNC

Postby Robertspark » Sun Jan 13, 2019 10:48 pm

Revised + added to the Macroloop a little......

Tip: exec.Code() is not recommended for a macroloop.... IMO

Code: Select all
// MACRO B VARS MACROLOOP for UCCNC
// 13/01/2019
//Robertspark

string strFRO;
string strSSO;
char[] charsToTrim = { '%', ' ' };

while(loop)
{
   if (AS3.Getbuttonstate(144)) // if machine is in reset no point in trying to update the variables
   {
      Thread.Sleep(50);
   }
   else // MACHINE NOT IN RESET / E-STOP, UPDATE VALUES.
   {
   
   if (!exec.IsMoving())  // no point updating on the fly as the frontend does not actually know where the machine tool actually is because of the comms buffer, and macroloop timing.  These values are not updated in macroB during motion either.
      {
         exec.Setvar(exec.GetXmachpos() , 5021); // Machine (ABS) X coordinate
         exec.Setvar(exec.GetYmachpos() , 5022); // Machine (ABS) Y coordinate
         exec.Setvar(exec.GetZmachpos() , 5023); // Machine (ABS) Z coordinate
         exec.Setvar(exec.GetAmachpos() , 5024); // Machine (ABS) A coordinate
         exec.Setvar(exec.GetBmachpos() , 5025); // Machine (ABS) B coordinate
         exec.Setvar(exec.GetCmachpos() , 5026); // Machine (ABS) C Ccoordinate

         exec.Setvar(exec.Wx , 5041); // Work X coordinate
         exec.Setvar(exec.Wy , 5042); // Work Y coordinate
         exec.Setvar(exec.Wz , 5043); // Work Z coordinate
         exec.Setvar(exec.Wa , 5044); // Work A coordinate
         exec.Setvar(exec.Wb , 5045); // Work B coordinate
         exec.Setvar(exec.Wc , 5046); // Work C Ccoordinate
      }

      exec.Setvar(Convert.ToDouble(AS3.Getfield(867)) , 4109); // Set FeedRate {F CODE}
      exec.Setvar(Convert.ToDouble(AS3.Getfield(869)) , 4119); // Set SpindleRate {S CODE}
      
      //exec.Code("#4113=" + AS3.Getfield(867) ); // Set FeedRate {M CODE}
      exec.Setvar(Convert.ToDouble(exec.Getcurrgcodelinetext()) , 4114); // Sequence Number (LINE) {N CODE}
      //exec.Code("#4114=" + AS3.Getfield(869) ); // Program Number {O CODE}
      exec.Setvar(Convert.ToDouble(exec.Getcurrenttool()) , 4120); // Tool Number  {T CODE}
      
      exec.Setvar(exec.Modalcodes[1] , 4001); // Modal Group 1 - MOTION
      exec.Setvar(exec.Modalcodes[2] , 4002); // Modal Group 2 - PLANE SELECTION
      exec.Setvar(exec.Modalcodes[3] , 4003); // Modal Group 3 - DISTANCE MODE
      exec.Setvar(exec.Modalcodes[5] , 4005); // Modal Group 5 - FEEDRATE MODE
      exec.Setvar(exec.Modalcodes[7] , 4007); // Modal Group 7 - CUTTER DIA COMP MODE
      exec.Setvar(exec.Modalcodes[8] , 4008); // Modal Group 8 - TOOL LEN OFFSET
      exec.Setvar(exec.Modalcodes[10] , 4010); // Modal Group 10 - CANNED CYCLE RTN
      exec.Setvar(exec.Modalcodes[12] , 4012); // Modal Group 12 - WORK COORDS
      exec.Setvar(exec.Modalcodes[13] , 4013); // Modal Group 13 - CONTROL MODE
      exec.Setvar(exec.Modalcodes[16] , 4016); // Modal Group 16 - SCALE
      exec.Setvar(exec.Modalcodes[17] , 4017); // Modal Group 17 - COORD ROTATION
            
      // ODD BALL {NON MACRO B} ONES
      strFRO = AS3.Getfield(232);// FeedRate Over-Ride   
      strFRO  = strFRO.TrimEnd(charsToTrim);      
      exec.Setvar(Convert.ToDouble(strFRO), 4209 ); // FeedRate Over-Ride
      strSSO = AS3.Getfield(233);  // SpindleRate Over-Ride
      strSSO  = strSSO.TrimEnd(charsToTrim);
      exec.Setvar(Convert.ToDouble(strSSO), 4219 ); // SpindleRate Over-Ride
      exec.Setvar(Convert.ToDouble(AS3.Getfield(169)) , 4220 ); // Tool Length
      
      //exec.Setvar(Convert.ToDouble(AS3.Getfield(2500 + exec.Getcurrenttool())) , 4221 ); // Tool Dia      

      exec.Setvar(exec.rotX, 4400); // Current  Rotation Co-ordinate Centre Rx
      exec.Setvar(exec.rotY, 4401); // Current  Rotation Co-ordinate Centre Ry
      exec.Setvar(exec.rotAngle, 4402); // Current  Rotation Angle
      exec.Setvar(exec.scaleX, 4411); // Current X Axis Scale
      exec.Setvar(exec.scaleY, 4412); // Current Y Axis Scale      
      exec.Setvar(exec.scaleZ, 4413); // Current Z Axis Scale      
      exec.Setvar(exec.scaleA, 4414); // Current A Axis Scale
      exec.Setvar(exec.scaleB, 4415); // Current B Axis Scale
      exec.Setvar(exec.scaleC, 4416); // Current C Axis Scale      
       
      //exec.Setvar(exec.scaleX, 4411); // void Setvar (double value, int varnum)
      
      Thread.Sleep(50);
   }
}
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: MACROLOOP >> MACRO B VARS Populate for UCCNC

Postby dezsoe » Mon Jan 14, 2019 11:54 am

Hi Rob,

Did you mean
Code: Select all
      exec.Setvar(Convert.ToDouble(exec.Getcurrentgcodelinenumber()) , 4114); // Sequence Number (LINE) {N CODE}

instead of
Code: Select all
      exec.Setvar(Convert.ToDouble(exec.Getcurrgcodelinetext()) , 4114); // Sequence Number (LINE) {N CODE}
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: MACROLOOP >> MACRO B VARS Populate for UCCNC

Postby Robertspark » Mon Jan 14, 2019 12:26 pm

Thanks for reviewing, not sure, I'll have a look later this evening

(I didn't think I was going to use the N-code or O-code in wizards to reset back to the original values after the wizard has run.... I just put it in because it sort of populated the rest of the #41xx vars. as much as I could from the standard UCCNC exec.fields and or exec.variables )
https://www.cnczone.com/forums/attachme ... 992.attach)

The main ones to use were the machine + work co-ordinates + modal groups...... the stuff you may change if you are doing one thing with a wizard and may want to use G91, G41/G42, G51, G68 etc
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm


Return to UCCNC TOOL BOX

Who is online

Users browsing this forum: No registered users and 4 guests