hexagon logo

Alignment in Subroutine Not Working

Hi All,

I've worked with subroutines a bit before, but so far mostly to put math stuff in one place out of the main program. Today I'm working on writing an external subroutine to measure a threaded hole using something like this: < https://www.pcdmisforum.com/forum/pc...ion-of-threads>. I think this might be my first subroutine that I've actually tried to measure features in.

My first step in the subroutine is to create an alignment directly over the hole, which vastly simplifies the feature programming. However, PC-DMIS is not using the alignment properly. Move points move the machine relative to the alignment as I would expect; however, it is trying to probe all of my measured features as if they were at the CAD origin rather than at the center of my alignment!

Here is my subroutine code so far:


SUBROUTINE/THREADSCANNER,
POSITION = : POSITION OF HOLE IN ACTIVE ALIGNMENT,
DIRECTION = : DIRECTION VECTOR (POINTING STRAIGHT OUT OF HOLE) IN ACTIVE ALIGNMENT,
ORIENTATION = : VECTOR NORMAL TO DIRECTION, POINTING TO SIDE TO VERTICALLY SCAN,
MINOR_DIA = : NOMINAL MINOR DIAMETER OF HOLE,
MAX_DEPTH = : DEPTH TO START VERTICAL SCAN AT (MUST BE AT LEAST 2*PITCH BELOW TOP),
PITCH = : PITCH OF THREAD,
SCAN_REVS = : NUMBER OF REVOLUTIONS TO SPIRAL SCAN (MUST FIT WITHIN HOLE),
MOVESPD = : SPEED DURING MOTION,
RADIAL_DISTANCE_TOL = 0.001 : POINTS WITHIN THIS DISTANCE FROM HIGH POINT WILL BE CONSIDERED ON THE CREST,
MIN_CREST_TOL = 0.125 : MINIMUM ACCEPTABLE CREST WIDTH AS A PERCENTAGE OF PITCH,
MAX_CREST_TOL = 0.375 : MAXIMUM ACCEPTABLE CREST WIDTH AS A PERCENTAGE OF PITCH,
=
$$ NO,
**WARNING: THIS WILL MOVE THE MACHINE!!!**
If you type in dumb numbers, it will do dumb things.
Also, make sure your tip angle is right.
ACCELERATION/MAXACCELX=250, MAXACCELY=250, MAXACCELZ=250
MOVESPEED/ MOVESPD
$$ NO,
Align to hole, move to top
POSITION_POINT=GENERIC/POINT,DEPENDENT,CARTESIAN,$
NOM/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
MEAS/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
NOM/IJK,<DIRECTION.X,DIRECTION.Y,DIRECTION.Z>,$
MEAS/IJK,<DIRECTION.X,DIRECTION.Y,DIRECTION.Z>
ORIENTATION_LINE=GENERIC/LINE,DEPENDENT,CARTESIAN,$
NOM/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
MEAS/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
NOM/IJK,<ORIENTATION.X,ORIENTATION.Y,ORIENTATION.Z>,$
MEAS/IJK,<ORIENTATION.X,ORIENTATION.Y,ORIENTATION.Z>,$
DISTANCE/1,1
[COLOR=#2980b9]HOLE_ALIGNMENT=ALIGNMENT/START,RECALL:STARTUP,LIST=YES
ALIGNMENT/LEVEL,ZPLUS,POSITION_POINT
ALIGNMENT/ROTATE,XPLUS,TO,ORIENTATION_LINE,ABOUT,ZPLUS
ALIGNMENT/TRANS,XAXIS,POSITION_POINT
ALIGNMENT/TRANS,YAXIS,POSITION_POINT
ALIGNMENT/TRANS,ZAXIS,POSITION_POINT
ALIGNMENT/END[/COLOR]
[COLOR=#27ae60]MOVE/POINT,NORMAL,<0,0,0>
MOVE/POINT,NORMAL,<0,0,0.1>
MOVE/POINT,NORMAL,<0.05,0,0>
MOVE/POINT,NORMAL,<0,0,0>
MOVE/INCREMENT,<0,0,0.1>
MOVE/INCREMENT,<0.1,0,0>[/COLOR]
[COLOR=#e74c3c]TEST_MEAS_POINT=FEAT/POINT,CARTESIAN
THEO/<0,0,0>,<0,0,1>
ACTL/<0,0,0>,<0,0,1>
MEAS/POINT,1,WORKPLANE
HIT/BASIC,NORMAL,<0,0,0>,<0,0,1>,<0,0,0>,USE THEO=YES
ENDMEAS/[/COLOR]
[COLOR=#e74c3c]TEST_POINT =FEAT/CONTACT/VECTOR POINT/DEFAULT,CARTESIAN
THEO/<0,0,0>,<0,0,1>
ACTL/<0,0,0>,<0,0,1>
TARG/<0,0,0>,<0,0,1>
SNAP=NO
SHOW FEATURE PARAMETERS=NO
SHOW CONTACT PARAMETERS=YES
AVOIDANCE MOVE=NO,DISTANCE=0.4
SHOW HITS=NO[/COLOR]
$$ NO,
Set scanning options to take ~1 second with 100 points, make vertical scan
ASSIGN/VERTICAL_SCAN_LENGTH=PITCH*2
ASSIGN/VERTICAL_SCAN_LENGTH_MM=VERTICAL_SCAN_LENGTH*25.4
SCANSPEED/VERTICAL_SCAN_LENGTH_MM
OPTIONPROBE/MAXFORCE=0.36,LOWFORCE=0.06,UPPERFORCE=0.18,TRIGGE RFORCE=0.06,
PROBEACCURACY=0.1,POSACCURACY=0.1,#RETURNDATA=7,
RETURNSPEED=1,SCANPNTDENSITY=100/VERTICAL_SCAN_LENGTH_MM,
SCANACCELERATION=10,SCANOFFSETFORCE=0.06,
PROBINGMODE=DFL,MANFINEPROBING=NO
PREHIT/MINOR_DIA/2
RETRACT/MINOR_DIA/2
TOUCHSPEED/ 1
[COLOR=#e74c3c]VERT_LINE_SCAN=BASICSCAN/LINE,NUMBER OF HITS=2,SHOW HITS=YES,SHOWALLPARAMS=YES
<MINOR_DIA/2,0,-MAX_DEPTH>,<MINOR_DIA/2,0,-MAX_DEPTH+VERTICAL_SCAN_LENGTH>,CutVec=0,1,0,DirVe c=0,0,1
InitVec=-1,0,0,EndVec=-1,0,0,THICKNESS=0,PROBECOMP=YES,AVOIDANCE MOVE=NO,DISTANCE=0
FILTER/NULLFILTER,
EXEC MODE=DEFINED
BOUNDARY/PLANE,<0,0,0>,PlaneVec=0,0,-1,Crossings=1
HITTYPE/VECTOR
NOMS MODE=NOM,0.05
HIT/VECTOR,<0,0,0>,<-1,0,0>,<0,0,0>,T=0
HIT/VECTOR,<0,0,0>,<-1,0,0>,<0,0,0>,T=0
ENDSCAN[/COLOR]
ENDSUB/



The move points in green work, both in simulation and on the machine; the features in red do not work in either simulation or reality (or at least, the first one doesn't in reality; I didn't let it bury itself in my part just to test the next two Slight smile ). Here's the code I'm calling it with, if that helps:


MOVE/CLEARPLANE
MILL_MILL_1=CALLSUB/THREADSCANNER,"THREAD_SCANNER":MPOINT(-0.15,0.375,0),MPOINT(0,0,1),MPOINT(0,1,0),0.07,0.0 5,1/56,1,20,,



This is preceded by manual, rough, and finish alignments which I can post as well if that would be helpful.

Does anyone know why my alignment might work for movements but not for measurements, or how I can fix it so it works for both?

Thank you,
Matthew
  • Would it be possible to save the alignment in the main prog, and recall it in the sub ?
  • Not really. The reason I wanted to do it in the sub was so that I could call the sub in one line of code and have it work; that way I can use it easily for different holes across multiple parts. Having to create and then save an alignment prior to each and every call would be a real pain.
  • I also tried RECALL: USE_ACTIVE_ALIGNMENT(STARTUP) in my subroutine alignment, but that didn't work either.
  • Try unchecking "Reset global settings when branching" under F5
    And recall alignment set to "Use active alignment".
  • Thank you . I unchecked "Reset global settings when branching" in both the calling program and the subroutine program and changed the alignment to recall "USE_ACTIVE_ALIGNMENT". It does the same thing as before in the simulation.
  • I've tried your code with ENDSUB/ after TEST_POINT and it behaved as you described. I changed generic feature names to F1 and F2 and it worked . Maybe feature names have something to do with it?
  • Thank you for trying it, ! I tried moving the endsub/ and renaming the generic features to F1 and F2 and it still didn't work for me.

    I stumbled across a similar thread that mentioned independent vs. dependent generic features - I'll try changing them to independent and see what happens.
  • Thank you for trying it, ! I tried moving the endsub/ and renaming the generic features to F1 and F2 and it still didn't work for me.

    I stumbled across a similar thread that mentioned independent vs. dependent generic features - I'll try changing them to independent and see what happens.


    Actually, I've tried many different things before I got to that point. The last thing I did was retype everything below MOVESPEED and change the features names. Here's your code that works on my machine, v2019r2 offline:


    SUBROUTINE/THREADSCANNER,
    POSITION = : POSITION OF HOLE IN ACTIVE ALIGNMENT,
    DIRECTION = : DIRECTION VECTOR (POINTING STRAIGHT OUT OF HOLE) IN ACTIVE ALIGNMENT,
    ORIENTATION = : VECTOR NORMAL TO DIRECTION, POINTING TO THE SIDE TO VERTICAL SCAN,
    MINOR_DIA = : NORMAL MINOR DIAMETER OF HOLE,
    MAX_DEPTH = : DEPTH TO START VERTICAL SCAN AT (MUST BE AT LEAST 2*PITCH BELOW TOP),
    PITCH = : PITCH OF THREAD,
    SCAN_REVS = : NUMBER OF REVOLUTION TO SPIRAL SCAN (MUST FIT WITHIN HOLE),
    MOVESPD = : SPEED DURING MOTION,
    RADIAL_DISTANCE_TOL = : .001 : POINTS WITHIN THIS DISTANCE FROM HIGH POINT WILL BE CONSIDERED ON THE CREST,
    MIN_CREST_TOL = : .125 : MINIMUM ACCEPTANCE CREST WIDTH AS A PERCENTAGE PITCH,
    MAX_CREST_TOL = : .375 : MAXIMUM ACCEPTANCE CREST WIDTH AS A PERCENTAGE PITCH,
    =
    ACCELERATION/MAXACCELX=250, MAXACCELY=250, MAXACCELZ=250
    MOVESPEED/ MOVESPD
    F1 =GENERIC/POINT,DEPENDENT,CARTESIAN,$
    NOM/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
    MEAS/XYZ,<POSITION.X,POSITION.Y0,POSITION.Z>,$
    NOM/IJK,<DIRECTION.X,DIRECTION.Y,DIRECTION.Z>,$
    MEAS/IJK,<DIRECTION.X,DIRECTION.Y,DIRECTION.Z>
    F2 =GENERIC/LINE,DEPENDENT,CARTESIAN,$
    NOM/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
    MEAS/XYZ,<POSITION.X,POSITION.Y,POSITION.Z>,$
    NOM/IJK,<ORIENTATION.X,ORIENTATION.Y,ORIENTATION.Z>,$
    MEAS/IJK,<ORIENTATION.X,ORIENTATION.Y,ORIENTATION.Z>,$
    DISTANCE/1,1
    DIM LOC3
    AX MEAS NOMINAL +TOL -TOL DEV OUTTOL
    X 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Y 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Z 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    END OF DIMENSION LOC3
    DIM LOC4
    AX MEAS NOMINAL +TOL -TOL DEV OUTTOL
    X 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Y 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Z 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    END OF DIMENSION LOC4
    A1 =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
    ALIGNMENT/LEVEL,ZPLUS,F1
    ALIGNMENT/ROTATE,XPLUS,TO,F2,ABOUT,ZPLUS
    ALIGNMENT/TRANS,XAXIS,F1
    ALIGNMENT/TRANS,YAXIS,F1
    ALIGNMENT/TRANS,ZAXIS,F1
    ALIGNMENT/END
    DIM LOC1
    AX MEAS NOMINAL +TOL -TOL DEV OUTTOL
    X 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Y 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Z 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    END OF DIMENSION LOC1
    DIM LOC2
    AX MEAS NOMINAL +TOL -TOL DEV OUTTOL
    X 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Y 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    Z 0.0000 0.0000 0.0020 0.0020 0.0000 0.0000
    END OF DIMENSION LOC2
    MOVE/POINT,NORMAL,<0,0,0>
    MOVE/POINT,NORMAL,<0.5,0,0.1>
    MOVE/POINT,NORMAL,<0,0,0>
    PNT1 =FEAT/POINT,CARTESIAN
    THEO/<0,0,0>,<0,0,1>
    ACTL/<0,0,0>,<0,0,1>
    MEAS/POINT,1,WORKPLANE
    HIT/BASIC,NORMAL,<0,0,0>,<0,0,1>,<0,0,0>,USE THEO=YES
    ENDMEAS/
    PNT2 =FEAT/CONTACT/VECTOR POINT/DEFAULT,CARTESIAN
    THEO/<0,0,0>,<0,0,1>
    ACTL/<0,0,0>,<0,0,1>
    TARG/<0,0,0>,<0,0,1>
    SNAP=NO
    SHOW FEATURE PARAMETERS=NO
    SHOW CONTACT PARAMETERS=NO
    ENDSUB/
  • I'm running 2019 R1 offline - maybe it's got a bug?

    I deleted and re-typed everything below the movespeed command and left the default names, but it's still not working. What are you reporting with the location dimensions? I did not include those.
  • Independent definitely didn't work - the alignment ended up in the wrong spot!