Changing function of Linear ATC Macro

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Changing function of Linear ATC Macro

Postby nacnudz » Tue Jan 18, 2022 9:39 am

Hi Everyone,
I am very new to UCCNC (Been running for a week and still building my CNC) and i am after some help to change the function of a Macro.
I have an open builds 1500x1500 CNC and i have installed an AMB 1050 Spindle with ATC.

Stepcraft provide you with their ATC Macro as the ATC unit is provided by them but i need to make some changes.

I have relocated the Tool Rack from the rear right to the front right of the CNC as i am going to build an enclosure for it and i wouldn't be able to reach it all the way up the back without climing inside!

The Stepcraft Macro allows for 20mm of movement in the Y Axis for placing and removing the tool from the tool clip which is mounted along the Back on the X Axis. I have installed my tool holder along the Y axis instead so it doesnt take up too much room at the front.

Can someone please point me in the right direction to change this seting so that it allows the 20mm of movement in the X Axis instead of the Y?

I hope my explanation makes sense!

Here is the Current Macro

Code: Select all
//STEPCRAFT linear toolchanger code

// (1) STEPCRAFT port definition
int Chuckopenport = 2;
int Chuckopenpin = 4;

double[] ToolX = new double[11];
double[] ToolY = new double[11];
ToolX[0] = 0; // Tool0 X position
ToolY[0] = 0; // Tool0 Y position

// (2) STEPCRAFT tool holder XY positions
ToolX[1] = 1228.7; // Tool1 X position
ToolY[1] = 20.5; // Tool1 Y position
ToolX[2] = 1228.7; // Tool2 X position
ToolY[2] = 53.1; // Tool2 Y position
ToolX[3] = 1228.7; // Tool3 X position
ToolY[3] = 86.6; // Tool3 Y position
ToolX[4] = 1228.7; // Tool4 X position
ToolY[4] = 119.9; // Tool4 Y position
ToolX[5] = 1228.7; // Tool5 X position
ToolY[5] = 153.6; // Tool5 Y position

// (3) STEPCRAFT optional tools
ToolX[6] = 1228.7; // Tool6 X position
ToolY[6] = 186.4; // Tool6 Y position
// ToolX[7] = 100; // Tool7 X position
// ToolY[7] = 180; // Tool7 Y position
// ToolX[8] = 100; // Tool8 X position
// ToolY[8] = 180; // Tool8 Y position
// ToolX[9] = 100; // Tool9 X position
// ToolY[9] = 180; // Tool9 Y position
// ToolX[10] = 100; // Tool10 X position
// ToolY[10] = 180; // Tool10 Y position

// (4) STEPCRAFT basic parameters for tool change
double SafeZ = -2;
double Ztoolrelease = -56.8;
double Ztoolpickup = -56.8;
double Ytooloffset = -20; //STEPCRAFT tool position offset for Y
double Ztooloffset = -15; //STEPCRAFT tool position offset for Z

int Newtool = exec.Getnewtool();
int Currenttool = exec.Getcurrenttool();

if(Newtool == -1) // If new tool number is -1 means a missing T code, so we need to stop here...
return;

// (5) STEPCRAFT max. number of tools possible
if(Newtool <0 || Newtool >6) // Tool number is out of range, so we need to stop here...
return;

if(Newtool == Currenttool) // Same tool was selected, so do nothing, stop here...
return;

if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
{
  MessageBox.Show("The machine was not yet homed, do homeing before executing a tool change!");
  exec.Stop();
  return;
}

while(exec.IsMoving()){}

// Get current XY machine coordinates to return to this position at the end of the macro

double Xoriginalpos = exec.GetXmachpos();
double Yoriginalpos = exec.GetYmachpos();

// Stop spindle if running and Move Z up

exec.Stopspin();
exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
while(exec.IsMoving()){}

if(Currenttool!=0)
{
  // Move to old tool position on XY plane

  // STEPCRAFT
  exec.Code("G00 G53 X" + ToolX[Currenttool] + " Y" + (ToolY[Currenttool] +Ytooloffset));
  while(exec.IsMoving()){}

  // Drop current tool
  exec.Code("G00 G53 Z"+ Ztoolrelease); // Move Z axis down to tool holder position

  // STEPCRAFT
  exec.Code("G01 F500 G53 Y" + ToolY[Currenttool]); // Move Y axis to tool holder position

  while(exec.IsMoving()){}
  exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec
 
  // STEPCRAFT
  exec.Code("G01 F500 G53 Z"+ (SafeZ + Ztooloffset)); // STEPCRAFT Move Z up for tool change
  while(exec.IsMoving()){}
}

