Probing angular rotation G68 according to workpiece

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

Probing angular rotation G68 according to workpiece

Postby florianka » Fri Jun 02, 2023 12:33 pm

Hello,

I am using a Stepcraft M1000 in my milling application I like to adjust the coordinate system, if my workpiece is not aligned with the machine coordinate system. One user already mentioned this in an older thread (refer to A)).

trendsetter wrote:Hi all,
I am Michael, based in Germany, just starting with a UC300 and UCCNC.
Up to now I used the Estlcam software for my CNC. Estlcam and Ardunio are easy to use, running well in most cased but has the limitation of just 3 Axis and a non perfect g-code interpreter.
Therefore I decided to upgrade to UCCNC where I just built up the hardware, which is at the moment not connected to the CNC machine. Anyhow I miss some featured in UCCNC, which are available in Estlcam and very comfortable: Zeroing, touching and edge finding of the workpiece.
A) Automatically Edge finding with touch plate & angular correction: https://www.youtube.com/watch?v=bhZdbgM6S70
B) Touching of edges and corners, and circles:
https://www.youtube.com/watch?v=aT_9LtDPnKw
C) Surface touching (shuld be available as plug in.)
https://www.youtube.com/watch?v=ApBfHW7AhsM
All the things are running very smooth and are used every time to zero the workpiece.
Are these features are also available within UCCNC? Which plug ins you can recommend? (I am no programmer…)
Thanks for helping here.
Best regards,
Michael


You can see the workflow and the calculation in the following code. I like to move my probe to 4 different positions. A and B on the same axis, and C and D on another axis. Afterwards, the angle between the machine coordinate system and the line AB is calculated for the rotation in G68 and the origin of the workpiece is calculated as the intersection of AB and CD.

However, currently I could not find out, if there is the possibility to move the machine via the GUI while the macro is running. I added comments at the specific positions in the code.

Does anybody have an idea how to do that or has found a solution for that problem already?


Code: Select all
if (MessageBox.Show("Start anything?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes)
  return;

string ifai=AS3.Getfield(27242);double move=Convert.ToDouble(ifai);if(move==55){if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58))
{
MessageBox.Show("The machine has not yet been homed, HOME before executing!");
exec.Stop();
return;
}

double probe_radius = 3;


exec.AddStatusmessage("Move to point A; ");
# Wait for user input.
# Can I move the machine during this macro at this point?

if (MessageBox.Show("Are you at Point A?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes)
  return;

# Save x, y and z value to a variable A.
double Ax = exec.GetXpos();
double Ay = exec.GetYpos();
double Az = exec.GetZpos();

exec.AddStatusmessage("Move to point B; ");
if (MessageBox.Show("Are you at Point B?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes)
  return;
# Can I move the machine during this macro at this point?

# Save x, y and z value to a variable B.
double Bx = exec.GetXpos();
double By = exec.GetYpos();
double Bz = exec.GetZpos();

exec.AddStatusmessage("Move to point C; ");
if (MessageBox.Show("Are you at Point C?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes)
  return
# Can I move the machine during this macro at this point?


# Save x, y and z value to a variable C.
double Cx = exec.GetXpos();
double Cy = exec.GetYpos();
double Cz = exec.GetZpos();

exec.AddStatusmessage("Move to point D; ");
if (MessageBox.Show("Are you at Point D?", "Are you sure?", MessageBoxButtons.YesNo) != DialogResult.Yes)
  return;
# Can I move the machine during this macro at this point?

# Save x, y and z value to a variable D.
double Dx = exec.GetXpos();
double Dy = exec.GetYpos();
double Dz = exec.GetZpos();

# Calculate the angle between AB and global Y-axis.
# The angle is calculated in the XY-plane and in degrees.

double ABx = Ax - Bx;
double ABy = Ay - By;
double gamma = Math.Atan(ABx / ABy) * 180 / Math.PI;

# Calculate the angle between CD and global Y-axis.
# The angle is calculated in the XY-plane and in degrees.

double CDx = Dx - Cx;
double CDy = Dy - Cy;
double beta = Math.Atan(CDy / CDx) * 180 / Math.PI;

# Calculate the intersection point between AB and CD.
# The intersection point is calculated in the XY-plane.

double b1 = Ay-(Ax / (Bx-Ax))*(By-Ay);
double b2 = Cy-(Cx / (Dx-Cx))*(Dy-Cy);
double origin_x = (b2-b1) / (Math.Tan(gamma) - Math.Tan(beta));
double origin_y = Math.tan(gamma)*origin_x + b1;

# Calculate the distance between Dx and origin_y and Dy and origin_y.

double distance_x = Math.Abs(Dx - origin_x);
double distance_y = Math.Abs(Dy - origin_y);

# Set the DRO values for the distance between Dx and origin_y and Dy and origin_y.
AS3.Setfield(distance_x, 97);
AS3.Setfield(distance_y, 98);

exec.Code("G68" + "A" + origin_x + "B" + origin_y + "R" + gamma);


Best regards
Florian
florianka
 
Posts: 1
Joined: Fri Jun 02, 2023 11:34 am

Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests