Another plasma component...
- rodw
- Offline
- Platinum Member
- Posts: 10807
- Thank you received: 3559
I spent a bit of time today working on the component I use for scaling the voltage from the THCAD. It already has a lowpass filter built into it and now I'm working on a moving average of the arc volts from 3-1000 consecutive readings. Comparing the dv/dt between the current period and the moving average should allow us to sense if the torch crosses into a void.
For Phil's benefit, this is the moving average code which receives torch volts, arcOK and buffer size as parameters. I've had this working but have changed it so we can define the number of readings to average which are read into a fixed buffer so it might need a bit of cleaning up yet. I did not want to use any dynamically allocated memory which is how I'd normally write something like this.
We do some fancy pointer footwork to calculate the total and average without resorting to any for loops
#define BUFSIZE 1000 // maximum number of readings to average torch volts
double buf[BUFSIZE];
float avgarcvolts(double tvolts, int iscutting, int buffersize)
{
// Calculates the moving average of buffersize readings
static double *b, *p = &buf[0]; // pointers for beginning of buffer and current position
static double *e = &buf[buffersize]; // pointer for end of buffer
static int wascutting = 0; // cutting state last time
static double sumvolts = 0.0; // Sum of readings in buffer
static int numreadings = 0; // number of readings in buffer
if(!iscutting && wascutting){
// Torch just turned off, so reset the variables
p = b;
sumvolts = 0.0;
numreadings = 0;
wascutting = iscutting; //and save the state
return(0.0);
}
if(iscutting){ // Arc_OK is on so lets start gathering data to average
*p++ = tvolts; // Save volts to the buffer and increment pointer
if(numreadings < buffersize)
numreadings++;
if(p > e) // if we've gone past the end of the buffer, wrap to the beginning
p = b;
sumvolts += tvolts; // add the new reading
if(numreadings >= buffersize)
sumvolts -= *p; // subtract the oldest reading (which is this one)
}
wascutting = iscutting; //and save the state
if(numreadings)
return(sumvolts/(double)numreadings); // return Average volts
else
return (0.0); // catch divide by zero errors
}
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
- Posts: 23170
- Thank you received: 4860
(for a notional 10 point average)
new = 0.9 * old + 0.1 * latest
Or, for variable gain:
new = (1 - G) * old + (G) * latest
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
- Posts: 10807
- Thank you received: 3559
Andy, thanks for shooting down my cool non-looping algorithm down in flames with a single line of codeWhilst your method will return a true moving-average it is often sufficient just to use
(for a notional 10 point average)
new = 0.9 * old + 0.1 * latest
Or, for variable gain:
new = (1 - G) * old + (G) * latest
I'm not really sure if plasma is an application I'd like to use approximations. There are a number of places I would like to use this. It would be fine for sampling the voltage to establish the command signal for PID control (Currently I only take a single point reading).
But now I have the technique, there are other signal processing techniques mentioned in the literature that I may extend the algorithm to include. But one step at a time.
Please Log in or Create an account to join the conversation.
- phillc54
- Topic Author
- Offline
- Platinum Member
- Posts: 5711
- Thank you received: 2088
In the meantime I have been playing around with QtVCP which has recently been pushed to master branch and it looks really promising for the construction of custom GUI's.
I have now included a sample QtVCP GUI (which is still very much a work in progress and incomplete) in the repo. It can be found in sim/qtvcp_screens/plasmac.
Cheers, Phill
Please Log in or Create an account to join the conversation.
- sevaz
- Offline
- Junior Member
- Posts: 24
- Thank you received: 5
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
- Posts: 19486
- Thank you received: 6533
Managed to get the toma_thc config to work with Mesa boards, uploaded it to the original post at
forum.linuxcnc.org/plasma-laser/34978-th...-with-how-to?start=0
Hopefully will have some more time to give your config a good run over and test it on some actual hardware.
Regards
Tom
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
- Posts: 10807
- Thank you received: 3559
Please Log in or Create an account to join the conversation.
- phillc54
- Topic Author
- Offline
- Platinum Member
- Posts: 5711
- Thank you received: 2088
tommylight wrote:
Why change the thread name ?
rodw wrote:
Tommy, I think a user changed the thread name. Lets see if this post changes it back! And yes, I found it really annoying too
Thanks guys, I didn't notice that, nor did I know it could be done...
Cheers, Phill.
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
- Posts: 10807
- Thank you received: 3559
[
Thanks guys, I didn't notice that, nor did I know it could be done...
Cheers, Phill.
And you changed it again!
EDIT. When I posted, it went back to "hights problem" so I edited the title in this post.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
- Posts: 19486
- Thank you received: 6533
I was just a bit worried that my sanity went out of the window after several hours in front of 4 monitors !
Please Log in or Create an account to join the conversation.