if(Currenttool==0)
{

  // STEPCRAFT open chuck if tool = 0
  exec.Wait(200);
  MessageBox.Show("No tool in chuck. Correct?"); // STEPCRAFT safety question
  exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec
}

if(Newtool!=0)
{
  // Move to new tool position on XY plane
  exec.Code("G00 G53 X" + ToolX[Newtool] + " Y" + ToolY[Newtool]);
  while(exec.IsMoving()){}

  // Pick new tool
  exec.Code("G01 F1000 G53 Z"+ Ztoolpickup); // Move Z axis down to tool holder position

  while(exec.IsMoving()){}
  exec.Clroutpin(Chuckopenport, Chuckopenpin); // Close the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec

  while(exec.IsMoving()){}
  if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
  {
  exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
  //MessageBox.Show("Tool change done."); // STEPCRAFT no message required
  }

  // STEPCRAFT
  exec.Code("G01 F1000 G53 Y" + (ToolY[Newtool] +Ytooloffset)); // Move Y axis to tool holder offset position

  exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
  while(exec.IsMoving()){}
}

if(Newtool==0)
{
  // Move Z/axis up with open chuck
  exec.Code("G00 G53 Z"+ SafeZ); // Move Z up

  while(exec.IsMoving()){}
  exec.Clroutpin(Chuckopenport, Chuckopenpin); // Close the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec

  while(exec.IsMoving()){}
  if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
  {
  exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
  //MessageBox.Show("Tool change done."); // STEPCRAFT no message required
  }
  while(exec.IsMoving()){}
}



// Move back to start point

exec.Code("G00 G53 X" + Xoriginalpos + " Y" + Yoriginalpos);
while(exec.IsMoving()){}

// Measure new tool will go here....
// Getting the tool offset of the new tool
exec.Code("G43 H"+Newtool); // Load new tool offset

exec.Wait(200);

while(exec.IsMoving()){}
if(exec.Ismacrostopped()) // STEPCRAFT interruption
{
  exec.StopWithDeccel();
  MessageBox.Show("Tool change was interrupted by user!");
}





Thanks

Chris
nacnudz
 
Posts: 2
Joined: Tue Jan 18, 2022 9:05 am

Re: Changing function of Linear ATC Macro

Postby nacnudz » Wed Jan 19, 2022 9:35 am

I managed to work it out!

I set the Y axis offset to 0 and created a new X axis offset.

I then swapped all the X and Y axis info around in reference to picking up the tools and then changed all of the Yaxis offset to X Axis offset.

I wasnt able to find any info on how to do this so i hope this will help someone else who may be in need too.

Here is the modified code.

Code: Select all
//STEPCRAFT linear toolchanger code

// (1) STEPCRAFT port definition
int Chuckopenport = 1;
int Chuckopenpin = 8;

double[] ToolX = new double[11];
double[] ToolY = new double[11];
ToolX[0] = 1244.5; // Tool0 X position
ToolY[0] = 242; // Tool0 Y position

// (2) STEPCRAFT tool holder XY positions
ToolX[1] = 1227.7; // Tool1 X position
ToolY[1] = 13.9; // Tool1 Y position
ToolX[2] = 1227.7; // Tool2 X position
ToolY[2] = 47.8; // Tool2 Y position
ToolX[3] = 1227.7; // Tool3 X position
ToolY[3] = 80; // Tool3 Y position
ToolX[4] = 1227.7; // Tool4 X position
ToolY[4] = 113.2; // Tool4 Y position
ToolX[5] = 1227.7; // Tool5 X position
ToolY[5] = 147; // Tool5 Y position
ToolX[6] = 1227.7; // Tool6 X position
ToolY[6] = 179.7; // Tool6 Y position


