EDM GAP control C code
Posted: Thu Dec 27, 2018 12:44 pm
Hello,
I'm building micro-EDM milling machine with KFLOP+KANALOG controller.
I want to write a C code to automatize GAP control in KmotionCNC in accordance to GAP voltage.
The algorithm is very simple: Define GAP window (upper and lower voltage, proportional to Open Circuit voltage), Define Short Circuit voltage (with some safety limit). Measure actual voltage.
If the measured voltage (on ADC) lower than Short Circuit voltage than Kmotion perform reverse feed.
If the measured voltage higher than Upper GAP window voltage than Kmotion go faster.
If the measured voltage lower than Lower GAP window voltage AND higher than Short Circuit voltage than Kmotion go slower.
I made some draft code, but my C experience is very bad:
I will be very happy if you kindly will answer my few questions:
1. Does my code is ok?
2. How could I implement this code in KmotionCNC? I want there will be toggle button, when it will clicked ones - the code start to work, when it will clicked second time the code will stop. Do I need to put the code inside the USER BUTTONS menu with new thread number? I need to choose EXECUTE PROG mode?
3. For reverse feed, after short circuit I want to add some timer (or defined amount of steps). It is very important for flushing condition of the GAP. Could I just add delay function like this:
4. For my experiments - Could I define all the constants at the KmotionCNC UI - like input windows. I don't want every time go inside the code, change the values, save the code etc.
Thank you very much.
PS: I'm very happy with Dynomotion hardware and software. I got everything that I want at the 1/10 price (and less) of the other (same functionality) controllers (*ALIL.......).
Best Regards,
Gennady
I'm building micro-EDM milling machine with KFLOP+KANALOG controller.
I want to write a C code to automatize GAP control in KmotionCNC in accordance to GAP voltage.
The algorithm is very simple: Define GAP window (upper and lower voltage, proportional to Open Circuit voltage), Define Short Circuit voltage (with some safety limit). Measure actual voltage.
If the measured voltage (on ADC) lower than Short Circuit voltage than Kmotion perform reverse feed.
If the measured voltage higher than Upper GAP window voltage than Kmotion go faster.
If the measured voltage lower than Lower GAP window voltage AND higher than Short Circuit voltage than Kmotion go slower.
I made some draft code, but my C experience is very bad:
Code: Select all
#include "KMotionDef.h"
// Code for GAP control with GAP average voltage
main()
{
const float OC = 2.4; // Open Circuit Voltage
const float SC = 0.5; // Short Circuit Voltage
const float FAST = 1.5; // FRO value to speed up
const float SLOW = 0.5; // FRO value to speed down
const float REV = -2.0; // FRO value to reverse after SC
const float FRATE = 5.0; // FRO rate
const float UW = 0.75; // Upper GAP window value percentage of OC
const float DW = 0.5; // Down GAP window value percentage of OC
const float SCW = 1.3; // Percentage value of SC for retraction
const int Voltage = 0; // Define ADC channel for monitoring
for (;;) //loop forever
{
WaitNextTimeSlice();
if (ADC (Voltage) < SC*SCW) //Voltage lower than SC voltage with some safety limit?
{
SetFROwRate REV FRATE; //GO reverse!
}
if (ADC (Voltage) > OC*UW); //Voltage higher than Upper GAP window?
{
SetFROwRate FAST FRATE; //GO faster!
}
if (ADC (Voltage) < OC*DW && ADC (Voltage) > SC*SCW); //Voltage higher than SC but lower than Down GAP window?
{
SetFROwRate SLOW FRATE; //GO slower!
}
}
}
1. Does my code is ok?
2. How could I implement this code in KmotionCNC? I want there will be toggle button, when it will clicked ones - the code start to work, when it will clicked second time the code will stop. Do I need to put the code inside the USER BUTTONS menu with new thread number? I need to choose EXECUTE PROG mode?
3. For reverse feed, after short circuit I want to add some timer (or defined amount of steps). It is very important for flushing condition of the GAP. Could I just add delay function like this:
Code: Select all
if (ADC (Voltage) < SC*SCW) //Voltage lower than SC voltage with some safety limit?
{
SetFROwRate REV FRATE; //GO reverse!
delay (1000); //GO reverse for 1 second, only after that perform next code line
}
Thank you very much.
PS: I'm very happy with Dynomotion hardware and software. I got everything that I want at the 1/10 price (and less) of the other (same functionality) controllers (*ALIL.......).
Best Regards,
Gennady