Saving parameters after shut down

More
13 years 10 months ago #28038 by JR1050
I have a Cinci lathe that has a power chuck,tailstock and parts catcher, none of which have limit switches or sensors to indicate their position .On the original Acra 850 control the state was set by initializing the machine and storing the position of of the tailstock or chuck.The control tracked a "state " and stored its last state on powerdown.

I need to be able to do the same thing,how do I write directly to the hard drive to save the last state of a parameter so I dont have to manually set the state of each of these on every power up? My logic is written as comp's in C. Suggestions?

Thanks

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #28045 by ArcEye
Hi

..............................none of which have limit switches or sensors to indicate their position


You probably need to expand a little upon what exactly you will be saving.
Lost me a bit as to what the 'state' consists of, if it cannot determine where the items are.

If your component is a userspace one, then you can just use the standard file functions from stdio.h, but I suspect the reason you ask is because it is a realtime component?

One easy way to side step the problems of accessing devices from a realtime module, would be to write a userspace component whose sole function is to read parameters at start up and write them to disc when signalled at close down.

You could then just connect the userspace to the realtime component, via suitable HAL pins for your data type, and have a signal pin to trigger a read or write.

regards

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #28048 by ArcEye
This is an example of what I was talking about, it compiles OK but not tested.
(I have cast the float pin to float* from volatile real_t*, don't know how that will pass through fscanf,
if there are problems you could just use an intermediary float variable to receive it and then set the pin value from that )

Code:
component paramhelper; pin in float invalue "Receives value to save"; pin out float outvalue "Sends value"; pin in bit readtrigger = 0 "signal to read from file"; pin in bit writetrigger = 0 "signal to write to file"; option singleton yes; option userspace yes; author "ArcEye"; license "GPL"; ;; #include <stdio.h> /* Standard input/output definitions */ #include <stdlib.h> #include <stdint.h> /* Standard types */ #include <string.h> /* String function definitions */ #include <unistd.h> /* UNIX standard function definitions */ #include <fcntl.h> /* File control definitions */ #include <errno.h> /* Error number definitions */ #include <signal.h> int done = 0; void adios(int sig) { done = 1; } void user_mainloop(void) { char filepath[] = "~/emc2/param.sav"; int read = 0; signal(SIGINT, adios); signal(SIGTERM, adios); while(!done) { usleep(500000); FOR_ALL_INSTS() { if(readtrigger && !read) // only want to read once { FILE *fp; fp = fopen(filepath, "r"); fscanf(fp, "%f", (float*)&outvalue); read = 1; } else if(writetrigger) { FILE *fp; fp = fopen(filepath, "w"); fprintf(fp, "%f", invalue); } } } exit(0); }
The following user(s) said Thank You: JR1050

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #28051 by JR1050
Thanks for the response. Let me see if i can explain.The chuck can be used to grab the part from the inside or the outside.It uses two solenoids to open or close the chuck.The chuck can be operated by a single foot switch or by mcodes.The control does not know whether the chuck is open or closed,so it gets a parameter,a bit,'" inside_chuck" or "outside_chuck" set. Right now im using a button to set the state of inside or outside,Id like to set it once and save the last known state.whether inside or outside,so on power up,the control knows the chuck is open(od grip) or closed(id grip).

You are correct,all of this is written as a realtime component.The userspace example is what I was looking for. Figuring machine logic is relatively easy,the c programming I know is from writing tool changers ,ect. Im kinda missing the how to use C part of using C for regular computer stuff,if any of that makes any sense!!!Thanks!!

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #28054 by ArcEye
You're welcome

The example is back of an envelope stuff.

Occurred to me after posting that synchronising between a realtime and userspace component, it would probably be best to have a data-ready bit flag so that the realtime component knows that outvalue has been set to something meaningful .
Otherwise, unless you programmed a delay, it would send a read command and then immediately read the value of the pin which would probably still be 0 because it was being updated on a much slower thread.

regards

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #28059 by BigJohnT

JR1050 wrote: Thanks for the response. Let me see if i can explain.The chuck can be used to grab the part from the inside or the outside.It uses two solenoids to open or close the chuck.The chuck can be operated by a single foot switch or by mcodes.The control does not know whether the chuck is open or closed,so it gets a parameter,a bit,'" inside_chuck" or "outside_chuck" set. Right now im using a button to set the state of inside or outside,Id like to set it once and save the last known state.whether inside or outside,so on power up,the control knows the chuck is open(od grip) or closed(id grip).


Why not just have a selector switch for ID/OD chuck.

John

Please Log in or Create an account to join the conversation.

Time to create page: 0.334 seconds
Powered by Kunena Forum