// (4) STEPCRAFT basic parameters for tool change
double SafeZ = -2;
double Ztoolrelease = -70.4;
double Ztoolpickup = -70.4;
double Ytooloffset = 0; //STEPCRAFT tool position offset for Y
double Xtooloffset = -20; //STEPCRAFT tool position offset for Y
double Ztooloffset = -15; //STEPCRAFT tool position offset for Z

int Newtool = exec.Getnewtool();
int Currenttool = exec.Getcurrenttool();

if(Newtool == -1) // If new tool number is -1 means a missing T code, so we need to stop here...
return;

// (5) STEPCRAFT max. number of tools possible
if(Newtool <0 || Newtool >6) // Tool number is out of range, so we need to stop here...
return;

if(Newtool == Currenttool) // Same tool was selected, so do nothing, stop here...
return;

if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
{
  MessageBox.Show("The machine was not yet homed, do homeing before executing a tool change!");
  exec.Stop();
  return;
}

while(exec.IsMoving()){}

// Get current XY machine coordinates to return to this position at the end of the macro

double Xoriginalpos = exec.GetXmachpos();
double Yoriginalpos = exec.GetYmachpos();

// Stop spindle if running and Move Z up

exec.Stopspin();
exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
while(exec.IsMoving()){}

if(Currenttool!=0)
{
  // Move to old tool position on XY plane

  // STEPCRAFT
  exec.Code("G00 G53 Y" + ToolY[Currenttool] + " X" + (ToolX[Currenttool] +Xtooloffset));
  while(exec.IsMoving()){}

  // Drop current tool
  exec.Code("G00 G53 Z"+ Ztoolrelease); // Move Z axis down to tool holder position

  // STEPCRAFT
  exec.Code("G01 F500 G53 X" + ToolX[Currenttool]); // Move X axis to tool holder position

  while(exec.IsMoving()){}
  exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
  //exec.Wait(1000); // Wait one 1000msec
 
  // STEPCRAFT
  exec.Code("G01 F500 G53 Z"+ (SafeZ + Ztooloffset)); // STEPCRAFT Move Z up for tool change
  while(exec.IsMoving()){}
}

if(Currenttool==0)
{

  // STEPCRAFT open chuck if tool = 0
  exec.Wait(200);
  MessageBox.Show("No tool in chuck. Correct?"); // STEPCRAFT safety question
  exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec
}

if(Newtool!=0)
{
  // Move to new tool position on XY plane
  exec.Code("G00 G53 Y" + ToolY[Newtool] + " X" + ToolX[Newtool]);
  while(exec.IsMoving()){}

  // Pick new tool
  exec.Code("G01 F1000 G53 Z"+ Ztoolpickup); // Move Z axis down to tool holder position

  while(exec.IsMoving()){}
  exec.Clroutpin(Chuckopenport, Chuckopenpin); // Close the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec

  while(exec.IsMoving()){}
  if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
  {
  exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
  //MessageBox.Show("Tool change done."); // STEPCRAFT no message required
  }

  // STEPCRAFT
  exec.Code("G01 F1000 G53 X" + (ToolX[Newtool] +Xtooloffset)); // Move X axis to tool holder offset position

  exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
  while(exec.IsMoving()){}
}

if(Newtool==0)
{
  // Move Z/axis up with open chuck
  exec.Code("G00 G53 Z"+ SafeZ); // Move Z up

  while(exec.IsMoving()){}
  exec.Clroutpin(Chuckopenport, Chuckopenpin); // Close the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec

  while(exec.IsMoving()){}
  if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
  {
  exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
  //MessageBox.Show("Tool change done."); // STEPCRAFT no message required
  }
  while(exec.IsMoving()){}
}



// Move back to start point

exec.Code("G00 G53 X" + Xoriginalpos + " Y" + Yoriginalpos);
while(exec.IsMoving()){}

// Measure new tool will go here....
// Getting the tool offset of the new tool
exec.Code("G43 H"+Newtool); // Load new tool offset

exec.Wait(200);

while(exec.IsMoving()){}
if(exec.Ismacrostopped()) // STEPCRAFT interruption
{
  exec.StopWithDeccel();
  MessageBox.Show("Tool change was interrupted by user!");
}


nacnudz
 
Posts: 2
Joined: Tue Jan 18, 2022 9:05 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest