EDM GAP control C code

Moderators: TomKerekes, dynomotion

Post Reply
Gennady
Posts: 4
Joined: Thu Dec 27, 2018 11:04 am

EDM GAP control C code

Post by Gennady » 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:

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!
			}
		}
}
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:

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
			}
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

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: EDM GAP control C code

Post by TomKerekes » Thu Dec 27, 2018 7:17 pm

Hi Gennady,
1. Does my code is ok?
Your code and approach seem reasonable, except much of your C syntax is incorrect.

You might see the ArcVoltageFRO.c example

To read a Kanalog ADC and convert the value to Volts use:
KANALOG_CONVERT_ADC_TO_VOLTS(ADC(chan))

Some of your "if" statements have ';" in the wrong place to have the statement do nothing

SetFROwRate needs parentheses and requires 2 parameters

To delay use Delay_sec(T); where T is in seconds
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?
The ArcVoltageFRO.c example shows how to control the operation by turning on and off a virtual bit.

You can use the Screen Editor to add a toggle button to toggle a bit.



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.
You can add Edit Controls for Parameters that KFLOP can then read. See the Calculator Add Example of how to read Edit Controls (~13 minutes into this video)



BaxEDM has a lot of info available for use with the Arc Generator they sell.
Regards,

Tom Kerekes
Dynomotion, Inc.

Gennady
Posts: 4
Joined: Thu Dec 27, 2018 11:04 am

Re: EDM GAP control C code

Post by Gennady » Thu Dec 27, 2018 8:59 pm

Thank you Tom!
I will learn all the examples you provide and fix C syntax.

BaxEDM has very impressive and professional looking system. I already implement his tip about the noise problem and USB cable from Kflop to PC.

I'm just material engineer who like to torture materials with electricity :) , so my system will be much more simple.

I will share pics of my machine when it will have some reasonable looking.

Gennady.

Gennady
Posts: 4
Joined: Thu Dec 27, 2018 11:04 am

Re: EDM GAP control C code

Post by Gennady » Tue Jan 01, 2019 11:45 am

Ok, the code is working now (more or less).
IMG_20181231_164129.jpg


I uploaded my full init file with control loop:
init_with_gap_ui.c
(7.54 KiB) Downloaded 193 times
Now I have a little problem to transmitting values from the KmotionCNC screen to the code, I implement the example of add.c, but I'am getting an error. For example, The first variable I want to transmit are Open Circuit Voltage value, the control box is linked to variable 1025:

Code: Select all

if (GetEditControlDouble(&OC, 1025, 1000))
	{
	printf("Error Reading Edit Control Var=1025\n"); 
	return 0;
	}
I put inside 2.8 (for example) but when I push INIT button I have an error (at the console) - Please see attached screenshot.
Untitled.jpg

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: EDM GAP control C code

Post by TomKerekes » Tue Jan 01, 2019 1:31 pm

Hi Gennady,

Wow very cool.

The Edit Controls and the DRO Labels communicate between KFLOP and the PC using one of the 200 KFLOP persist variables as a trigger word that have a range from 0 - 199. So try using a number like 160 instead of 1025.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Gennady
Posts: 4
Joined: Thu Dec 27, 2018 11:04 am

Re: EDM GAP control C code

Post by Gennady » Tue Jan 01, 2019 4:27 pm

Thank you Tom,
Now variables are passing right.

Strange, but the toggle button do not work with 1xx VAR (led still off). Fix it back to 1xxx VAR without problem.

I'm dealing with another problem. The system decelarate (min fro=0.1) and go reverse (fro=-6) without any problem, but when I want the system to accelerate (for example Max fro=2) it's fluctuate on fro 1.1-1.2...

Does it related to motion profile settings and maximum speeds? I calculated the maximum velocity in accordance to axis/encoders specs and put same value in acceleration and jerk fields (for now). At kmotion cnc trajectory screen I experimentally found the maximum velocity (at which the axis still moving).

I know that I'm doing wrong....also at the same screen there are FRO control limit by hardware/software - my intuition said to me that if I want quick FRO (and for EDM it's a must) I need to put a value higher than 1. Correct me if I'm wrong.

May be you could direct me to some examples/manuals at this field?

User avatar
TomKerekes
Posts: 2529
Joined: Mon Dec 04, 2017 1:49 am

Re: EDM GAP control C code

Post by TomKerekes » Tue Jan 01, 2019 5:28 pm

Hi
Strange, but the toggle button do not work with 1xx VAR (led still off). Fix it back to 1xxx VAR without problem.
yes we should be more clear about that, toggle buttons reference an IO bit not a persist variable. Extended Virtual Bits have numbers 1024-2047.
I'm dealing with another problem. The system decelarate (min fro=0.1) and go reverse (fro=-6) without any problem, but when I want the system to accelerate (for example Max fro=2) it's fluctuate on fro 1.1-1.2...
Try increasing the KMotionCNC | Tool Setup | Trajectory Planner | Look Ahead Time. KFLOP attempts to avoid buffer underflow, so if not enough data is in the buffer to be able to stop, the FRO is automatically reduced.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply