585,663 active members*
3,074 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > Dynomotion/Kflop/Kanalog > Automatic tool changer program for a 8 tool turret Diy lathe cnc
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2006
    Posts
    33

    Automatic tool changer program for a 8 tool turret Diy lathe cnc

    Hi, i´m building a cnc lathe, i have no problem with mechanical part but i´m a begginer with Kflop and C programming, ok, i´ll try to explain that i have and what i would like achieve

    the plate with the 8 tools turn with a servomotor (currently config in kflop like A axis, set it like 1mm is one tool jump), i can lock/unlock the plate base with a pneumatic cilinder, commanded by a electric valve driven by kflop board (IO20) through external relay, i leave a video of the mechanical assembly
    CNC TURRET 8 POSITION TOOL CHANGER FOR A CNC LATHE - YouTube
    the secuence can be like this:

    - set the tool
    - unlock the turret plate (IO20 on)
    - wait time
    - turn the A axis (1mm = 1 tool, G0 A8 is the tool 8))
    - wait time
    - lock the turret plate (IO20 off)

    note: the second wait time it´s not the same for all tool change, to change tool 1 to the tool 2 it´s shorter than change from tool 1 to the tool 8

    and i would like to do this:
    - make the tool change using "T" and "M06" commanded in the Gcode program, the tool plate should turn by the shortest path

    and in other side, i´ll would like to use and external control, in this control i have 8 buttons (each button it´s wired to one input to kflop) ok, when i press one tool button, the turret unlock (IO20) the tool plate, turn (A axis) to the commanded tool and lock again, if i press one tool button more than 4sg, the turret don´t turn but set this tool like the working tool, and if i pulse more than one button--> error, or don´t move

    regards
    P.D: when it works, I promise to upload a video

  2. #2
    Join Date
    May 2006
    Posts
    4045
    Hi tessen,

    Are you planning to use mach3 or KMotionCNC?

    Which axis channel controls the Turret?

    How many counts or steps per tool?

    Regards
    TK
    http://dynomotion.com

  3. #3
    Join Date
    Aug 2006
    Posts
    33
    Hi Tom, thank for your help
    from i have tried kmotioncnc i don't want to hear to speak about mach3
    the turret axis is the channel 2, to change one tool i have to send 4250 pulses (34000pulses/rev)

    best regards

  4. #4
    Join Date
    May 2006
    Posts
    4045
    Hi tessen,

    On power up how will you be able to determine where the turret is? Will you do some sort of Home sequence?

    Regards
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Aug 2006
    Posts
    33
    Hi Tom
    currently i don't have any homing sequence, i have to set it manually, for this reason i would like to set the tool position from the external control

  6. #6
    Join Date
    May 2006
    Posts
    4045
    Hi tessen,

    Oh so on power up the Operator will need to check what tool position it is currently at. If he/she sees that it is at tool position 7 then he/she will hold down button #7 for 4 seconds. Is that correct?

    Regards
    TK
    http://dynomotion.com

  7. #7
    Join Date
    Aug 2006
    Posts
    33
    Hi Tom
    yes, that's right

    regards

  8. #8
    Join Date
    May 2006
    Posts
    4045
    Hi tessen,

    Here is some code. You forgot to specify some things like how/where the 8 buttons would be connected. You may have to change some defines.

    It turned out a bit more complex because it is written as a state machine. A state machine approach allows a single Thread of execution to keep track of what it is doing and go off and do something else and then come back to what it was doing.

    Actually there are two state machines ServiceToolChange and ServiceToolButtons. The first does your little unclamp, wait, move turret, clamp, wait, sequence. The second monitors the buttons to see if one is pushed or released and for how long and then either initializes the position, starts a tool change, or does nothing.

    I've included a main forever loop to call the two state machines so you can test running as a separate Thread. But after it is all working you can add the calls to your Init program loop.

    Here is the code:

    Code:
    #include "KMotionDef.h"
    
    // Services Tool Changer using non-blocking State Machine approach
    // The Service routines maintain their state so they can always return
    // immediately and later resume from their previous state.
    
    // T O O L   C H A N G E R   S E Q U E N C E
    //
    // define state that the tool changer may be in
    enum {T_IDLE,T_START,T_WAIT_UNCLAMP,T_WAIT_MOVE,T_WAIT_CLAMP};
    
    #define TOOL_VAR 9        	// Tool changer desired new tool Var
    #define TOOL_STATE_VAR 8  	// Tool changer state is saved globally in this Var
    #define LAST_TOOL_VAR 7   	// Tool changer Last tool position is saved globally in this Var
    #define TOOL_CLAMP_BIT 20 	// IO bit number to clamp turret
    #define TOOL_DIST 4250.0	// Steps/counts to move turret to next tool
    #define CLAMP_TIME 1.5    	// seconds to wait for the clamp/unclamp
    #define TURRET_AXIS 2     	// axis channel for the turret motor
    
    int *ChangerState 	= &persist.UserData[TOOL_STATE_VAR];
    int *Tool     		= &persist.UserData[TOOL_VAR];
    int *LastTool 		= &persist.UserData[LAST_TOOL_VAR];
    
    double ToolTime;
    
    // Services Tool Change Sequence
    void ServiceToolChange(void)
    {
        switch (*ChangerState)
        {
        case T_IDLE:
            {
                break;
            }
        case T_START:
            {
                if (*LastTool==0)
                {
                    printf("Error Turret Position Never defined\n");
                    *ChangerState = T_IDLE;  // go idle
                }
                else if (*Tool > 8 || *Tool < 1)
                {
                    printf("Invalid Tool Number %d\n",*Tool);
                    *ChangerState = T_IDLE;  // go idle
                }
                else
                {
                    printf("Tool Change Unclamp\n");
                    ClearBit(TOOL_CLAMP_BIT);  // Release Clamp
                    ToolTime = Time_sec() + CLAMP_TIME;  // wait until this time
                    *ChangerState = T_WAIT_UNCLAMP;
                }
                break;
            }
        case T_WAIT_UNCLAMP:
            {
                if (Time_sec() > ToolTime)
                {
                    // time to move.  Compute distance
    
                    int delta = *Tool - *LastTool;  // how far to move 
                    if (delta>4)  delta-=8;		// optimize direction
                    if (delta<-4) delta+=8;
    
                    printf("Turret Moved From %d to %d, delta = %d\n", *LastTool,*Tool,delta);
                    *LastTool = 0;  // set as undefined while moving
                    MoveRel(TURRET_AXIS,delta*TOOL_DIST);
    
                    *ChangerState = T_WAIT_MOVE;
                }
                break;
            }
        case T_WAIT_MOVE:
            {
                // check if disabled
                if (!chan[TURRET_AXIS].Enable)
                {
                    *ChangerState = T_IDLE;
                }
                else if (CheckDone(TURRET_AXIS))
                {
                    printf("Tool Change Clamp\n");
                    SetBit(TOOL_CLAMP_BIT);  // Clamp
                    ToolTime = Time_sec() + CLAMP_TIME;  // wait until this time
                    *ChangerState = T_WAIT_CLAMP;
                }
                break;
            }
        case T_WAIT_CLAMP:
            {
                // if clamped go idle
                if (Time_sec() > ToolTime)
                {
                    printf("Tool Change Complete\n");
                    *LastTool = *Tool;  // remember where we are
                    *ChangerState = T_IDLE;
                }
                break;
            }
        }
    }
    
    // E X T E R N A L   T O O L   B U T T O N   M A N A G E M E N T 
    //
    // define states that the tool button service may be in
    enum {T_IDLE,T_ONE_BUTTON_PUSHED};
    
    double ToolButtonTime;
    int ButtonState = T_IDLE;
    int LastButton;
    
    #define FIRST_TOOL_BUTTON 36
    #define NUM_TOOL_BUTTONS 8
    
    #define LONGPUSH 4.0  	// Push button this long to force tool number
    #define SHORTPUSH 1.0  	// Push button this long to do tool change
    
    // returns button number 0-N if one single button pushed
    // otherwise returns -1 if no buttons pushed
    // or -2 if more than one button pushed
    
    int CheckForOneButtonPushed(void)
    {
        int i,b,n=0;
    
        for (i=0; i<NUM_TOOL_BUTTONS; i++)
        {
            if (ReadBit(FIRST_TOOL_BUTTON+i))
            {
                b=i; // rememeber last one
                n++; // remember how many
            }
        }
        if (n==1) return b; 	// one pushed, return which one
        if (n==0) return -1; 	// none pushed, return -1
        return -2; 				// more than one, return -2
    }
    
    // Services Some Operator buttons to perform two functions
    // A short duration push of a single button will cause a tool change
    // A long duration push of a single button will set the current turret
    // position as that tool number
    void ServiceToolButtons(void)
    {
        int NewButton=CheckForOneButtonPushed();
        double T=Time_sec();
    
        switch (ButtonState)
        {
        case T_IDLE:
            {
                // Single button pushed?
                if (NewButton >= 0)
                {
                    LastButton=NewButton;
                    ToolButtonTime=T;
                    ButtonState = T_ONE_BUTTON_PUSHED;
                }
                break;
            }
        case T_ONE_BUTTON_PUSHED:
            {
                // same one still pushed?
                if (NewButton != LastButton)
                {
                    // no, check for more than one pushed
                    if (NewButton==-2)
                    {
                        // more than one, do nothing and start over
                    }
                    // check how long it had been pushed
                    else if (T > ToolButtonTime + LONGPUSH)
                    {
                        *LastTool = LastButton+1;  // set tool number
                        printf("Turret Set as Tool %d\n",*LastTool);
                    }
                    else if (T > ToolButtonTime + SHORTPUSH)
                    {
                        // short push, initiate a ToolChange if
                        // Tool Changer is idle
                        if (*ChangerState == T_IDLE)
                        {
                            *Tool = LastButton+1;  // set new tool to load
                            *ChangerState = T_START;  // Go!
                            printf("Tool %d Change Initiated\n",*Tool);
                        }					
                    }
                    ButtonState = T_IDLE;  // go back to idle state
                }
                break;
            }
        }
    }
    
    // Loop servicing things
    main()
    {
        for (;;)  // loop forever
        {
            WaitNextTimeSlice();
            ServiceToolChange();
            ServiceToolButtons();
        }
    }
    Here is a program that you can assign to your M6 to initiate a Tool change from GCode.

    Code:
    #include "KMotionDef.h"
    
    // Assumes a Tool Changer State Machine is running in a forever loop
    // (which is necessary to allow external buttons to change tools)
    
    #define TOOL_STATE_VAR 8  	// Tool changer state is saved globally in this Var
    #define TOOL_VAR 9        	// Tool changer desired new tool Var
    // define state that the tool changer may be in
    enum {T_IDLE,T_START,T_WAIT_UNCLAMP,T_WAIT_MOVE,T_WAIT_CLAMP};
    
    main()
    {
        int *ChangerState    = &persist.UserData[TOOL_STATE_VAR];
        int Tool = persist.UserData[TOOL_VAR];  // value stored is an integer 
    
        if (*ChangerState == T_IDLE)
        {
            *ChangerState = T_START;  // Go!
            printf("Tool %d Change Initiated\n",Tool);
    
            // wait till finished
            while (*ChangerState != T_IDLE)
                WaitNextTimeSlice();
        }
        else
        {
            printf("Error Tool Changer not idle");
        }					
    }
    There are a number of debug messages included. So if it doesn't work check the Console Screen for what happens.

    Regards
    TK
    http://dynomotion.com

  9. #9
    Join Date
    Aug 2006
    Posts
    33
    Hi Tom
    i try to run your program, but not works yet, i don't know that i´m doing wrong
    this is my config

    M6 (Extecute prog)-->Thread 2 -->VAR 0 --> C file=ToolM6TrigService.c

    in thread 1 i have running my init file and i can move all axis, to test the program i launch the ServiceToolChange.c in the thread 3 but nothing happens when i try to change the tools through command line

    TOOLS (all buttons are Normally Closed, conected to +3.3v)
    T1 --> IO23
    T2 --> IO24
    T3 --> IO25
    T4 --> IO31
    T5 --> IO32
    T6 --> IO33
    T7 --> IO45
    T8 --> IO44

    best regards and thanks for your time

  10. #10
    Join Date
    May 2006
    Posts
    4045
    Hi tessen

    The M6 must be configured to pass the Tool Number in the Var that the C program is looking for it. This is defined in the C program as:

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

    Using Thread #2 is ok. But you may want to change to Execute Prog/Wait so that the GCode will wait until the tool change finishes.

    Couldn't you see where to change the Button IO numbers? Change:

    #define FIRST_TOOL_BUTTON 36

    to

    #define FIRST_TOOL_BUTTON 23

    If your Buttons are all negative logic (go low when pushed - check the Digital I screen). Then change:

    if (ReadBit(FIRST_TOOL_BUTTON+i))

    to

    if (!ReadBit(FIRST_TOOL_BUTTON+i))


    In the C Language the "!" symbol is the "NOT" operator.

    HTH
    Regards
    TK
    http://dynomotion.com

  11. #11
    Join Date
    Aug 2006
    Posts
    33
    Hi Tom!
    the toolchanger running, the video i had promised

  12. #12
    Join Date
    May 2006
    Posts
    4045
    Nice! I like the tool change dance.
    Thanks
    TK
    http://dynomotion.com

Similar Threads

  1. lathe automatic tool changer(turret)
    By valmet58 in forum Uncategorised MetalWorking Machines
    Replies: 5
    Last Post: 05-04-2014, 07:09 PM
  2. CAM: Tool path generation for ATC Automatic Tool Changer
    By S.Seveelavanan in forum Uncategorised CAM Discussion
    Replies: 10
    Last Post: 08-09-2012, 04:45 PM
  3. Hoss 16 Tool Automatic Tool Changer
    By hoss2006 in forum Benchtop Machines
    Replies: 316
    Last Post: 03-03-2011, 10:29 PM
  4. Need Help! - Automatic Tool Changer
    By mattjames in forum DNC Problems and Solutions
    Replies: 2
    Last Post: 08-17-2009, 04:51 AM
  5. Automatic Tool Changer
    By spalm in forum DIY CNC Router Table Machines
    Replies: 4
    Last Post: 07-11-2007, 01:49 AM

Posting Permissions

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