3 point level macro

Started by MIL-TFP-41, August 01, 2025, 11:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MIL-TFP-41

So I had some parts, some castings, that I wanted to probe to establish a best condition plane. I reached out to Renishaw, they do sell a add on package, Inspection Plus Advanced Cycles, that will establish a plane form 3 points.

Me being me, and knowing the math behind this isn't that tough, decided to brew up my own.

How it works -
Probe 3 points on a surface. Store the XYZ values of each point in #160 thru #168
For simplicity, I stored X & Y in point 1 as zero. The X and Y points 2 and point 3 are the incremental distance from point 1. The Z value at each point is what I am actually probing

so, for example, point 1 would be X0, Y0, Z(probe)
#160=0
#161=0
#162=(probe value)
point 2 would/could be X3. Y0. z(probe)
#163=3.
#164=0
#165=(probe value)
point 3, X2. Y2. z(probe)
#166=2.
#167=2.
#168=(probe value)

Once that data is collected, run it through the macro.
What is output -
#180 would be the angular error that the machine needs to rotate around "X" to make the plane flat
#181 would be the angular error that the machine needs to rotate around "Y" to make the plane flat
#183 would be the angular error that the machine needs to rotate around "Z" to make the plane flat

Now, in my experiments, the error in Z was not necessary for my purposes. I wrote the errors to the "a"(rotated around X) and "b"(rotated around Y) registers in the WSEC tables. I made G54.4 active, checked that part, and everything was now flat.

At first, the order of points collected was critical. I did add a section in "(--- Set Positive Vector Direction ---)" to overcome this, hopefully. I also found that when probing a plane in an orientation other than "home" one has to invert the angles depending on orientation. Not sure I can verbalize all of that efficiently on a forum.


 Anyway, enough explaining. Use at your own risk, yadda yadda.


O8526 (LEVEL PLANE ANGLE)
(INPUTS)
(S - WRITE TO WSEC OFFSET NUMBER)
(EX- S2. WILL WRITE VALUES TO G54.4 P2)
(FORMAT - G65 P8526 S2.)

