"If statement" nightmare

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

  • "If statement" nightmare

    **SOLVED**

    I slightly edited Matthew D. Hoedeman 's code from "Post #5" and came up with this:
    Code:
                WORKPLANE/ZPLUS
                DISPLAYPRECISION/5
    DIM LOC3= LOCATION OF SPHERE SPH1  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    D      0.29100+0    0.00030+0    0.00030+0    0.29120    0.00020    0.00000 ----#----
    END OF DIMENSION LOC3
                ASSIGN/SPH=LOC3.D.MEAS
    DIM LOC4= LOCATION OF CIRCLE CIR_2035  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    D      0.20350+0    0.00020+0    0.00020+0    0.20330   -0.00020    0.00000 ----#----
    END OF DIMENSION LOC4
                ASSIGN/V1=CIR_2035.D
                ASSIGN/V2=SPH1.D
                IF_GOTO/V1<0.2033,GOTO = JUNK
                IF_GOTO/V1>0.2037,GOTO = JUNK
                IF_GOTO/V2<0.2907,GOTO = JUNK
                IF_GOTO/V2>0.2913,GOTO = JUNK
    $$ NO,
                DONE CHECKING FOR JUNK
                IF_GOTO/V1<0.2036,GOTO = L2036_MINUS
                IF_GOTO/V1>0.2036,GOTO = L2036_PLUS
    L2036_MINUS=LABEL/
                IF_GOTO/V2<=0.29100,GOTO = BUCKET1
                IF_GOTO/V2>0.29101,GOTO = BUCKET2
    L2036_PLUS =LABEL/
                IF_GOTO/V2<0.2910,GOTO = BUCKET3
                IF_GOTO/V2>0.2914,GOTO = BUCKET4
    BUCKET1    =LABEL/
                COMMENT/REPT,
                Bucket 1
                GOTO/DONE
    BUCKET2    =LABEL/
                COMMENT/REPT,
                Bucket 2
                GOTO/DONE
    BUCKET3    =LABEL/
                COMMENT/REPT,
                Bucket 3
                GOTO/DONE
    BUCKET4    =LABEL/
                COMMENT/REPT,
                Bucket 4
                GOTO/DONE
    JUNK       =LABEL/
                COMMENT/REPT,
                The sphere and/or the gage point diameter = FUBAR
                GOTO/DONE
    DONE       =LABEL/
    Thanks all for your input!



    __________________________________________________ __________________________________________________ ___________________________________
    Original Post-->
    I have to measure the ID and OD of this part on the CMM. No problem, I have that done.

    My Issue--> Based on where those dimensions fall, I have a "Bucket Selection Procedure" (supplied by my customer) that dictates what "bucket" I am physically supposed to put the part in after inspection. This is for really close-tolerance assembly reasons. My boss wants PC DMIS assigning the "Bucket Number" via report comment (to remove the risk of me or someone else putting product in the wrong bin).

    Please note--> These tolerances are RIDICULOUS and far exceed the accuracy of my machine. My boss and the customer are aware but still want me to proceed.

    Here is what I have so far, I am not sure why it won't work. It keeps on showing "Bin 4".
    Code:
                DISPLAYPRECISION/5
    DIM LOC3= LOCATION OF SPHERE SPH1  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    D      0.29120    0.00500    0.00500    0.29100   -0.00020    0.00000 ----#----
    END OF DIMENSION LOC3
    DIM LOC4= LOCATION OF CIRCLE CIR_2035  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    D      0.20351    0.00500    0.00500    0.20350   -0.00001    0.00000 ----#----
    END OF DIMENSION LOC4
                IF/LOC3.D.MEAS<0.2907 OR LOC3.D.MEAS>0.2913
                  ASSIGN/BUCKET="SØ0.2910±0.0003 Reject"
                END_IF/
                IF/LOC4.D.MEAS<0.2033 OR LOC4.D.MEAS>0.2037
                  ASSIGN/BUCKET="Ø0.2035±0.0002 Reject"
                END_IF/
                IF/LOC3.D.MEAS>=0.2033 OR LOC3.D.MEAS<=0.2035 AND LOC4.D.MEAS>=0.2907 OR LOC4.D.MEAS<=0.2910
                  ASSIGN/BUCKET="Bucket 1"
                END_IF/
                IF/LOC3.D.MEAS>=0.2033 OR LOC3.D.MEAS<=0.2035 AND LOC4.D.MEAS>=0.29101 OR LOC4.D.MEAS<=0.2913
                  ASSIGN/BUCKET="Bucket 2"
                END_IF/
                IF/LOC3.D.MEAS>=0.20351 OR LOC3.D.MEAS<=0.2037 AND LOC4.D.MEAS>=0.2907 OR LOC4.D.MEAS<=0.2910
                  ASSIGN/BUCKET="Bucket 3"
                END_IF/
                IF/LOC3.D.MEAS>=0.20351 OR LOC3.D.MEAS<=0.2037 AND LOC4.D.MEAS>=0.29101 OR LOC4.D.MEAS<=0.2913
                  ASSIGN/BUCKET="Bucket 4"
                END_IF/
                COMMENT/REPT,
                BUCKET
    IMG_0565.JPG
    Last edited by DAN_M; 04-20-2018, 08:49 AM.

  • #2
    What are the constraints for going into which bucket?
    EDIT:
    I'm assuming that's what the picture indicates?

    Comment


    • #3
      Code:
                  DISPLAYPRECISION/5
      DIM LOC3= LOCATION OF SPHERE SPH1  UNITS=IN ,$
      GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
      AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
      D      0.29120    0.00500    0.00500    0.29100   -0.00020    0.00000 ----#----
      END OF DIMENSION LOC3
      DIM LOC4= LOCATION OF CIRCLE CIR_2035  UNITS=IN ,$
      GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
      AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
      D      0.20351    0.00500    0.00500    0.20350   -0.00001    0.00000 ----#----
      END OF DIMENSION LOC4
      ASSIGN/MEAS_3=LOC3.D.MEAS
      ASSIGN/MEAS_4-LOC4.D.MEAS
                  COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                  "LOC 3: " + MEAS_3
                  "LOC 4: " + MEAS_4
      IF/MEAS_3>=0.2033 AND MEAS_3<=0.2035 AND MEAS_4>=0.2907 AND MEAS_4<=0.2910
      ASSIGN/BUCKET="Bucket 1"
      Last edited by InspectorJester; 04-19-2018, 01:13 PM. Reason: See red

      Comment


      • InspectorJester
        InspectorJester commented
        Editing a comment
        KIRBSTER269 I'm not sure if you're agreeing with me or not lol

        Also did you run it (have to ask)
        And I would recommend having an ELSE at the end, to tell the software what to do if it's none of the above.
        ELSE/ASSIGN/BUCKET="1 or both are OOT"

      • KIRBSTER269
        KIRBSTER269 commented
        Editing a comment
        I myself do not have time to set your script up, but I agree the "AND" aspect. You want the line to comply with everything in it, not one "OR" the other. I agree the logic. Does it work? It's your Credit on the line, not mine.

      • DAN_M
        DAN_M commented
        Editing a comment
        I have tried running offline with the code I originally posted as well as the code DPH suggested in comment#4, no luck =/

    • #4
      Your loc3 nominal is 0.29120



      try changing or to and change loc3 and loc4
      Code:
      IF/LOC4.D.MEAS>=0.2033 AND LOC4.D.MEAS<=0.2035 AND LOC3.D.MEAS>=0.2907 AND LOC3.D.MEAS<=0.2910
      ASSIGN/BUCKET="Bucket 1"
      END_IF/
      IF/LOC4.D.MEAS>=0.2033 AND LOC4.D.MEAS<=0.2035 AND LOC3.D.MEAS>=0.29101 AND LOC3.D.MEAS<=0.2913
      ASSIGN/BUCKET="Bucket 2"
      END_IF/
      IF/LOC4.D.MEAS>=0.20351 AND LOC4.D.MEAS<=0.2037 AND LOC3.D.MEAS>=0.2907 AND LOC3.D.MEAS<=0.2910
      ASSIGN/BUCKET="Bucket 3"
      END_IF/
      IF/LOC4.D.MEAS>=0.20351 AND LOC4.D.MEAS<=0.2037 AND LOC3.D.MEAS>=0.29101 AND LOC3.D.MEAS<=0.2913
      ASSIGN/BUCKET="Bucket 4"
      END_IF/
      COMMENT/REPT,
      BUCKET
      Last edited by dph51; 04-19-2018, 01:54 PM.

      B&S CHAMELEON/PCDMIS CAD++ V2011

      There are no bugs, only "UNDOCUMENTED ENHANCEMENTS!"

      sigpic

      Comment


      • DAN_M
        DAN_M commented
        Editing a comment
        Didn't work =( thanks for the attempt though

      • dph51
        dph51 commented
        Editing a comment
        Dan_M
        See my latest update

    • #5
      I would do it with "IF/GOTO" statements. Much more simple to debug. It may take more lines, but it is much easier (IMO).
      sigpic
      Originally posted by AndersI
      I've got one from September 2006 (bug ticket) which has finally been fixed in 2013.

      Comment


      • DAN_M
        DAN_M commented
        Editing a comment
        I will send you a virtual beer if you could send me a quick sample that I could follow. I have been staring at this for far too long, my mind is now mush lol

    • #6
      I do see a problem with your sort:
      .2035 & .2913 can go in either bucket 2 or 4 per your picture.
      I'll see what I can whip out real quick
      sigpic
      Originally posted by AndersI
      I've got one from September 2006 (bug ticket) which has finally been fixed in 2013.

      Comment


      • DAN_M
        DAN_M commented
        Editing a comment
        thank you matt

    • #7
      Code:
      CIR_2035   =AUTO/CIRCLE,SHOWALLPARAMS = YES,SHOWHITS = NO
                  THEO/0,0,0,0,0,1,0.203,0
                  ACTL/0,0,0,0,0,1,0.203,0
                  TARG/0,0,0,0,0,1
                  THEO_THICKNESS = 0,RECT,OUT,CIRCULAR,LEAST_SQR,ONERROR = NO,$
                  AUTO MOVE = BOTH,DISTANCE = 7,RMEAS = None,None,None,$
                  READ POS = NO,FIND HOLE = NO,REMEASURE = NO,$
                  NUMHITS = 4,INIT = 0,PERM = 0,SPACER = 2,PITCH = 0,$
                  START ANG = 0,END ANG = 0,DEPTH = 0,$
                  ANGLE VEC = 1,0,0
      SPH1       =AUTO/CIRCLE,SHOWALLPARAMS = YES,SHOWHITS = NO
                  THEO/0,0,0,0,0,1,0.291,0
                  ACTL/0,0,0,0,0,1,0.291,0
                  TARG/0,0,0,0,0,1
                  THEO_THICKNESS = 0,RECT,OUT,CIRCULAR,LEAST_SQR,ONERROR = NO,$
                  AUTO MOVE = BOTH,DISTANCE = 7,RMEAS = None,None,None,$
                  READ POS = NO,FIND HOLE = NO,REMEASURE = NO,$
                  NUMHITS = 4,INIT = 0,PERM = 0,SPACER = 2,PITCH = 0,$
                  START ANG = 0,END ANG = 0,DEPTH = 0,$
                  ANGLE VEC = 1,0,0
                  ASSIGN/V1 = CIR_2035.D
                  ASSIGN/V2 = SPH1.D
                  COMMENT/DOC,NO,check for junk
                  IF_GOTO/V1<.2033,GOTO = JUNK
                  IF_GOTO/V1>.2037,GOTO = JUNK
                  IF_GOTO/V2<.2907,GOTO = JUNK
                  IF_GOTO/V2>.2913,GOTO = JUNK
                  COMMENT/DOC,NO,DONE CHECKING FOR JUNK
                  IF_GOTO/V1<.2036,GOTO = L2036
                  IF_GOTO/V1<.2038,GOTO = L2038
      L2036      =LABEL/
                  IF_GOTO/V2<.2910,GOTO = BUCKET1
                  IF_GOTO/V2<.2914,GOTO = BUCKET2
      L2038      =LABEL/
                  IF_GOTO/V2<.2910,GOTO = BUCKET3
                  IF_GOTO/V2<.2914,GOTO = BUCKET4
      JUNK       =LABEL/
                  COMMENT/REPT,this part is junk
                  GOTO/DONE
      BUCKET1    =LABEL/
                  COMMENT/REPT,BUCKET 1
                  GOTO/DONE
      BUCKET2    =LABEL/
                  COMMENT/REPT,BUCKET 2
                  GOTO/DONE
      BUCKET3    =LABEL/
                  COMMENT/REPT,BUCKET 3
                  GOTO/DONE
      BUCKET4    =LABEL/
                  COMMENT/REPT,BUCKET 4
                  GOTO/DONE
      DONE       =LABEL/
      I think that will do it.
      Last edited by Matthew D. Hoedeman; 04-19-2018, 02:27 PM.
      sigpic
      Originally posted by AndersI
      I've got one from September 2006 (bug ticket) which has finally been fixed in 2013.

      Comment


      • #8
        I don't get it.

        A .2035 with a .2907 can go in either bucket 1 or 3.

        A .2033 and a .2910 can go in either bucket 1 or 2

        Or am I reading that wrong?
        Automettech - Automated Metrology Technology

        Comment


        • #9
          .2035 and .2910 can go in all 4 buckets.

          B&S CHAMELEON/PCDMIS CAD++ V2011

          There are no bugs, only "UNDOCUMENTED ENHANCEMENTS!"

          sigpic

          Comment


          • DAN_M
            DAN_M commented
            Editing a comment
            We're building assemblies for our customer. There are three different part numbers that will be split into their own buckets. Only parts from "Bucket 1" can be assemble with other "Bucket 1" parts, the same for Buckets 2-4. You get the idea.

            Thanks for pointing this out, I didn't catch it originally. Having a part that fulfills the requirements for all 4 buckets isnt a bad thing, it will actually help the assembly process on our end. That kind of part can technically be assembled with all of the other Bucket numbers

        • #10
          One has to assume something, as it's not obvious from the table which bucket the borderline parts should go. In the following example I assume (Low <= dimension < High) for the 'inner' borders, and add a little extra to include the written value for the 'outer' border. Being a programmer, I prefer IF-THEN-ELSE as that shows the structure visually. I also don't like to repeat myself, so I define a FUNCTION for the range test (this also has the benefit of only one place to change if the borders should be interpreted differently):

          Code:
          $$ NO,
                      Test data
                      .
                      ASSIGN/D3=0.2908
                      ASSIGN/D4=0.2035
          $$ NO,
                      Function IN_RANGE(X, LO, HI) tests for LO <= X < HI (the same as [LO, HI[ if you know that way of writing)
                      .
                      ASSIGN/IN_RANGE=FUNCTION((X, LO, HI), (X>=LO AND X < HI))
                      ASSIGN/EPSILON=0.00001
          $$ NO,
                      Is any argument out of total range?
                      .
                      IF/(IN_RANGE(D3, 0.2907, 0.2913+EPSILON)==0) OR (IN_RANGE(D4, 0.2033, 0.2037+EPSILON)==0)
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        At least one diameter is Out of Range!
                      END_IF/
                      ELSE/
                        IF/IN_RANGE(D4, 0.2033, 0.2035)
              $$ NO,
                          Bucket 1 or 2
                          .
                          IF/IN_RANGE(D3, .2907, .2910)
                            COMMENT/REPT,
                            Bucket 1
                            .
                          END_IF/
                          ELSE/
                            COMMENT/REPT,
                            Bucket 2
                            .
                          END_ELSE/
                        END_IF/
                        ELSE/
              $$ NO,
                          Bucket 3 or 4
                          .
                          IF/IN_RANGE(D3, .2907, .2910)
                            COMMENT/REPT,
                            Bucket 3
                            .
                          END_IF/
                          ELSE/
                            COMMENT/REPT,
                            Bucket 4
                            .
                          END_ELSE/
                        END_ELSE/
                      END_ELSE/
          AndersI
          SW support - Hexagon Metrology Nordic AB

          Comment


          • Kp61dude!
            Kp61dude! commented
            Editing a comment
            Apply it DAN_M there's no formal training needed. Just need to get your hands dirty. Over and over and over and over again.

          • DAN_M
            DAN_M commented
            Editing a comment
            I'm really trying to do this but I am hitting a wall with understanding this

            I really wish Andersl was here to show me this in person

            I'm thinking about having HEX remote into my computer and having someone read his example and then show me how to set it up

          • DJAMS
            DJAMS commented
            Editing a comment
            Very nice AndersI !

        • #11
          Basically a function is a math equation that you define.
          In this instance, he defined his math equation as IN_RANGE, and told it to check if the number X is Higher than/Equal to the number LO, but lower than/Equal to the number HI.
          So as you can see, using IF statements he declares:
          IF D4 is between 0.2033 and 0.2035.

          I personally like to program this way because, as stated above, it seems clearer and easier to understand. You want to know if D4 is within the range 0.2033 and 0.2035
          So the code asks, IF/IN_RANGE(D4,0.2033,0.2035).

          It's the same way as defining a variable, but sort of different.

          First you tell it what generic variables are going to be required (In the IN_RANGE example, X, LO, and HI are used)
          Anything you want to do to these variables is defined next. All it's saying is that X should be >= LO, AND X should be <= HI

          It's one of those "a million ways to achieve the same goal" techniques.

          Comment


          • InspectorJester
            InspectorJester commented
            Editing a comment
            Correct me if I'm wrong

          • DAN_M
            DAN_M commented
            Editing a comment
            Are functions typed into Document Comment's?

            I can follow the logic reading it but am unsure how to go about beginning to set this up.

          • InspectorJester
            InspectorJester commented
            Editing a comment
            The document comment was just an explanation of the assignment

        • #12
          I thought doing it with arrays... As usual !
          Even if I like the AndersI method, which is very clean !
          Code:
          ASSIGN/V1=ARRAY(.2033,CIR_2035.D,.2034999)
          ASSIGN/V2=ARRAY(.2035,CIR_2035.D,.2037)
          ASSIGN/V3=ARRAY(.2907,SPH1.D,.2909999)
          ASSIGN/V4=ARRAY(.2910,SPH1.D,.2913)
          IF SORTUP(V1)==V1
          ASSIGN/V5=0
          END IF
          IF SORTUP(V2)==V2
          ASSIGN/V5=-1
          END IF
          IF SORTUP(V3)==V3
          ASSIGN/V6=0
          END IF
          IF SORTUP(V4)==V4
          ASSIGN/V6=2
          ​​​​​​​END IF
          IF V5+V6==0
          COMMENT,REPT,
          BUCKET 1
          END IF
          IF V5+V6==2
          COMMENT,REPT,
          BUCKET 2
          ​​​​​​​END IF
          IF V5+V6==-1
          COMMENT,REPT,
          BUCKET 3
          ​​​​​​​END IF
          IF V5+V6==1
          COMMENT,REPT,
          BUCKET 4
          ​​​​​​​END IF
          ELSE
          COMMENT,REPT,
          Part out !
          END ELSE

          Comment


          • #13
            WINNER and still master of PC-DMIS total consciousness
            sigpic
            Originally posted by AndersI
            I've got one from September 2006 (bug ticket) which has finally been fixed in 2013.

            Comment


            • DAN_M
              DAN_M commented
              Editing a comment
              Not too fast !!

              I'm messing around with the solution @Andersl offered up, it seems pretty legit

          • #14
            Another, just because it's a fun little exercise

            Code:
            
            ASSIGN/TESTVAL1=.2033
                        ASSIGN/TESTVAL2=.2915
            $$ NO,
                        CHECK THE FIRST VALUE AND ASSIGN IT EITHER A OR B
                        IF/0.2033 <= TESTVAL1 AND TESTVAL1 <= 0.2035
                        ASSIGN/SORT_CHAR="A"
                        END_IF/
                        ELSE_IF/0.2035 <= TESTVAL1 AND TESTVAL1 <= 0.2037
                        ASSIGN/SORT_CHAR="B"
                        END_ELSEIF/
                        ELSE/
                        ASSIGN/SORT_CHAR=""
                        END_ELSE/
            $$ NO,
                        CHECK THE SECOND VALUE AND ASSIGN IT EITHER 1 OR 2
                        IF/0.2907 <= TESTVAL2 AND TESTVAL2 <= 0.2910
                        ASSIGN/SORT_NUM="1"
                        END_IF/
                        ELSE_IF/0.2910 <= TESTVAL2 AND TESTVAL2 <= 0.2913
                        ASSIGN/SORT_NUM="2"
                        END_ELSEIF/
                        ELSE/
                        ASSIGN/SORT_NUM=""
                        END_ELSE/
            $$ NO,
                        COMBINE THE LETTER AND NUMBER AND SORT BASED ON THAT
                        ASSIGN/RESULT=SORT_CHAR + SORT_NUM
                        SELECT/RESULT
                        CASE/"A1"
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        BUCKET 1
                        END_CASE/
                        CASE/"A2"
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        BUCKET 2
                        END_CASE/
                        CASE/"B1"
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        BUCKET 3
                        END_CASE/
                        CASE/"B2"
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        BUCKET 4
                        END_CASE/
                        DEFAULT_CASE/
                        COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                        REJECT
                        END_DEFAULTCASE/
                        END_SELECT/
            Automettech - Automated Metrology Technology

            Comment


            • #15
              DAN_M
              Originally posted by AndersI View Post
              ASSIGN/IN_RANGE=FUNCTION((X, LO, HI), (X>=LO AND X < HI))
              No it's an assignment. You're basically assigning the variable to a math equation instead of performing a math equation on the variables. I think...?

              Comment

              Working...
              X