Save to EEprom or something like it?
Hi
I´m trying to get a way to store locations of the ATC tools place in the magazine.
The ATC works in a way that it switches places of the tool from the caruosel to the spindle and viceversa. So the tools actually switches place with eachother.
Is there a way of storing variables i memory and still have them after a reboot or do I have to store them in a file on the harddrive?
One way would be to do a double toolswitch, first set to tool from the spindle back to it´s own pot and after rotate to the new tool, then it dosen´t switch places.
When calling for ex T10 M6. Is it toolpocket 10 or tool ID 10 that si beeing sent? This from the toolfile in KmotionCNC.
/Lars
Re: Save to EEprom or something like it?
Hi Lars,
Writing data to FLASH is a possibility but there are a limited number of write cycles (10000+).
Writing data to disk in the form of a C #include file is another possibility. Here is a simple example that helped a User keep track of the Last Tool Loaded:
A Program to Write the File:
Code:
#include "KMotionDef.h"
#define LAST_TOOL_VAR 7 // Tool changer Last tool position is saved globally in this Var
int *LastTool = &persist.UserData[LAST_TOOL_VAR];
main()
{
*LastTool=1234; // as an example
FILE *f=fopen("C:\\temp\\LastTool.h","wt");
fprintf(f,"#define SAVED_LAST_TOOL %d\n",*LastTool);
fclose(f);
}
The file Written:
#define SAVED_LAST_TOOL 1234
Program to access the data:
Code:
#include "KMotionDef.h"
#include "C:\temp\LastTool.h"
#define LAST_TOOL_VAR 7 // Tool changer Last tool position is saved globally in this Var
int *LastTool = &persist.UserData[LAST_TOOL_VAR];
main()
{
*LastTool = SAVED_LAST_TOOL;
printf("LastTool was = %d\n",*LastTool);
}
M6 now passes both the Slot and the Tool ID. The Slot is passed into the specified Variable and the Tool ID is passed in the next Variable.
HTH
Regards
Re: Save to EEprom or something like it?
Hi Tom
Is the only file handeling functions fopen, fprintf and fclose avalible with kmotiondef?
Having a hard time grasping a way to keep track of 15 toolpots and what tool is in the spindle and what pos the magazine is in.
Can I have muliple valuse stored in a file, LastTool.h?
Do i have to make 17 seperate files? And then open them all and check each one for the next tool wanted. Seams a bit wrong.
Tried to open file in append mode and that did not work. Kept writing over the old and not adding a new line.
There must be some other way to handle this! Sense i am not running the kflop without a computer, standalone, is there no way of startup a c program the just runs on the computer and send a couple of variables with?
I feel i am out my deapth here.......
/Lars
Re: Save to EEprom or something like it?
Hi Lars,
Quote:
Is the only file handeling functions fopen, fprintf and fclose avalible with kmotiondef?
Yes
Quote:
Can I have muliple valuse stored in a file, LastTool.h?
Yes. Just add more fprintf's. Such as:
fprintf(f,"#define TOOL_IN_SLOT1 %d\n",*Tool1);
fprintf(f,"#define TOOL_IN_SLOT2 %d\n",*Tool2);
fprintf(f,"#define TOOL_IN_SLOT3 %d\n",*Tool3);
Quote:
There must be some other way to handle this! Sense i am not running the kflop without a computer, standalone, is there no way of startup a c program the just runs on the computer and send a couple of variables with?
This technique will allow you to write any data you want to the PC Disk. The data will then be included whenever a program is executed that includes it. It will be up to you to come up with a scheme that saves whatever you need to save and make use of it. I would expect that you would want to save all the data whenever the Tool Changer does something like moves or changes a tool. That way if the machine is shut down then the latest information will be current the next time the program is executed.
HTH
Regards
1 Attachment(s)
Re: Save to EEprom or something like it?
Hi
I have wrote a program that i think can work. I have never done anything with pointers and included files. Can you have a quick look and see if i have made any major errors in my way of thinking. I will make the ATC.c file that is included before running to program the first time. Just so it will have somewere to start.
I am not anywere close to the machine and my Kflop so I have not been able to test compile it yet. Many thanks Tom!
/Lars
1 Attachment(s)
Re: Save to EEprom or something like it?
Hi Lars,
You made probably the most classic mistake made at least once by every C Programmer regarding Pointers. A "Pointer" is a thing that points to something else. Think of it like a small space on a black board where you can write down the address of a house that one of your workers is to go and work. For this to work properly, besides allocating the black board space, two more things must be true. #1 There must be a valid house someplace for your worker to work at. #2 you must write on the blackboard the address of the house.
Your program doesn't do steps #1 and #2. So your worker may look at the black board and read an old, invalid, garbage address and go to the wrong house or even a house that doesn't exist and start doing work there.
To allocate memory for a place to save a Tool Pot number do:
int Toolpot1;
To allocate memory for a place to save the address of a Tool Pot number do:
int *Toolpot1;
In the pointer case we need to make sure #1 and #2 above are valid before we can use the pointer. In the earlier programs we wanted to save information into the global persist.UserData[] array so that whatever data we put there would not only exist within one execution of a program it would still be there the next time the program was run (as long as there wasn't a power loss). Also a different program could then also access the same variable. So in order to make this easier and more readable we made pointers to the variables we were going to use.
Attachment 273842
However in your current situation pointers to global variables may not be necessary as your program will #include the data each time it is executed anyway. So in summary you have two choices. #1 make your variables simple integers rather than pointers. #2 assign the pointers to unused persist.UserData[] addresses before using them.
Pointers are one of the most dangerous and confusing aspects of C Programming yet one of the most powerful.
HTH
Regards
1 Attachment(s)
Re: Save to EEprom or something like it?
After reading your post a couple of times i think i understand it all. I have made a program that sort of work. All the file handeling is working correctly now. But I can´t seem to get the value from, ex T15 M6, from Kmotioncnc to Kmotion prog. Value recived is 0 and not 15. If I manually enter value to variable Toolwanted, it works. I have set variable in tool setup in Kmotioncnc to 4. And in toolfile both slot and number is 15.
Have I made the conversion from float to int wrong perhaps?
I will attach to program in a txt file. Code is a bit sloppy right now and needs cleaning up. Bear with me,....
Re: Save to EEprom or something like it?
I reread one of your earlier postes and found that you wrote that Toolslot is passed in the first variable and ToolNumber is in the next. Does that meen that if I have specified Var 4, in KmotionCnc for M6 cmd, Toolslot is passed in variable 4 and Toolnumber is passed in variable 5?
/Lars
Re: Save to EEprom or something like it?
Hi Lars,
Quote:
Have I made the conversion from float to int wrong perhaps?
Yes. KMotionCNC puts the data as a simple integer into the integer variable so there is no need to do any special type conversion. Change:
float TW = *(float *)&persist.UserData[4];
int Toolwanted = (int)TW;
To:
int Toolwanted = persist.UserData[4];
Quote:
I reread one of your earlier postes and found that you wrote that Toolslot is passed in the first variable and ToolNumber is in the next. Does that meen that if I have specified Var 4, in KmotionCnc for M6 cmd, Toolslot is passed in variable 4 and Toolnumber is passed in variable 5?
Yes. We refer to them as Tool Slot and Tool ID. T numbers less than 100 are interpreted as slot numbers. Larger than 100 are considered to be Tool IDs. Not sure what approach you intend on using.
HTH
Regards
Re: Save to EEprom or something like it?
Made the changes and the ATC now works perfect! Using Toolnumber instead of Toolslot.
Thank you Tom!