Need Help! 3D probing to create point cloud.


Page 1 of 2 12 LastLast
Results 1 to 12 of 16

Thread: 3D probing to create point cloud.

  1. #1
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default 3D probing to create point cloud.

    Hello,
    I have very little experience with C programming.
    I’m am looking for a C program to probe a 3D surface and create the output file in a comma-delimited file or another format to create a point cloud. File will be used to create a 3D machining program.
    I’m only using Kflop, Kanalog, Konnect, &KMotionCNC to run my machine which is a custom retrofit from a Yamaha X Y Z robot.

    Also, I have a G-Code program that I found online. It uses G38.3 and macro variables. is there a plan to add G38.x Straight probe to the EMC.var file?

    Similar Threads:


  2. #2
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    Can you describe in detail how and what strategy you would wish to use to do the probing?

    Do you have your probe interfaced to KFLOP?

    We don't have plans to add G38.x but you should be able to do the equivalent with custom MCodes.

    See this Thread (you might ask if JoeKumanchik is willing to share his code):
    https://www.cnczone.com/forums/dynom...ml#post1999582

    Here is a basic ProbeDirection.c example:

    Code:
    #include "KMotionDef.h"
    
    // For basic KMotionCNC Probing configure KMotionCNC to call this C Program
    // with an MCode and 3 parameters P Q R passed in variables 50,51,52 to 
    // specify the X Y Z Probe directions speeds
    //
    // Modify this program for the input bit you are using for your probe.  As
    // written the program keeps moving until the bit goes high.  If the polarity
    // of your probe is opposit this then remove the NOT Symbol '!' applied to the
    // ReadBit result. 
    //
    // For Example:
    //
    // M100 = Exec/Wait/Sync  Thread 2 Var 50 <>\C programs\ProbeDirection.c
    //
    // Then to probe in the X direction at 100 counts/sec use GCode as:
    //
    // M100 P100 Q0 R0
    //
    // Then to probe in the Y direction at 50 counts/sec use GCode as:
    //
    // M100 P0 Q50 R0
    //
    // 
    
    main()
    {
    	Jog(0,*(float *)&persist.UserData[50]);	// move in the velocites specified
    	Jog(1,*(float *)&persist.UserData[51]);
    	Jog(2,*(float *)&persist.UserData[52]);
    
    //	printf("X Y Z Speeds = %f %f %f\n",
    //		*(float *)&persist.UserData[50],
    //		*(float *)&persist.UserData[51],
    //		*(float *)&persist.UserData[52]);
    
    	while (!ReadBit(46)) ;   		// wait for switch to go high
    
    	Jog(0,0); 						//Stop
    	Jog(1,0);
    	Jog(2,0);
    }
    Doing all the probing in KFLOP in C rather than in the PC in GCode would probably be somewhat faster if that is an issue.


    Here is a code fragment writing CSV data to a disk file taken from the CaptureXYZMotionToFile.c example.
    Code:
    	p=gather_buffer;
    
    	FILE *f=fopen("C:\\temp\\kflopdata.txt","wt");
    	for (i=0; i<N; i++)
    	{
    		// round times to neaarest servo tick
    		
    		p[0] = ((int)(p[0]/TIMEBASE + 0.5))*TIMEBASE;
    		fprintf(f,"%16.9f,%16.3f,%16.3f,%16.3f\n",p[0],p[1],p[2],p[3]);
    		p += 4;
    	}
    	fclose(f);
    Regards

    TK
    http://dynomotion.com


  3. #3
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    My strategy would be a XY grid and probe in Z. I'm currently using my tool setter as a probe for testing.
    I have read your post to JoeKumanchik and I have contacted him.
    I am learning, I have a little understanding about using three M codes, Open file, Probe and loop, then close file.
    I have a program that uses Subroutines in the form of O1 and Looping: do, while, endwhile as well as Conditional: if, else, endif.
    When I try to run it KmotionCNC gives me G code error; Unknown word starting with F. example o3 if [#1202 lt #1201]
    Does KmotionCNC support the execution of Logical expressions

    Thank you,



  4. #4
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    KMotionCNC can do subroutine loops and conditionals, but not with 'if' and 'while' statements.

    You would need to re-write the program in a form of something like a subroutine to do a row and a subroutine to do a grid point. Then loop the subroutines the appropriate number of times.

    Here are some examples (from the SubroutineWithConditionals.ngc example):
    Code:
    G20
    #100 = 5
    
    (examples of logical operations)
    (result is 1 if condition is true)
    (result is 0 if condition is false)
    
    #101 = [#100 >  5]
    #102 = [#100 >= 5]
    #103 = [#100 <  5]
    #104 = [#100 <= 5]
    #105 = [#100 =  5]
    #106 = [#100 <> 5]
    
    (subroutine call can be looped a number of times)
    (the L or Q word may be used to specify the count)
    (if neither L or Q is specified a count of 1 is used)
    (if the count is 0 the subroutine will not be called at all)
    
    M98 P1 L3  (example using L to specify the loop count)
    M98 P1 Q3  (example using Q to specify the loop count)
    
    M98 P1 L#100  (example using a variable loop count)
    
    M98 P1 L[5 > 4]  (example using a conditional as a loop count)
    M2
    
    O1
    #200 = [#200+1]
    M99
    HTH
    Regards

    TK
    http://dynomotion.com


  5. #5
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hello Tom,

    This is my current Version of software.
    KFLOP 4.33 Build 18:05:42 Dec 1 2015

    I tried running the SubroutineWithConditionals the programs runs but when I tried to modify a statement

    [#100 > 5] GOTO 10 ( GCode Error: Unknown word where unary operation could be
    M98 P1
    N10

    Is this error do to the software Version?
    Also I am running on a laptop with Windows XP Professional service Pack 3.
    Please recommend latest version of software to run.

    Thank you,



  6. #6
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    GOTO is not supported. Instead there is M98 which is a subroutine call. The P parameter indicates which subroutine to jump to (with a matching O word). The L parameter (loop count) can be used as the number of times to call the subroutine. A conditional expression for the L parameter when evaluated to be 1 (true) or 0 (false) can be used to call a subroutine one time or zero times (not at all).

    The latest Releases can be found here, but none support IF, WHILE, or GOTO:
    Dynomotion

    Regards

    TK
    http://dynomotion.com


  7. #7
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Quote Originally Posted by TomKerekes View Post
    Hi eng101,

    GOTO is not supported. Instead there is M98 which is a subroutine call. The P parameter indicates which subroutine to jump to (with a matching O word). The L parameter (loop count) can be used as the number of times to call the subroutine. A conditional expression for the L parameter when evaluated to be 1 (true) or 0 (false) can be used to call a subroutine one time or zero times (not at all).

    The latest Releases can be found here, but none support IF, WHILE, or GOTO:
    Dynomotion

    Regards
    Hello Tom,

    I have been able to work out a solution for probing, but saving the data to a file has become my next hurdle.

    The following code sends the starting point of X,Y,Z the file FILE *f=fopen("C:\\temp\\kflopdata.txt","wt"); just fine.

    Xneg = ch0->Dest; // stores the current position as the start of the data gather line
    Yneg = ch1->Dest;
    Zpos = ch2->Dest;
    //
    //fprintf(f,"%8.3f,%8.3f,%8.3f\n",(ch0->Dest),(ch1->Dest),(ch2->Dest)); // Test print to file 5/8/2018 OK
    //fprintf(f,"\n");
    //fprintf(f,"%8.3f,%8.3f,%8.3f\n",(ch0->Dest+1),(ch1->Dest+2),(ch2->Dest+3));
    //fclose(f);
    Ignor the //, It correctly saved to the file.
    0.00, 0.00, 0,00
    blank line I added these next two lines just to make sure.
    1.00, 2.00, 3.00.

    But when inside of a nested For loop.


    if (!ReadBit(1055)) // only save the position if the probe was triggered
    {
    fprintf(f,"%16.3f,%16.3f,%16.3f\n",(ch0->Dest/StepsPerMM),(ch1->Dest/StepsPerMM),(ch2->Dest/ZaxisIndex_mm)); // write the three axis coordinates to file with commas (ch0->Dest/StepsPerMM),(ch1->Dest/StepsPerMM),(ch2->Dest/ZaxisIndex_mm))
    }

    The file is opened, the date and time the file is modified is updated but no data is present.
    Any thoughts, would be helpful.
    Has anyone else in the Zone had this problem and would you share your solution?.

    Thank you



  8. #8
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    I can't see any obvious issue. It only saves data to the file when bit1055 is not set. '!' is the 'not' operator. Was that your intention? Maybe you could show us your whole program.

    Regards

    TK
    http://dynomotion.com


  9. #9
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hello Tom,

    Yes, My tool setter is always logic Hi or 1 until it is depressed.
    Quick note I removed the brackets for the print command in the nested loop, now it prints to the file.
    One problem, the value for Z is always zero.

    In this example:
    for(y=0; y<Yloop+1; y++) // 2nd for Loop (for Loop int. Condition; Increment) however many Yloops make the increment and start probe at new Y position, Checked and corrected Loop OK 5/6/2018
    { // Start of Code Block
    MoveAtVel(2,-ZMAX,1800); // y<Yloop=True. Move the z axis to the lower position at a low speed
    //5/4/2018 float ZMAX = *(float *)&persist.UserData[52]*ZaxisIndex_mm; checked OK

    while(!CheckDone(2) && !ReadBit(1055)); // check for either probe contact or the end of the move

    Jog(2,0.0); // stops the movement on the Z axis
    P0 = ch0->Dest; // stores the current position as the start of the data gather line
    P1 = ch1->Dest;
    if (!ReadBit(1055)) // only save the position if the probe was triggered
    //{ Removed Brackets 5/10/2018 now prints to file
    P2 = ch2->Dest;
    fprintf(f,"%8.3f,%8.3f,%8.3f\n",(P0/StepsPerMM),(P1/StepsPerMM),(P2/ZaxisIndex_mm)); // write the three axis coordinates to file with commas (ch0->Dest/StepsPerMM),(ch1->Dest/StepsPerMM),(ch2->Dest/ZaxisIndex_mm))
    //} Removed parentheses 5/10/2018
    Delay_sec(.2); // Delay .2 seconds
    Move(2,Zpos); // raise the Z axis to the upper position

    while (!CheckDone(2)); // Check if motion is complete

    Output :

    0.00 0.00 0.00
    0.00 0.50 0.00
    0.00 1.00 0.00
    0.50 0.00 0.00
    0.50 0.50 0.00
    0.50 1.00 0.00
    ect.

    But in this example:
    Xneg = ch0->Dest; // stores the current position as the start of the data gather line
    Yneg = ch1->Dest;
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    MoveAtVel(2,-ZMAX,1800); // y<Yloop=True. Move the z axis to the lower position at a low speed
    //5/4/2018 float ZMAX = *(float *)&persist.UserData[52]*ZaxisIndex_mm; checked OK

    while(!CheckDone(2) && !ReadBit(1055)); // check for either probe contact or the end of the move

    Jog(2,0.0); // stops the movement on the Z axis

    if (!ReadBit(1055)) This test completed 5/10/2018 for print file OK
    ////////////////////////////////////////////////////////////////////////////////////////////////
    Zpos = ch2->Dest;

    fprintf(f,"%8.3f,%8.3f,%8.3f\n",(ch0->Dest),(ch1->Dest),(ch2->Dest)); // Test print to file 5/8/2018 OK
    fprintf(f,"\n");
    fclose(f);


    Output is:
    0.00 0.00 -3.612


    Any thoughts

    Thank you for support



  10. #10
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    I tried to explain in my last email. The problem is with the '!' operator. Because your probe goes high when it is triggered the bit will normally be high. The code will only print the data when the bit is not high (low), So the "if" statement skips reading Z and printing. By removing the brackets then only one line is skipped (reading Z) so Z prints garbage. Keep the brackets and try removing the '!' operator to be like this:

    Code:
    if (ReadBit(1055)) // only save the position if the probe was triggered
    {
        P2 = ch2->Dest;
        // write the three axis coordinates to file with commas
        fprintf(f,"%8.3f,%8.3f,%8.3f\n",(P0/StepsPerMM),(P1/StepsPerMM),(P2/ZaxisIndex_mm)); 
    }
    //}
    Regards

    TK
    http://dynomotion.com


  11. #11
    Registered
    Join Date
    Oct 2008
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Thanks tom,

    I miss understood, I thought I was inverting the input for some reason.
    It is now working.

    Now the the next issue, I've created a point could, now what do I do with it.
    This is not a issue with Dynomotion but there has been others working on this. What have you all out there used to convert your data into something useful.
    I have Inventor 2010 Pro, importing points at the moment has not worked.
    Mastercam 8.1 for mill
    Autocad 2011
    Is there a good freeware package out there?

    Thank in advance.



  12. #12
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2883
    Downloads
    0
    Uploads
    0

    Default Re: 3D probing to create point cloud.

    Hi eng101,

    Glad to hear you got it working. Would you mind posting your final code? It would be fun to see a scan.

    It would probably help for you to explain what you are trying to accomplish.

    A Google search found Meshlab which is an Open Source program that seems to be able to convert point cloud to stl format and others.
    MeshLab



    Regards

    TK
    http://dynomotion.com


Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

3D probing to create point cloud.

3D probing to create point cloud.