Need Help! Automatic Tool Change C Code


Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Automatic Tool Change C Code

  1. #1
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Automatic Tool Change C Code

    Hi Tom,

    We are trying to write the C Code for the tool change so that we can send a video of it doing everything.

    When I compile and run the Automatic Tool Change Example from the Dynomotion Wiki the console screen shows an error: "Unable to open/read file:c:\Temp\ToolChangerData.txt"

    Is this going to impact the program? How do I correct this error? I'm running windows 10.

    Thanks,
    Dan

    Similar Threads:


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

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    That is the file used to keep track of the last loaded tool. It should just contain a number. You might use notepad and create it. Use -1 to do indicate no tool loaded.

    But if KMotionCNC is running and the file isn't valid the operator should be asked to enter the last loaded tool. Is KMotionCNC running?

    Regards

    Regards
    TK http://dynomotion.com


  3. #3
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Hi Tom,

    Yeah I get a message at the start every time to identify the last loaded tool. If the file isn't valid that won't impact anything?

    Thanks,
    Dan



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

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    I don't understand what you mean by that and you didn't answer my question whether you are running KMotionCNC.

    Is the Operator asked which Tool is loaded?

    Does your Windows C Drive have a C:\Temp Directory?

    The code is written such that if it can't determine if or which tool is loaded it will not load any tool and will Halt the GCode.

    Regards

    Regards
    TK http://dynomotion.com


  5. #5
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by TomKerekes View Post
    Hi Dan,

    I don't understand what you mean by that and you didn't answer my question whether you are running KMotionCNC.

    Is the Operator asked which Tool is loaded?

    Does your Windows C Drive have a C:\Temp Directory?

    The code is written such that if it can't determine if or which tool is loaded it will not load any tool and will Halt the GCode.

    Regards
    Currently I'm writing the C code in the Kmotion C Code editor. I have the Machine Initialized using the KmotionCNC. When I want to run the tool change code I click the "Save/Compile/Download/Run" Button.

    KmotionCNC then asks which tool is in the tool changer. I type 1 and then it begins the unload sequence (that's as far as I am).

    Is there a better way to test my code? Should I assign my test code to the M6 command in the KmotionCNC Tool Setup Screen?

    When I look at the C Drive there is no C:\Temp folder, can I make a new folder anywhere and then reference that new folder? (I tried this and got the same error message)



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

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    Currently I'm writing the C code in the Kmotion C Code editor. I have the Machine Initialized using the KmotionCNC. When I want to run the tool change code I click the "Save/Compile/Download/Run" Button.

    KmotionCNC then asks which tool is in the tool changer. I type 1 and then it begins the unload sequence (that's as far as I am).

    Is there a better way to test my code? Should I assign my test code to the M6 command in the KmotionCNC Tool Setup Screen?
    You can test your code using either of those methods but if you run the code from the C Code Editor you should be aware that the code expects the tool number to be loaded into persist Variable #9. So you should manually set that value the same as what the M6 Txx would do automatically. The definition shown below is what determines where the Tool number is expected:

    #define TOOL_VAR 9 // Tool changer desired new tool Var




    When I look at the C Drive there is no C:\Temp folder, can I make a new folder anywhere and then reference that new folder? (I tried this and got the same error message)
    It isn't clear to me what you actually tried. But this definition in the code determines what folder is to be used to find which file. (note the double slashes are needed in C to specify a single slash as the slash character is an "escape" character used to treat the following character in a special manner):

    #define TOOL_DISK_FILE "c:\\Temp\\ToolChangerData.txt"


    HTH
    Regards

    Regards
    TK http://dynomotion.com


  7. #7
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Ok thanks that all makes sense. The double/single slash part I had no idea about. I'll try it the correct way this time.



  8. #8
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by slimneill View Post
    Ok thanks that all makes sense. The double/single slash part I had no idea about. I'll try it the correct way this time.

    Hey Tom I got the Tool change working, which I thought would take us a lot longer. Now that I'm debugging it there are a few things that I noticed that I would like to address.

    1. The bigger issue that I'm facing is that I have a number of fail safes built into the tool change and if at any point in the code a fail safe is tripped the tool change is aborted, which is good. But there is no logic for the tool change to ask me what tool is currently in the spindle after a failed tool change attempt. For example, I perform a tool change T2 M6 with current tool being T1. The tool change gets all the way to installing T2 into spindle and then quits outs (Tool 2 is now in the spindle). When I try to do a tool change again it still thinks Tool 1 is the tool in the spindle and try's to drop off Tool 2 into a loaded tool holder. Is there a simple way to add the question of what tool is in the spindle at the moment the machine spits out an error message and aborts the tool change?

    2. If I notice that the tool holder isn't going into the desired location (See issue 1 above) I hit the feed hold button which is set up in my initialization file. But when I go this it only stops the motion, the tool change process continues on with dumping the tool and only aborts when it doesn't sense the new tool. I never really noticed that the C code continues on with the feedhole button activated hit until now. Is there a simple way to change this? Do I modify the Initialization file to freeze all commands or do I do something in the C Code for tool change?

    3. I also noticed that now that I have the tool change Code in the M6 command. When ever I change the Tool on the KmotionCNC Tool ID drop down box the machine automatically does a tool change to that tool even if I'm just flipping through them. Which I don't want it to do during a job setup when I'm working around that area. Is there a way to prevent the tool change feature from activating off of the Tool ID Drop down box?

    Thanks for your help!
    Dan



  9. #9
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    1. The bigger issue that I'm facing is that I have a number of fail safes built into the tool change and if at any point in the code a fail safe is tripped the tool change is aborted, which is good. But there is no logic for the tool change to ask me what tool is currently in the spindle after a failed tool change attempt. For example, I perform a tool change T2 M6 with current tool being T1. The tool change gets all the way to installing T2 into spindle and then quits outs (Tool 2 is now in the spindle). When I try to do a tool change again it still thinks Tool 1 is the tool in the spindle and try's to drop off Tool 2 into a loaded tool holder. Is there a simple way to add the question of what tool is in the spindle at the moment the machine spits out an error message and aborts the tool change?
    One thought would be to set the LastTool as 0 (undefined/unknown) using SaveCurrentTool(0) on any Tool Change Abort. That should cause the Operator to be prompted whenever the next tool is to be loaded.

    2. If I notice that the tool holder isn't going into the desired location (See issue 1 above) I hit the feed hold button which is set up in my initialization file. But when I go this it only stops the motion, the tool change process continues on with dumping the tool and only aborts when it doesn't sense the new tool. I never really noticed that the C code continues on with the feedhole button activated hit until now. Is there a simple way to change this? Do I modify the Initialization file to freeze all commands or do I do something in the C Code for tool change?
    Feed Hold only stops the axes that are defined in the Coordinate System. I suppose you could sprinkle in tests for Feed Hold (CS0_StoppingState != 0) in all your wait loops and do what is appropriate. Such as stop all the axes (Jog to zero speeds), or disable axes, or whatever and then abort.

    3. I also noticed that now that I have the tool change Code in the M6 command. When ever I change the Tool on the KmotionCNC Tool ID drop down box the machine automatically does a tool change to that tool even if I'm just flipping through them. Which I don't want it to do during a job setup when I'm working around that area. Is there a way to prevent the tool change feature from activating off of the Tool ID Drop down box?
    Well that is supposed to be what the Tool drop down is for. Why would you be flipping through Tools? Do you have "M6 on Tool Table Changes" selected in Tool Setup | Trajectory Planner? That will cause the tool to be reloaded whenever the Tool Table is Changed/Closed.

    Regards

    Regards
    TK http://dynomotion.com


  10. #10
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Tool Change In Action, Thanks for the Awesome Support Tom!

    More videos to come of the drill and laser in action.







  11. #11
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    Wow. Impressive machine. Can't wait for the other videos with it actually doing something

    Any chance your willing to share your final Tool Changer Code?

    Regards

    Regards
    TK http://dynomotion.com


  12. #12
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Thanks Tom,

    Its not done yet, this was just as far as I was able to get in one weekend. Once everything is operational and bugs ironed out i'll post the code. I've tried to add to the wiki before but it didn't work when I tried to add the part zero probe code.

    On a side note, the machine still automatically performed a tool change when you select a different tool in the drop down box tool selection box even when the perform M6 command option is unchecked in the tool setup screen. Is there something in my code that needs to be changed or the KmotionCNC?

    Thanks,
    Dan



  13. #13
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    We can post any code to the wiki if you have problems doing it.

    The Tool Drop down is supposed to be an easy way to change tools. So that behavior is by design. I'm not sure I really understand the issue. What exactly are you expecting?

    Regards

    Regards
    TK http://dynomotion.com


  14. #14
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by TomKerekes View Post
    Hi Dan,

    We can post any code to the wiki if you have problems doing it.

    The Tool Drop down is supposed to be an easy way to change tools. So that behavior is by design. I'm not sure I really understand the issue. What exactly are you expecting?

    Regards
    Next time I'm home I'll video the touch probe and send you the code to post. Email or here?

    My issue with the drop down chart is, just by opening the table to look at the tool database for offsets and data entry etc, when I leave that menu the machine automatically performs the tool change.

    What command is being sent? Is it an actual m6 g code command or something else?



  15. #15
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by TomKerekes View Post
    Hi Dan,

    We can post any code to the wiki if you have problems doing it.

    The Tool Drop down is supposed to be an easy way to change tools. So that behavior is by design. I'm not sure I really understand the issue. What exactly are you expecting?

    Regards
    Next time I'm home I'll record the touch probe and send you the code to post. Email or here?

    My issue with the drop down chart auto tool changing is, just by opening the table to look at the tool database for offsets and data entry etc, when I leave that menu the machine automatically performs the tool change. Sliding the tool tray into the work area.

    What command is being sent? Is it an actual m6 g code command or something else?



  16. #16
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Hi Dan,

    Next time I'm home I'll record the touch probe and send you the code to post. Email or here?
    That would be great either way. But if you post here attach the C files as .txt files don't paste them into the message or the formatting will be lost.

    My issue with the drop down chart auto tool changing is, just by opening the table to look at the tool database for offsets and data entry etc, when I leave that menu the machine automatically performs the tool change. Sliding the tool tray into the work area.
    Selecting a Tool from the drop down should perform a tool change. But opening the Tool Table to edit or view it should not. Are you sure that is the case? I just tested and don't see that. What Version of KMotion are you running?

    Regards

    Regards
    TK http://dynomotion.com


  17. #17
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by TomKerekes View Post

    Selecting a Tool from the drop down should perform a tool change. But opening the Tool Table to edit or view it should not. Are you sure that is the case? I just tested and don't see that. What Version of KMotion are you running?

    Regards
    This was the case I recall happening, even if there wasn't a change in tool selection when I clicked away form the menu (anywhere on the screen) causing it drop down list to close, the machine would read a tool change command and execute it even if there was change in tool selection.

    i.e. if Tool 6 was in the spindle, Tool 6 would be dropped off and picked back up again.

    We are running 4.34H



  18. #18
    Member
    Join Date
    May 2012
    Location
    canada
    Posts
    537
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by slimneill View Post
    This was the case I recall happening, even if there wasn't a change in tool selection when I clicked away form the menu (anywhere on the screen) causing it drop down list to close, the machine would read a tool change command and execute it even if there was change in tool selection.

    i.e. if Tool 6 was in the spindle, Tool 6 would be dropped off and picked back up again.

    We are running 4.34H
    My machine changes only when you use the drop down list. No action when you open tool table. Also you should add a check to your toolchange program for requested tool and current tool being equal and end the program. No need to actually do a tool change when the current tool is loaded.



  19. #19
    Member
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    216
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by mmurray70 View Post
    My machine changes only when you use the drop down list. No action when you open tool table. Also you should add a check to your toolchange program for requested tool and current tool being equal and end the program. No need to actually do a tool change when the current tool is loaded.
    Which spindle are you using? I'm curious as to how you verify that it isn't rotating?

    My HSD spindle has a signal that is on/off for 180deg rotation while operating the signal looks like it's on full time but there is a 50% chance that you will get a high signal even when the spindle isn't moving.

    My VFD (HITACHI) has an output signal which goes high when zero RPM is achieved which is what I'm using.



  20. #20
    Member
    Join Date
    May 2012
    Location
    canada
    Posts
    537
    Downloads
    0
    Uploads
    0

    Default Re: Automatic Tool Change C Code

    Quote Originally Posted by slimneill View Post
    Which spindle are you using? I'm curious as to how you verify that it isn't rotating?

    My HSD spindle has a signal that is on/off for 180deg rotation while operating the signal looks like it's on full time but there is a 50% chance that you will get a high signal even when the spindle isn't moving.

    My VFD (HITACHI) has an output signal which goes high when zero RPM is achieved which is what I'm using.
    My toolchange program checks if the spindle is running (just reads the CW and CCW bits) and if it is, it turns it off and waits 3 seconds for it to stop. It then orientates, and waits for orientation signal before actually changing the tool.

    You would probably be safe enough to just check if its on, tell it to stop, wait and then toolchange. Make sure your not using any manual switches or anything that could leave spindle on. If you want to be extra sure maybe you could get it to read that sensor and make sure the state isnt changing for a second or so.



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

Automatic Tool Change C Code

Automatic Tool Change C Code