Alignment in Subroutine Not Working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

    Code:
    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 ). Here's the code I'm calling it with, if that helps:

    Code:
    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
    Last edited by mbatten; 03-18-2020, 01:27 PM.

  • #2
    Would it be possible to save the alignment in the main prog, and recall it in the sub ?

    Comment


    • #3
      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.

      Comment


      • #4
        I also tried RECALL: USE_ACTIVE_ALIGNMENT(STARTUP) in my subroutine alignment, but that didn't work either.

        Comment


        • #5
          Try unchecking "Reset global settings when branching" under F5
          And recall alignment set to "Use active alignment".
          Last edited by BKulpa; 03-19-2020, 07:33 AM. Reason: Added comment

          Comment


          • #6
            Thank you BKulpa. 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.

            Comment


            • #7
              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?

              Comment


              • #8
                Thank you for trying it, DungT! 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.

                Comment


                • mbatten
                  mbatten commented
                  Editing a comment
                  Independent definitely didn't work - the alignment ended up in the wrong spot!

              • #9
                Originally posted by mbatten View Post
                Thank you for trying it, DungT! 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:


                Code:
                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/

                Comment


                • #10
                  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.

                  Comment


                  • DungT
                    DungT commented
                    Editing a comment
                    It could be a bug.
                    F1 and F2. Initially, xyz were wonky and now all zero

                  • mbatten
                    mbatten commented
                    Editing a comment
                    Hm. If I can't figure anything else out, I'll install 2019 R2 (or maybe 2020 if it looks decent) and see if that makes a difference.

                    F1 and F2 should be right for me because my origin trihedron is showing up where it should.

                • #11
                  That's strange! The trihedron was at CAD model origin away from my A1 alignment (the cursor's below A1), and F1 and F2 were out in space. After I tinkered with it, everything snapped back in place.

                  Comment


                  • mbatten
                    mbatten commented
                    Editing a comment
                    The trihedron is showing up in the right spot while it's running for me, even as the simulated head whisks itself away to the CAD origin. In the subroutine file, all the features are together (I assume at <0,0,0>) because the variables driving everything don't have values yet.

                • #12
                  I use subroutines a bunch... as a pointer, move your sub to your calling part routine to speed up the debugging aspect and once satisfied move your sub to your subroutine library (usually a different file).
                  PcDmis 2015.1 SP10 CAD++
                  Global 7-10-7 DC800S

                  Comment


                  • mbatten
                    mbatten commented
                    Editing a comment
                    That's a good idea, but do they always work the same in both places? I'm afraid that it would end up working together but not separated, which would be a pain...

                    Does it cause any issues to have other code with the subroutine when calling it externally? I could set myself up to test it both ways.

                • #13
                  It does behave different in some instances (of which I can't remember what they were) but very minimally. The trade off is worth it in my opinion.
                  Last edited by Kp61dude!; 03-19-2020, 04:23 PM.
                  PcDmis 2015.1 SP10 CAD++
                  Global 7-10-7 DC800S

                  Comment


                  • mbatten
                    mbatten commented
                    Editing a comment
                    Good to know.

                    I'll try combining mine in the morning and see if it makes a difference. It really shouldn't, but it might...

                  • Kp61dude!
                    Kp61dude! commented
                    Editing a comment
                    At the very least it will minimize the need to jump back and forth to sub and part routine.

                  • mbatten
                    mbatten commented
                    Editing a comment
                    It's not exactly the morning, but I just tried combining them and it didn't change the behavior. That will make development easier, though - thank you for the tip!

                • #14
                  Thank you to all who've responded so far! I've tried retyping the sub with default feature names and combining the two programs as a test, and it's still doing the same thing. I also just now tried swapping out the zeros in the first test point with 0+0, with no difference in result. I could in theory move my alignment to the calling program, but then I would have to make and save one every time I call the subroutine, which would be really annoying.

                  I could also program the whole thing in the alignment of the calling program, which would take a ton of really messy math, but would be better than what I have now.

                  Interestingly, if I stop the probe in simulation as it's moving toward the origin, this is what's shown in the Execution window:execution_window.png
                  It knows it's not going to 0,0,0 like I commanded it! What in the world is wrong with this software?

                  Comment


                  • #15
                    Do you happen to have clear cube on in either the main program or the sub? Or some other command that may not show up in the code?

                    Comment


                    • mbatten
                      mbatten commented
                      Editing a comment
                      No, I've avoided clear cube since my first program because it didn't show up in the code. I don't knowingly have anything else that would hide anything turned on either.

                  Related Topics

                  Collapse

                  Working...
                  X