585,599 active members*
3,647 visitors online*
Register for free
Login
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2008
    Posts
    216

    Part Home / Tool Setter C Code Fix

    Hi guys,

    I came across a video on Youtube of a cool little fixture that is used for zeroing the corner of a part. I decided to try and write my own code for this but the machine seems to go spuratically when i set this and push the zero button in KmontionCNC.

    I'm new to C programming so this may be full of issues or there could be something small i am over looking, could someone help me review this and see if they can figure out where i am going wrong?

    I am trying to duplicate the motion seen in this short video.

    https://www.youtube.com/watch?v=jZLW7knSICk

    My Code is attached, I tried to comment all throughout it so that it's easier to follow:

    I have tried to make it universal so that all can use it once i get it working i will share it.

    Thanks,
    Dan

  2. #2
    Join Date
    Jun 2013
    Posts
    1041

    Re: Part Home / Tool Setter C Code Fix

    Have you tried asking the guy who made the video if he would share his code?

    Ben

  3. #3
    Join Date
    Feb 2008
    Posts
    216

    Re: Part Home / Tool Setter C Code Fix

    Others haven asked on youtube for the code and he hasn't shared it.

  4. #4
    Join Date
    May 2006
    Posts
    4045

    Re: Part Home / Tool Setter C Code Fix

    Hi Dan,

    Thanks for offering to share your code.

    The main problem I see with your code is with this:

    while(!ReadBit(20))
    Jog(Y,0); // stop Y motion

    You are basically missing a semicolon. The syntax structure of a C while loop is:

    while (condition) statement;

    The while loop keeps executing the single statement while the condition is true. C statements are terminated with semi colons. BTW If you need multiple statements to be executed you can group the statements into a single "block" using curly brackets.

    But in these type of situations we normally want to do nothing while the condition is true (simply wait). So we put nothing followed by a semi colon like this:

    while(!ReadBit(20)) ;

    The code without the semicolon causes the following Jog command to be executed continuously in the loop. Calling continuous Jogs without any time for the newly created trajectory to even begin causes problems.

    Please try adding the ; for all the while statements and test if things work better.

    On another note the delays can probably be replaced by while (!CheckDone(X)) ; statements to improve performance.

    Also to make your code more readable and understandable to others there is a convention of indentation that C Programmers use. Lines of code are indented by different amounts to indicate which level of grouping they belong to. This has no effect on the execution of the code but simply makes it more readable and shows the intent of the author. So for example if the Jog was intended to be looped by the "while" statement it would be written as:

    Code:
    while(!ReadBit(20))
        Jog(Y,0);		      // stop Y motion
    If multiple statements were to be grouped together with curly brackes and desired to be and looped by the while statement it might look something like:
    Code:
    while(!ReadBit(20))
    {
        Jog(X,0);		      // stop Y motion
        Jog(Y,0);		      // stop Y motion
        Jog(Z,0);		      // stop Y motion
    }
    HTH
    Regards
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Feb 2008
    Posts
    216

    Re: Part Home / Tool Setter C Code Fix

    Thanks for the Help Tom, I'll make the changes and give it another try, i would never have figured that one out.

    I'm all for sharing on here, I've gain so much from others, why not give back.

  6. #6
    Join Date
    Feb 2008
    Posts
    216

    Re: Part Home / Tool Setter C Code Fix

    Hi Tom,

    We made the changes and the code is working well.

    The only last thing I want to do to the code before I finalize it and post it here is to zero the DROs in mach3.

    What type of code do I add to the C-code to do this? I know how to zero the C code for homing but that zero's the Machine coordinates, I only want to zero the system (or relative) coordinates for the part i'm starting with.

    Thanks for the help, I'll see about adding a video too.

    -Dan

  7. #7
    Join Date
    May 2006
    Posts
    4045

    Re: Part Home / Tool Setter C Code Fix

    Hi Dan,

    I think you will need to do that from Mach3 rather than KFLOP C code with something like:

    DoOEMButton (1008) 'calculate work offset

    See:

    Mach3 Plugin Encoder Setup

    How are you invoking the Probe Sequence from Mach3? Can you add this to your code there?

    Regards
    TK
    http://dynomotion.com

  8. #8
    Join Date
    Feb 2008
    Posts
    216

    Re: Part Home / Tool Setter C Code Fix

    Hi Tom,

    I've added a Button to the Mach3 Screen using MachScreen utility and I'm using the NotifyMach.C file in the Kflop plugin that I have modified to msg==10100.

    I haven't learned how to do the VB programming on the Mach3 side yet, I've been focusing on the C code so far.

    I saw this part in your manual last night when I was searching for a solution, but to be honest it didn't make a lot of sense to me, not yet anyways.

    I understand the NotifyPlugin part below, but the Sleep and DoOEMButton(1008) isn't clear yet.

    NotifyPlugins(10100) 'tell KFlop to set command to encoder
    Sleep 300 'make sure mach updates
    DoOEMButton (1008) 'calculate work offset

    Thanks for your help as always.
    -Dan

  9. #9
    Join Date
    May 2006
    Posts
    4045

    Re: Part Home / Tool Setter C Code Fix

    Hi Dan,

    In that case the Sleep is to allow time for the program in KFLOP launched by the Notify Plugins to complete. In your case since your multiple probings may take some time you will probably need to do something better. Such as a loop polling a Virtual IO bit. Then have the KFLOP Program set the Virtual IO bit when the probing is complete.

    You would be better of asking the Mach3 folks how all the Mach3 functions work. But here is a list from their site of various codes.
    OEM Buttons - Mach3Wiki

    BTW I believe there are developed screen sets for Mach3 that will do all manner of specialized probing to find the center of circles and so forth. They are written in Mach3 Basic and are all built around the G31 Gcode command to do a probe in any direction and speed. We support G31 so all those developed programs for Mach3 should work with KFLOP as well as with any controller.

    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    Nov 2010
    Posts
    1

    Re: Part Home / Tool Setter C Code Fix

    Hello, slimneill. I tried your code. I fixed it up a bit. It turned out not optimal, I do not know the language "C". Everything works. Thank you for your code.
    Sincerely, Vladimir.

  11. #11
    Join Date
    Feb 2008
    Posts
    216

    Re: Part Home / Tool Setter C Code Fix

    Thanks Vladimir,

    I updated my code to include the:
    DoPCFloat(PC_COMM_SET_X,0.00);
    DoPCFloat(PC_COMM_SET_Y,0.00);
    DoPCFloat(PC_COMM_SET_Z,0.00);

    At the end of the sequence but nothing changed in Mach3, Do I have to change a setting in Mach3 to make it work?

    Thanks,
    Dan

  12. #12
    Join Date
    May 2006
    Posts
    4045

    Re: Part Home / Tool Setter C Code Fix

    Hi Dan,

    The DoPCFloat type of commands are only supported by KMotionCNC not Mach3. You will have to handle it differently.

    Have you tried adding the Basic code

    DoOEMButton (1008) 'calculate work offset

    in your Mach3 code as we discussed before?

    Regards
    TK
    http://dynomotion.com

  13. #13
    Join Date
    Feb 2013
    Posts
    11

    Re: Part Home / Tool Setter C Code Fix

    So I thought I would at least mention that in your original post you stated that he would not share his code but he did! it was posted in the description of the video. I have it on my PC which I can send to you or you can go to his site and download it directly http://joeschmoe.com/jerbroZCircles.c
    Regards,
    -Chris

  14. #14
    Join Date
    Dec 2012
    Posts
    19

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2014, 01:08 AM
  2. Tool Length Offset Tool Setter
    By CNCneeds in forum News Announcements
    Replies: 0
    Last Post: 01-03-2014, 06:27 PM
  3. Tool Setter Macro for M-V60C and Metrol Setter
    By mitshack in forum Mazak, Mitsubishi, Mazatrol
    Replies: 1
    Last Post: 02-02-2013, 12:08 PM
  4. Okuma Tool Setter Reference Tool
    By lisaclisac in forum Okuma
    Replies: 7
    Last Post: 09-28-2012, 03:21 PM
  5. Tool setter macro for M-V60C and Metrol setter
    By mitshack in forum CNC (Mill / Lathe) Control Software (NC)
    Replies: 0
    Last Post: 10-06-2008, 02:38 PM

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
  •