(INPUT ERRORS)
IF[[#19LT1.]OR[#19GT7.]]GOTO1000

(POINT 1 DATA)
(#160 = X1)
(#161 = Y1)
(#162 = Z1)

(POINT 2 DATA)
(#163 = X2)
(#164 = Y2)
(#165 = Z2)

(POINT 3 DATA)
(#166 = X3)
(#167 = Y3)
(#168 = Z3)


(--- Compute Vectors V1 = P2 - P1 ---)
#170 = #163 - #160  (V1x = X2 - X1)
#171 = #164 - #161  (V1y = Y2 - Y1)
#172 = #165 - #162  (V1z = Z2 - Z1)

(--- Compute Vectors V2 = P3 - P1 ---)
#173 = #166 - #160  (V2x = X3 - X1)
#174 = #167 - #161  (V2y = Y3 - Y1)
#175 = #168 - #162  (V2z = Z3 - Z1)

(--- Compute Cross Product N = V1 x V2 ---)
#176 = [#171 * #175] - [#172 * #174]  (Nx)
#177 = [#172 * #173] - [#170 * #175]  (Ny)
#178 = [#170 * #174] - [#171 * #173]  (Nz)

(--- Set Positive Vector Direction ---)
WHILE [#178 LT 0] DO1
#176 = [#174 * #172] - [#175 * #171]
#177 = [#175 * #170] - [#173 * #172]
#178 = [#173 * #171] - [#174 * #170]
END1

(--- Normalize N ---)
#179 = SQRT[[#176*#176] + [#177*#177] + [#178*#178]]
#176 = #176 / #179
#177 = #177 / #179
#178 = #178 / #179

(--- Compute Angles in Degrees ---)
#180 = ATAN[#177 / #178]     (Rotate around X)
#181 = -ATAN[#176 / #178]    (Rotate around Y)
#182 = ATAN[#176 / #177]     (Rotate around Z — optional)

(--- Write Offset ---)
G90G10L23P#19 A#180 B#181
G11

M99

N1000
#3000=1(S INPUT ERROR)
M30
Like Like x 6 Love Love x 1 Thank  You Thank You x 2 View List

Zoffen

This would probably be a good time to ask for a raise.

When they ask why you think you deserve more money....

You just show them this macro and ask them if they understand it?  8)
Like Like x 2 Funny Funny x 4 View List
Believe none of what you hear and only half of what you see.

Safety! is no Accident!

jstell

That and show them the quote from Renishaw.
Like Like x 1 Funny Funny x 2 View List

CNCAppsJames

Quote from: jstell on August 01, 2025, 11:47 AMThat and show them the quote from Renishaw.
Yeah, how much are the advanced cycles?
"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

CNCAppsJames

"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

mkd

Cycle 431 native on Heidenhain. Easy peasy
Funny Funny x 2 View List

CNCAppsJames

Quote from: mkd on August 06, 2025, 01:31 PMCycle 431 native on Heidenhain. Easy peasy
G-Code > Conversational

:P 
Funny Funny x 3 View List
"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

CNCAppsJames

Or... set #6055 = 431 and save as O9015.

BOOM!

G431Sn.

Easy peasy.

:rofl:
Like Like x 1 Love Love x 1 View List
"That bill for your 80's experience...yeah, it's coming due. Soon." Author Unknown

Inventor Pro 2026 - CAD
CAMplete TruePath 2026 - CAV and Post Processing
Fusion360 and Mastercam 2026 - CAM

MIL-TFP-41

Had to revisit this the other day. There was an error in how I approached this at first.
Where a Fanuc control wants to rotate things one at a time, this line did not account for it rotating in X first:
#181=-ATAN[#176/#178](Rotate around Y)

To get around this, you gotta find the combined length of the vector after it has been rolled around the X-axis. This new length becomes the adjusted "Adjacent" side of the triangle for the Y-axis calculation, which I handled like so:

#183=SQRT[[#177*#177]+[#178*#178]] (Projected length in YZ)
#181=ATAN[-#176,#183] (Angle around Y)

Also note that different kinematics (and different orientations) will need to have the calculated angles inverted, otherwise you wind up doubling your error instead of correcting it. So on these lines:
#[#191+3.]=#180     (Writes X-axis rotation to #26013 for P1, #26023 for P2, etc)
#[#191+4.]=#181     (Writes Y-axis rotation to #26014 for P1, #26024 for P2, etc)

you may need to change them to:
#[#191+3.]=-#180     (Writes X-axis rotation to #26013 for P1, #26023 for P2, etc)
#[#191+4.]=-#181     (Writes Y-axis rotation to #26014 for P1, #26024 for P2, etc)

Because it can change depending on orientation, my preference is to invert things outside the macro, so I wind up with a line that looks like this:
#26013=-#26013

Anyways, yadda yadda yadda, here is the latest version:

O8526(LEVEL PLANE ANGLE)
(INPUTS)
(S=#19 - WRITE TO WSEC OFFSET NUMBER)
(EX- S2. WILL WRITE VALUES TO G54.4 P2)
 
(INPUT ERRORS)
IF[[#19LT1.]OR[#19GT7.]]GOTO1000
 
(POINT 1 DATA)
(#160=X1, #161=Y1, #162=Z1)
 
(POINT 2 DATA)
(#163=X2, #164=Y2, #165=Z2)
 
(POINT 3 DATA)
(#166=X3, #167=Y3, #168=Z3)
 
(--- Compute Vectors V1 = P2 - P1 ---)
#170=#163-#160 (V1x = X2 - X1)
#171=#164-#161 (V1y = Y2 - Y1)
#172=#165-#162 (V1z = Z2 - Z1)
 
(--- Compute Vectors V2 = P3 - P1 ---)
#173=#166-#160 (V2x = X3 - X1)
#174=#167-#161 (V2y = Y3 - Y1)
#175=#168-#162 (V2z = Z3 - Z1)
 
(--- Compute Cross Product N = V1 x V2 ---)
#176=[#171*#175]-[#172*#174] (Nx)
#177=[#172*#173]-[#170*#175] (Ny)
#178=[#170*#174]-[#171*#173] (Nz)
 
(--- Ensure Positive Vector Direction - No Loop ---)
IF[#178GE0]GOTO10
#176=-#176 (Invert Nx)
#177=-#177 (Invert Ny)
#178=-#178 (Invert Nz)
N10
 
(--- Normalize Vector N ---)
#179=SQRT[[#176*#176]+[#177*#177]+[#178*#178]]
IF[#179EQ0]GOTO1001 (Error: Points are co-linear/same point)
#176=#176/#179 (Normalized Nx)
#177=#177/#179 (Normalized Ny)
#178=#178/#179 (Normalized Nz)
 
(--- Compute Tilt Angles via 2-Argument ATAN ---)
#180=ATAN[#177,#178] (Angle around X)

#183=SQRT[[#177*#177]+[#178*#178]] (Projected length in YZ)
#181=ATAN[-#176,#183] (Angle around Y)

(--- Compute Z Rotation Clocking from P1 to P2 ---)
(Optional: Calculates alignment angle of the edge in XY plane)
#182=ATAN[#171,#170] (Angle around Z)

(--- Compute Target WSEC Base System Variable ---)
#190=[#19-1.]*10.   (Offset multiplier: 0 for P1, 10 for P2, 20 for P3)
#191=26010.+#190    (Base pointer: #26010 for P1, #26020 for P2, #26030 for P3, etc)

(--- Optional: Clear or write Shift values if desired ---)
(#[#191+0]=0.0)     (X translation shift)
(#[#191+1]=0.0)     (Y translation shift)
(#[#191+2]=0.0)     (Z translation shift)

(--- Write Dynamic Rotation Angles to WSEC ---)
#[#191+3.]=#180     (Writes X-axis rotation to #26013 for P1, #26023 for P2, etc)
#[#191+4.]=#181     (Writes Y-axis rotation to #26014 for P1, #26024 for P2, etc)
(--- Note - Z is optional ---)
(#[#191+5.]=#182)     (Writes Z-axis rotation to #26015 for P1, #26025 for P2, etc)

GOTO 9999 (Skip error traps)

(--- Error Handlers ---)
N1000
#3000=1 (S-VALUE OUT OF RANGE 1-7)
N1001
#3000=2 (PROBED POINTS ARE CO-LINEAR)

N9999
M99

M30