532,058 active members*
3,633 visitors online*
Register for free
Login
Results 1 to 17 of 17
  1. #1
    Registered
    Join Date
    Dec 2006
    Posts
    31

    M6 - Tool change sequence

    Hello,

    It's been a while since I've been involved into C programming and I can't find what's wrong with my code...
    If somebody would have a look at the attached file it would be great!

    Thanks for your attention,

    Jerome

  2. #2
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    You might compile with the TI Compiler or use Validate code to have additional error and warning reporting. You might watch this

    Video.



    I see you have ZUp_TcPos and Z_TcPos first declared as integers then as floats. You should probably remove the integer declaration.

    Compare is declared as a function but then used in a switch statement without parenthesis. The name of a function without parenthesis is the function's address. Not the returned value of a call to a function as I expect you want.

    TCPos() is used before it is declared

    Function AngularPosition is declared to take 3 parameters but the function itself only has 2. Also missing parameter types

    ActSlotPos is missing parameter types

    Function Compare can return without returning an integer value

    else (ReadBit(CarRef) == 0) is missing the "if" command. Actually the if and condition can be removed entirely as the 'else" clause should always be true because it is the opposite of the 'if' condition (unless the bit just changed)

    else (k > i || j > i) probably missing 'if'

    else (*ActTool != *OldTool) probably missing 'if'

    'While' has capital W instead of lower case w. So compiler thinks it is a function, Multiple places

    In C, strings are handled as arrays of characters. Individual characters can be specified with apostrophes as 'H'. Arrays of characters can be specified with quotes as "Home". This code:

    char Position;

    Position = 'Home'; //This means we are at home and the action to perform is a move to Tool Change Position

    Uses apostrophes to declare an array of characters. Also attempts to store multiple characters into a single character variable. Since you seem to be using Position just as an internal state the simplest thing might be to use a single character. 'H' and 'T'.

    Any code placed after a 'return' that is executed will never be executed. So with:

    return 0;
    break;

    the 'break' doesn't make sense.

    HTH
    TK
    http://dynomotion.com

  3. #3
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hi Tom,

    Thanks for our answers and help to clarify many issues.

    In between I've cleaned the code but still have some issues like this:
    " C Programs\1.33_Compare_M6_test.c:316: ';' expected "
    This errors occurs in that section of the code:

    /*-------------------------------
    ---ClockWise Rotation Function---
    -------------------------------*/
    int CW()
    {
    SetBit(CarCW);
    printf("CW()=> CWPos = %d\n",CWPos);
    for (x=1;x<=CWPos;x++)
    {
    printf("for x=%d \n",x);

    While(ReadBit(K)<1)
    {
    WaitNextTimeSlice();
    }
    j=1;

    While (ReadBit(J)<1)
    {
    WaitNextTimeSlice();
    }
    k=1;

    printf("j=%d \n",j);
    printf("k=%d \n",k);
    printf("x%d \n",x);
    ptr=&x;
    *ActSlot=*ActSlot++;

    While (ReadBit(Index)<1)
    {
    WaitNextTimeSlice();
    }
    }
    ClearBit(CarCW);
    return CWPos;
    }

    But I can't figure out why so I joined the updated file to this message.

    If you would have a look it would be nice.

    Thanks again,

    Jerome

  4. #4
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    There are 21 instances of "While" with a capital W

    This line:

    Code:
    	while((ReadBit(CarRef);)<1)
    has an extra ; Also == 0 would be more logical. Also an unnecessary set of parenthesis

    This:

    Code:
    	else (*ActTool!=*OldTool)
    is missing the 'if'

    These:

    Code:
    	int ReadBit();
    	int SetBit();
    Are defined by KMotionDef.h and take a parameter so should not be redefined incorrectly by you

    Code:
    	GrayToBinary16();
    is defined in the wrong place and doesn't specify the return type

    This is defined twice. The second is in the wrong place
    Code:
    	float AngularPosition(int D, float alphaRes);

    Many unused variables remove them

    This:

    Code:
    		i;
    does nothing

    With this code:

    Code:
    		if (*ActTool==*OldTool)
    		{
    			i=1;
    			printf("The actual tool is T#%d",*ActTool);
    		}
    		else if(*ActTool!=*OldTool)
    		{
    			OldTool=&persist.UserData[9+5];//Need to check the tool number or the tool Number depending on the Slot
    		}
    Since you already tested if they were equal in the else condition they will always be unequal so no need for a test. There are 2 instances of this.

    This:

    Code:
    		*ActSlot=*ActSlot++;
    increments the address of where ActSlot points to rather than the value where ActSlot is pointing to. Also post incrementing may occur before/after it is stored. So better to code:
    Code:
    		(*ActSlot)++;
    Similarly:

    Code:
    			i=i++;
    should be: (multiple places)
    Code:
    			i++;
    This code uses Position in the switch with the posibility of never being set to a valid value:

    Code:
    	int Position;
    	
    	if(ReadBit(AirCylHomePos))
    	{
    		Position=0; //This means we are at home and the action to perform is a move to Tool Change Position
    	}
    	else if(ReadBit(AirCylToolPos))
    	{
    		Position=1;
    	}
    		
    	switch(Position)
    The code is indented improperly in places making it confusing and hard to read. Please use the Auto Indentor as described in this Video:

    https://youtu.be/CsIijoLMq8U

    btw there is a trick shift/xor method to convert Gray code to binary requiring only n+1 operations for 2^n bits, You might Google it and see this recent post on our Forum
    HTH
    TK
    http://dynomotion.com

  5. #5
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hello Tom,

    Thanks for the feedback.

    I changed the code like you suggested and have been closing some faults.

    Actually, when I'm compiling with Cpp check I read these notifications of errors with KflopToKMotionCNCFunctions.c :

    Checking C:\KMotion435d\C Programs\1.36_Compare_M6_test.c ...
    C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c, line 109 : error arrayIndexOutOfBounds
    Array 'persist.UserData[100]' accessed at index 102, which is out of bounds.
    persist.UserData[PC_COMM_PERSIST+2] = TMP; // persist offset (doubles)
    ^

    C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c, line 119 : error arrayIndexOutOfBounds
    Array 'persist.UserData[100]' accessed at index 102, which is out of bounds.
    persist.UserData[PC_COMM_PERSIST+2] = TMP; // persist offset (doubles)

    I have many of these notifications and the same issues occurs with TI compiler for other reasons like those:

    "C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c", line 18: error: identifier "persist" is undefined
    "C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c", line 26: error: identifier "persist" is undefined
    "C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c", line 52: error: identifier "PC_COMM_GET_DROS" is undefined
    "C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c", line 64: error: identifier "PC_COMM_GET_MACHINE_COORDS" is undefined
    "C:\KMotion435d\C Programs\KflopToKMotionCNCFunctions.c", line 76: error: identifier "PC_COMM_GET_MISC_SETTINGS" is undefined

    I also would like to understand which variable is used to get the Tool ID, is it TWORD? The number I receive is totally different from the one stored into the Default table.

    KR,

    Jerome
    Attached Files Attached Files

  6. #6
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hello Tom,

    I found what was wrong with my code => I used the same declarations at the beginning of my files and one was cancelling the other due to variables declarations conflicts.

    Anyway, that's not the end of the story:
    The question I asked before still exists, where or how the settings from the tool ID are taken from the tool table because the results aren't aligned with the content of the tool table definition?

    When the code is executed I can see this:

    Actual alpha is: 325
    Actual Slot = 2
    Actual persist.UserData[9+2] = 2
    ActSlot = 2
    Units=2 T=4 H=10 D=1
    The Next Tool is: T#4

    The actual slot position is:2
    The Old Tool is T#0 The Previous Slot is #3090
    The Actual Tool is T#1 The Actual Slot is #2
    The NewTool is T#4 The Requested Slot is #2
    Bit#1046 G0=1
    Bit#1047 G1=1
    Bit#1048 G2=0
    Bit#1049 G3=0
    Bit#1050 G4=1
    Bit#1051 G5=0
    Bit#1052 G6=1
    Bit#1053 G7=0
    Bit#1054 G8=0
    Bit#1055 G9=1

    B9=1 p9=512
    B8=1 p8=256
    B7=1 p7=128
    B6=0 p6=0
    B5=0 p5=0
    B4=1 p4=16
    B3=1 p3=8
    B2=1 p2=4
    B1=0 p1=0
    B0=1 p0=1
    decimal=925 alphaRes=2.844445 alpha=325

    decimal=925 alphaRes=2.844445 alpha=325

    Actual alpha is: 325
    Actual Slot = 2
    Actual persist.UserData[9+2] = 2
    ActSlot = 2
    Case #1
    LoadSpindleAssume a CW Move => CWPos = 0
    CWPos=CWPos (0) + NSlot (10)
    CCWPos(10) =NSlot(10) - CWPos(0)
    CW()=> CWPos = 0


    So the actual Slot# is correct and read from the absolute encoder, not from the persist anymore.
    The previous Slot# comes from nowhere [1-10] and the tools # aren't correct:

    Neither Tool#2&4 does exist and the associated Slot number with Tool#4 is 2, this means the same as the previous one.
    The result is a LeastTravel function that returns a non-move action but load the spindle with obviously the same tool as before, Tool#2 in this case:

    Actual persist.UserData[9+2] = 2
    ActSlot = 2
    Case #1
    LoadSpindleAssume a CW Move => CWPos = 0
    CWPos=CWPos (0) + NSlot (10)
    CCWPos(10) =NSlot(10) - CWPos(0)
    CW()=> CWPos = 0


    When I execute the code with any different Tool#, the status described above is consistent and demonstrates the issue.
    This comes back to my question, how can I get the correct data to process the code with both, the Tool ID and Slot # ?

    Thanks to clarify this point.

    Kr,

    Jerome

  7. #7
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    I don't understand much of that but:

    The code you sent won't even compile because this:

    Code:
    #define TMP 9					// which spare persist to use to transfer data
    Was placed after

    Code:
    #include "KflopToKMotionCNCFunctions.c"
    Did you post the correct code?



    Also TMP defines which persist variables will be used by KflopToKMotionCNCFunctions.c. It uses a few variables to communicate to KMotionCNC. So variables 9 - 19 should not be used for other things. But you are using them:

    Code:
    	ReqSlot = &persist.UserData[9];	//Pocket# of the new Tool ID#
    	NewTool = &persist.UserData[9 + 1];	//Tool ID# needed
    	ActSlot = &persist.UserData[9 + 2];	//Actual Tool ID#
    	ActTool = &persist.UserData[9 + 3];	//Actual Pocket#
    	PrevSlot = &persist.UserData[9 + 4];	//Previous Pocket# used as temporary variable while changing tools
    	OldTool = &persist.UserData[9 + 5];	//Previous Tool ID# used as temporary variable while changing tools



    Many unused variables and duplicate functions. Please put some effort into cleaning up your code.

    "C:\Users\tk\Downloads\1.37_Compare_M6_test.c" , line 331: error: function "GrayToBinary16" has already been defined
    "C:\Users\tk\Downloads\1.37_Compare_M6_test.c" , line 364: error: function "AngularPosition" has already been defined
    "C:\Users\tk\Downloads\1.37_Compare_M6_test.c" , line 378: error: function "ActSlotPos" has already been defined




    Pointers are not being used correctly. You are confusing the address of a variable with the value of the variable. The '*" operator can be interpreted as "get the value at the address of". The opposite is the '&' operator which can be interpreted as "get the address of the value of". So for example you have declared these pointers:

    Code:
    PrevSlot = &persist.UserData[9 + 4];	//Previous Pocket# used as temporary variable while changing tools
    ActSlot = &persist.UserData[9 + 2];	//Actual Tool ID#
    "PrevSlot" is a pointer (the address of) to persist variable 13. And ActSlot is a pointer to persist variable 11

    If you execute:

    Code:
    PrevSlot = ActSlot;
    Now both pointers point to variable 11 which is probably not what you want.

    To copy the value of variable 11 into variable 13 code:

    Code:
    *PrevSlot = *ActSlot;
    HTH
    TK
    http://dynomotion.com

  8. #8
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hi Tom,

    I implemented the changes, I still get one error with TI compiler =>"C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: error: identifier "VirtualBitsEx" is undefined

    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 85: warning: function declared implicitly
    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: warning: function declared implicitly
    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: error: identifier "VirtualBitsEx" is undefined
    1 error detected in the compilation of "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c".


    TMP is now changed to 3 and tool setup VAR too

    #include "KMotionDef.h"
    #define TMP 3 // which spare persist to use to transfer data
    #define Zaxis 2
    #define Spindle 3
    #include "KflopToKMotionCNCFunctions.c"
    #define PC_COMM_PERSIST 100
    #define N_PC_COMM_PERSIST 8

    The code doesn’t produce the expected results the tool ID and the Slot number aren't in line with the tool table:

    Actual alpha is: 325
    Actual Slot = 2
    Actual persist.UserData[3+2] = 2
    ActSlot = 2
    Units=2 T=13 H=13 D=1
    The Next Tool is: T#13

    The actual slot position is:2
    The Old Tool is T#0 The Previous Slot is #3090
    The Actual Tool is T#1 The Actual Slot is #2
    The NewTool is T#13 The Requested Slot is #2
    Case #1
    I don't understand why the parameters aren't the ones listed in the tool table.

    Do you have an idea?

    The cleaned and corrected code is in attachment.

    Thanks,

    Jerome

  9. #9
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    I implemented the changes, I still get one error with TI compiler =>"C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: error: identifier "VirtualBitsEx" is undefined

    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 85: warning: function declared implicitly
    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: warning: function declared implicitly
    "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c", line 86: error: identifier "VirtualBitsEx" is undefined
    1 error detected in the compilation of "C:\KMotion435d\C Programs\1.38_Compare_M6_test.c".
    I don't get any errors. That would occur if KMotionDef.h wasn't included. Again it seems code you are sending me is different from what you are testing.


    TMP is now changed to 3 and tool setup VAR too
    In this case you still have the same conflict. I'm assuming you have this program assigned to M6 and are executing M6Txxxx? What Gcode are you running?

    What is happening is:

    #1 you execute M6Txxxx
    #2 KMotionCNC puts the slot of the desired new Tool into Var 3 and executes the program.
    #3 The program executes GetMiscSettings() in KflopToKMotionCNCFunctions.c which uses Var 3 to communicate to KMotionCNC
    #4 Var 3 has now been corrupted
    #5 The program prints *ReqSlot which is the corrupted Var 3 value



    Note: GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD); should not normally be necessary. KMotionCNC has already specified which tool slot should be loaded.


    Note if you are interested in better programming practices it is best to only use global variables when necessary. This is because to understand a global variable the entire program needs to be considered not just a function. And if you have a global variable its good to use a descriptive name. Functions that modify global variables are considered to be bad and confusing. Good functions are given data and return results without having surprise side effects, So for example:


    Code:
    	GrayToBinary16();
    	AngularPosition(D, alphaRes);
    GrayToBinary modifies global variable D which is then passed to AngularPosition. Better to use a local variable:

    Code:
    	unsigned short int D;
    	D=GrayToBinary16();
    	AngularPosition(D, alphaRes);
    And I would suggest removing all the global variables that aren't used.



    This in GrayToBinary16() is dangerous:

    Code:
    	BIN[9] = *ptr = GRAY[9];
    This is writing to where the pointer ptr is pointing to before ptr has been assigned to point to something. This is one of the worst bugs to have as things can be changed/corrupted at random that may not be noticed until later with difficulty tracing back to how it happened. I also don't see any purpose.


    This function is declared without parameter types:
    Code:
    int ActSlotPos(AngularPosition, Nslot, ActPos)
    TK
    http://dynomotion.com

  10. #10
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hello Tom,

    The code I have sent is exactly the one I've compiled.

    To simplify the debugging I'm working on the code part that receives the data to induce motion and results in positioning the umbrella for the next tool.
    This means:
    1. Getting the data
    2. Assigning the data to variables
    3. Printing the data for information purposes
    4. Executing the following sequence:
      1. D=GrayToBinary16(); //Converting the absolute encoder position to a decimal number
      2. AngularPosition(D, alphaRes); //Converting the decimal number to an angle (degrees)
      3. ActSlotPos(alpha, NSlot, ActPos); //Converting that angle to a numerical position value > 10 slots >1/36°
      4. LeastTravel(); //Choosing from a Clockwise(CW) or Counter Clockwise (CCW) rotation to reduce the tool change time.


    The main issue I encounter is the data incoming to the program from KMotionCNC.
    When I execute an M6 from from the tool table drop down and ie choose the tool ID 7700, the results printed on the console screen are :

    Units=2 T=13 H=13 D=1
    The Next Tool is: T#13

    The actual slot position is:13
    The Old Tool is T#10 The Previous Slot is #1
    The Actual Tool is T#1 The Actual Slot is #13
    The NewTool is T#13 The Requested Slot is #2
    Bit#1046 G0=1
    Bit#1047 G1=1
    Bit#1048 G2=0
    Bit#1049 G3=0
    Bit#1050 G4=1
    Bit#1051 G5=0
    Bit#1052 G6=1
    Bit#1053 G7=0
    Bit#1054 G8=0
    Bit#1055 G9=1

    B9=1 p9=512
    B8=1 p8=256
    B7=1 p7=128
    B6=0 p6=0
    B5=0 p5=0
    B4=1 p4=16
    B3=1 p3=8
    B2=1 p2=4
    B1=0 p1=0
    B0=1 p0=1
    decimal=925 alphaRes=2.844445 alpha=325

    Actual alpha is: 325
    Actual persist.UserData[TMP+2] = 2
    ActSlot = 2
    Assume a CW Move => CWPos = 0
    CWPos=CWPos (0) + NSlot (10)
    CCWPos(10) =NSlot(10) - CWPos(0)
    CW()=> CWPos = 0

    This is obviously incorrect since the tool table is:


    SLOT ID LENGTH DIAMETER XOFFSET YOFFSET COMMENT IMAGE

    10 1000 40.000000 10.000000 0.000000 0.000000 "" ""
    9 1100 60.000000 16.000000 0.000000 0.000000 "" ""
    9 1109 30.000000 6.000000 0.000000 0.000000 "" ""
    8 2200 0.000000 0.000000 0.000000 0.000000 "" ""
    8 2201 10.000000 14.000000 0.000000 0.000000 "" ""
    7 3300 0.000000 0.000000 0.000000 0.000000 "" ""
    7 3301 25.000000 4.000000 0.000000 0.000000 "" ""
    6 4400 0.000000 0.000000 0.000000 0.000000 "" ""
    6 4401 36.000000 5.000000 1.000000 2.000000 "Front NPTF Lathe tool" "NPTF Front.wrl"
    5 5500 0.000000 0.000000 0.000000 0.000000 "" ""
    5 5501 45.000000 6.000000 0.000000 0.000000 "" ""
    4 6600 0.000000 0.000000 0.000000 0.000000 "" ""
    4 6601 10.000000 3.000000 0.000000 0.000000 "" ""
    3 7700 0.000000 0.000000 0.000000 0.000000 "" ""
    3 7701 38.000000 8.000000 0.000000 0.000000 "" "EndMill-z.wrl"
    2 8800 0.000000 0.000000 0.000000 0.000000 "" ""
    2 8801 25.000000 12.000000 0.000000 0.000000 "" ""
    1 9900 0.000000 0.000000 0.000000 0.000000 "" ""
    1 9901 23.000000 10.000000 0.000000 0.000000 "" ""

    The test program is attached, does it gives the same results on your computer?
    NB: TMP value is from "KflopToKMotionCNCFunctions.c"

    Thanks for your help,

    Jerome
    Attached Files Attached Files

  11. #11
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    The code I have sent is exactly the one I've compiled.
    My mistake somehow I deleted the first line.

    NB: TMP value is from "KflopToKMotionCNCFunctions.c"
    I don't understand what you mean. Now the file doesn't compile because TMP isn't defined. Maybe you mean I need to change KflopToKMotionCNCFunctions.c to define it? I defined it to 3 as I'm assuming you have it still set to as well as the KMotionCNC M6 configuration.

    The test program is attached, does it gives the same results on your computer?
    Yes. As I tried to explain before GetMiscSettings() is not normally used for a Tool Change program. It returns the Tool Table index. Basically the line number of the Tool Table which can the be used to request the xy offsets and length. Which for your example is 13.

    And also as I tried to explain using the same Var for communication and passing the tool slot overwrites the original tool slot and ID passed by KMotionCNC.

    I changed the beginning of your main to:

    Code:
    int main()
    {
    	int ToolSlot, ToolID;
    	
    //	 /*INIT*/ InitAux();
    //	AddKonnect(0, &VirtualBits, VirtualBitsEx);
    
    /*-------------------------------------
    --------------Data Input---------------
    -------------------------------------*/
    	ToolSlot = persist.UserData[TMP];
    	ToolID = persist.UserData[TMP+1];
    	printf("ToolSlot = %d, ToolID = %d\n", ToolSlot, ToolID);
    	
    	GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
    	
    	ToolSlot = persist.UserData[TMP];
    	ToolID = persist.UserData[TMP+1];
    	printf("ToolSlot = %d, ToolID = %d\n", ToolSlot, ToolID);
    Which T7700M6 then prints this:


    ToolSlot = 3, ToolID = 7700
    ToolSlot = 2, ToolID = 13
    Units=2 T=13 H=1 D=1
    The Next Tool is: T#13


    Notice it prints the correct Tool Slot and ID before GetMiscSettings() is called but not after.
    TK
    http://dynomotion.com

  12. #12
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hi Tom,

    Thanks for the quick reply.
    Strange that the file doesn't compile, on my computer it does and the TMP value is defined as 3 in "KflopToKMotionCNCFunctions.c"
    Because it's defined in it and included I didn't rewrote a #define TMP 3 in my test file.

    I modified the code as you did for the begining:
    int main()
    {
    int ToolSlot, ToolID;
    /*INIT*/ InitAux();
    AddKonnect(0, &VirtualBits, VirtualBitsEx);

    /*-------------------------------------
    --------------Data Input---------------
    -------------------------------------*/
    ToolSlot = persist.UserData[TMP];
    ToolID = persist.UserData[TMP+1];
    printf("ToolSlot = %d, ToolID = %d\n", ToolSlot, ToolID);

    //GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
    //printf("Units=%d T=%d H=%d D=%d\n", Units, TWORD, HWORD, DWORD);
    //printf("The Next Tool is: T#%d\n", persist.UserData[TMP + 1] = TWORD);
    ReqSlot = persist.UserData[TMP]; //Pocket# of the new Tool ID#
    NewTool = persist.UserData[TMP + 1]; //Tool ID# needed
    ActSlot = persist.UserData[TMP + 2]; //Actual Pocket#
    ActTool = persist.UserData[TMP + 3]; //Actual Tool ID#
    PrevSlot = persist.UserData[TMP + 4]; //Previous Pocket# used as temporary variable while changing tools
    OldTool = persist.UserData[TMP + 5]; //Previous Tool ID# used as temporary variable while changing tools
    printf("\n The actual slot position is:%d\n", ActSlot);
    printf("The Old Tool is T#%d\t The Previous Slot is #%d\n", OldTool, PrevSlot);
    printf("The Actual Tool is T#%d\t The Actual Slot is #%d\n", ActTool, ActSlot);
    printf("The NewTool is T#%d\t The Requested Slot is #%d\n", NewTool, ReqSlot);

    /*-------------------------------------
    -----------Flow Sequence---------------
    -------------------------------------*/
    unsigned short int D;
    D=GrayToBinary16();
    AngularPosition(D, alphaRes);
    ActSlotPos(alpha, NSlot, ActPos);
    LeastTravel();

    return 0;
    }


    Same exercise with Tool ID 7700 from drop down and M6T7700:
    ToolSlot = 0, ToolID = 0

    The actual slot position is:10
    The Old Tool is T#0 The Previous Slot is #0
    The Actual Tool is T#0 The Actual Slot is #10
    The NewTool is T#0 The Requested Slot is #0
    Bit#1046 G0=1
    Bit#1047 G1=1
    Bit#1048 G2=1
    Bit#1049 G3=1
    Bit#1050 G4=1
    Bit#1051 G5=0
    Bit#1052 G6=1
    Bit#1053 G7=0
    Bit#1054 G8=0
    Bit#1055 G9=0

    B9=0 p9=0
    B8=0 p8=0
    B7=0 p7=0
    B6=1 p6=64
    B5=1 p5=32
    B4=0 p4=0
    B3=1 p3=8
    B2=0 p2=0
    B1=1 p1=2
    B0=0 p0=0
    decimal=106 alphaRes=2.844445 alpha=37

    Actual alpha is: 37
    Actual persist.UserData[TMP+2] = 10
    ActSlot = 10
    Assume a CW Move => CWPos = -10
    CWPos=CWPos (0) + NSlot (10)
    CCWPos(10) =NSlot(10) - CWPos(0)
    CW()=> CWPos = 0


    Well it doesn't give the same results as on you computer, same modifications done as shown above.
    I don't use the same variable for communication anymore, since you explained how it was used.
    I previously tought it was the array containing the Slot, Tool numbers and that I could acces the data from that variable.

    What are your thoughts?

    Jerome

  13. #13
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    Strange that the file doesn't compile, on my computer it does and the TMP value is defined as 3 in "KflopToKMotionCNCFunctions.c"
    What Version of KMotion are you using? But I don't believe TMP was ever defined in KflopToKMotionCNCFunctions.c. You might check the date stamp on the file to see if/when it was modified since the software release date. You might re-install KMotion to make sure you don't have modified files. And verify TMP is not defined within KflopToKMotionCNCFunctions.c in the fresh installation.

    Do you have KMotionCNC M6 Var configured for the same as TMP is defined?
    TK
    http://dynomotion.com

  14. #14
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hi Tom,

    I reinstalled KMotion4.35d and kept the old files excepted for KflopToKMotionCNCFunctions that is brand new, and effectively no TMP # defined.




    The file compiled is the same as previously given, whatever the TMP value <9, it doesn't change anything. The code is below and the results here after the code.

    #include "KMotionDef.h"
    #define Zaxis 2

    #define TMP 3
    #include "KflopToKMotionCNCFunctions.c"
    #define PC_COMM_PERSIST 100
    #define N_PC_COMM_PERSIST 8

    #define round(x) ((x)>=0?(long)((x)+0.5)long)((x)-0.5))
    #define QA 40 // define to which IO bits the AB signals are connected
    #define QB 41
    #define AirCylHomePos 138 //Carousel air cylinder is at home position
    #define AirCylToolPos 139 //Carousel air cylinder is at tool change position
    #define AirCyl 156 // Activate Air Cylinder for tool change
    #define ERes 1024 //Encoder Resolution, 10bits
    #define DeltaD 102 //Decimal value to compensate for absolute encoder zero alignment

    /*INPUTS and OUTPUTS*/
    /*INPUTS*/
    #define Index 137 //Indexing sensor to index the carousel position at each motor turn, CW or CCW
    #define CarRef 25 //When active carousel is at reference position corresponding to pocket #1
    #define J 1031 // Indexing sensor to control the indexing motor CW/CCW
    #define K 1030 // Indexing sensor to control the indexing motor CW/CCW
    #define G0 1046 // Konnect: 10bits for the gray code G1=>G10
    #define G1 1047 // G0 stands for Gray and 0 the power factor => 2^0,..., G9 => 2^9
    #define G2 1048
    #define G3 1049
    #define G4 1050
    #define G5 1051
    #define G6 1052
    #define G7 1053
    #define G8 1054
    #define G9 1055
    /*OUTPUTS*/
    #define CarCW 154 //Carousel ++Pocket index
    #define CarCCW 155 //Carousel --Pocket index
    /*------------------------------
    --Global variables declaration--
    ------------------------------*/
    int x;
    int index, CWPos, CCWPos;
    int OldTool, ActTool, ActSlot, NewTool, PrevSlot, ReqSlot;
    int Units, TWORD, HWORD, DWORD;
    unsigned short int GRAY[10], BIN[10];
    int i, j, k;
    int CW(); //Moves the umbrella clockwise
    int CCW(); //Moves the umbrella counterclockwise
    int LeastTravel(); // Determines the least amount of travelling time to reach a specific pocket or tool with an umbrella type tool changer
    unsigned int GrayToBinary16(); //Converts the Gray Code from an absolute encoder to a binary number (0-360 degrees)
    int alpha; //Angular position of the umbrella
    int ActPos, InvActPos; // Rounded results from the angular division
    int ActSlotPos(int alpha, int NSlot, int ActPos); //Reads the actual data and converts it to a corresponding pocket number
    float alphaRes = 1024.0f / 360.0f; //Resolution [bits/degrees]
    float AngularPosition(unsigned short int D, float alphaRes); // Converts a binary number to an angular position
    int NSlot = 10; // highest number tool slot in carousel


    int main()
    {
    int ToolSlot, ToolID;
    /*INIT*/ InitAux();
    AddKonnect(0, &VirtualBits, VirtualBitsEx);

    /*-------------------------------------
    --------------Data Input---------------
    -------------------------------------*/
    ToolSlot = persist.UserData[TMP];
    ToolID = persist.UserData[TMP+1];
    printf("ToolSlot = %d, ToolID = %d\n", ToolSlot, ToolID);
    //GetMiscSettings(&Units, &TWORD, &HWORD, &DWORD);
    //printf("Units=%d T=%d H=%d D=%d\n", Units, TWORD, HWORD, DWORD);
    //printf("The Next Tool is: T#%d\n", persist.UserData[TMP + 1] = TWORD);
    ReqSlot = persist.UserData[TMP]; //Pocket# of the new Tool ID#
    NewTool = persist.UserData[TMP + 1]; //Tool ID# needed
    ActSlot = persist.UserData[TMP + 2]; //Actual Pocket#
    ActTool = persist.UserData[TMP + 3]; //Actual Tool ID#
    PrevSlot = persist.UserData[TMP + 4]; //Previous Pocket# used as temporary variable while changing tools
    OldTool = persist.UserData[TMP + 5]; //Previous Tool ID# used as temporary variable while changing tools
    printf("\n The actual slot position is:%d\n", ActSlot);
    printf("The Old Tool is T#%d\t The Previous Slot is #%d\n", OldTool, PrevSlot);
    printf("The Actual Tool is T#%d\t The Actual Slot is #%d\n", ActTool, ActSlot);
    printf("The NewTool is T#%d\t The Requested Slot is #%d\n", NewTool, ReqSlot);

    /*-------------------------------------
    -----------Flow Sequence---------------
    -------------------------------------*/
    unsigned short int D;
    D=GrayToBinary16();
    AngularPosition(D, alphaRes);
    ActSlotPos(alpha, NSlot, ActPos);
    LeastTravel();

    return 0;
    }




    Results are identical as before:



    No Tool ID or Slot#
    Tool setup screen:




    Well I hope this answers your questions.

    Jerome

  15. #15
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    I reinstalled KMotion4.35d and kept the old files excepted for KflopToKMotionCNCFunctions that is brand new, and effectively no TMP # defined.
    So you must have changed it before by mistake correct?


    The file compiled is the same as previously given, whatever the TMP value <9, it doesn't change anything. The code is below and the results here after the code.
    Not sure what you mean by "whatever the TMP value <9". But what you posted has KMotionCNC M6 to put the data in Var 0 and the C Program getting the data from Var 3. So of course it doesn't work.
    TK
    http://dynomotion.com

  16. #16
    Registered
    Join Date
    Dec 2006
    Posts
    31

    Re: M6 - Tool change sequence

    Hi Tom,

    Thanks for your reply.

    So you must have changed it before by mistake correct?

    Yes, I have changed the file to declare TMP.
    I had issues with TMP undeclared while compiling: It was because TMP wasn't defined before the #include "KflopToKMotionCNCFunctions.c"
    Now it's correct as shown in the previous message.

    Not sure what you mean by "whatever the TMP value <9". But what you posted has KMotionCNC M6 to put the data in Var 0 and the C Program getting the data from Var 3. So of course it doesn't work.

    About the VAR used in KMotionCNC, I originally used the VAR# equal to TMP, then you wrote this:

    What is happening is:

    #1 you execute M6Txxxx
    #2 KMotionCNC puts the slot of the desired new Tool into Var 3 and executes the program.
    #3 The program executes GetMiscSettings() in KflopToKMotionCNCFunctions.c which uses Var 3 to communicate to KMotionCNC
    #4 Var 3 has now been corrupted
    #5 The program prints *ReqSlot which is the corrupted Var 3 value


    I misunderstood the way you explained the process and changed the VAR# to avoid any disturbance between VAR and TMP.
    But what you meant at that time was about the sequence of events not the VAR usage itself, my bad.

    Actual status:

    I did simplify and change the code in line with you inputs and the first tests are giving good results.
    I still need to implement the functionalities to handle the sequence properly between the spindle and carousel positions.
    Maybe this week I'll find some time to test, maybe...

    Many thanks for your help.

    Kr,

    Jerome

  17. #17
    Junior Member
    Join Date
    May 2006
    Posts
    3549

    Re: M6 - Tool change sequence

    Hi Jerome,

    About the VAR used in KMotionCNC, I originally used the VAR# equal to TMP, then you wrote this:

    What is happening is:

    #1 you execute M6Txxxx
    #2 KMotionCNC puts the slot of the desired new Tool into Var 3 and executes the program.
    #3 The program executes GetMiscSettings() in KflopToKMotionCNCFunctions.c which uses Var 3 to communicate to KMotionCNC
    #4 Var 3 has now been corrupted
    #5 The program prints *ReqSlot which is the corrupted Var 3 value


    I misunderstood the way you explained the process and changed the VAR# to avoid any disturbance between VAR and TMP.
    But what you meant at that time was about the sequence of events not the VAR usage itself, my bad.
    Sorry I was confusing. I meant to say it is best to simply use different persist variables for different purposes to avoid any conflict. That is have the KflopToKMotionCNCFunctions.c use communication variables in one range and have KMotionCNC pass Tool info to the C Program in another range. But it is actually ok to use the same range of variables for different purposes as long as they are used at different times. Which is what I believe you are doing now.

    HTH
    TK
    http://dynomotion.com

Similar Threads

  1. What decides GPP tool command output sequence??
    By Wrighter in forum SolidCAM for SolidWorks and SolidCAM for Inventor
    Replies: 5
    Last Post: 03-12-2019, 06:53 PM
  2. Tool Changer out of sequence Fanuc Oi-MC Control
    By ren3600 in forum Sharp CNC
    Replies: 1
    Last Post: 07-01-2017, 05:12 AM
  3. Sequence Number Before Every Tool Change
    By seattle77 in forum Post Processors for MC
    Replies: 3
    Last Post: 07-16-2009, 03:28 PM
  4. How to change the homing sequence...
    By jbcj in forum LinuxCNC (formerly EMC2)
    Replies: 4
    Last Post: 07-07-2009, 02:50 PM
  5. Mits M-v5cn,meldas 600 control,duplicate tool registration error or out of sequence
    By davissammy in forum General CNC (Mill / Lathe) Control Software (NC)
    Replies: 0
    Last Post: 10-04-2008, 04:39 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
  •