Z-Axis: Level compensation for uneven surfaces

Moderators: TomKerekes, dynomotion

Post Reply
McScotty
Posts: 11
Joined: Fri Feb 19, 2021 1:18 pm

Z-Axis: Level compensation for uneven surfaces

Post by McScotty » Fri Feb 19, 2021 2:04 pm

Hi Team / Tom,
I have a gantry mill with ball screws, dc servos driven by Copley Junus drives, heidenhain glass scales on all axes, Kflop/Kanalog and Mach3. A pendant with different switches and an encoder (Axis7) works as MPG. Everything is fine so far. But when it comes to milling pcb´s, a slightly uneven surface of the pcb can be a problem, because the milling depht is critical. I´m thinking about installing a gauge (another glass scale) nearby the endmill, to track the level of the surface and compensate the Z depht to achieve the same milling depht all the way. The gauge delivers its quadrature signals to Kanalog encoder input 6. An optical input is reserved for switching between "tracking mode" and "normal mode".

Can I do it this that way? I read a lot about dual closed loop, THC correction e.g, but I did not find a suiting example. Maybe my task is slightly different. Being no programmer, I was not able until now, to combine the two encoder signals in my init file. Can You give me a hint?

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

Re: Z-Axis: Level compensation for uneven surfaces

Post by TomKerekes » Fri Feb 19, 2021 9:52 pm

Hi McScotty,

I would think a dual loop same as THC should work for you. The code below connects the outer loop 6 to the inner loop 2 when Bit 46 is set.

Code: Select all

#include "KMotionDef.h"

// Creates dual feedback loops for cases such as rotary motor encoder feedback
// with linear scale encoder feedback.  Two KFLOP Servo Axes are required,
// one for each loop.  Output of the outer loop is applied as a velocity
// to the inner loop 

main()
{
    for (;;)  // loop forever
    {
		WaitNextTimeSlice();
		if (ReadBit(46))
			ch2->Dest += ch6->Output;  // move ch0 at speed of ch2 output
    }
}
You'll probably want to have two M Codes to turn on the dual mode and exclude the Z axis from the Coordinate System, and another to turn it off and restore Z into the Coordinate System. The A axis can be used to control the height target while in dual loop.

Code: Select all

#include "KMotionDef.h"

main()
{
	DefineCoordSystem(0,1,-1,6);  // remove Z
	SetBit(46);  // turn on the dual loop
}

Code: Select all

#include "KMotionDef.h"

main()
{
	ClearBit(46);  // turn off the dual loop
	DefineCoordSystem(0,1,2,6);  // include Z
}
HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

McScotty
Posts: 11
Joined: Fri Feb 19, 2021 1:18 pm

Re: Z-Axis: Level compensation for uneven surfaces

Post by McScotty » Mon Feb 22, 2021 10:20 am

Hi Tom,

Thank you for your quick response and your proposed solution. I've tried it. This is definitely a good solution for plasma / THC, where maintaining the Voltage of the arc is the main thing. When milling PCB, I need an exact relationship between the material surface and the tip of the milling cutter and I can not see, how this could work with the dual loop approach.

The following idea: When the machine is initialized, the zero point of the Z-axis is set when the milling cutter touches the material. At the same time the encoder for the height control (axis 6) is set to zero. A "connection" between axis 2 (Z) and axis 6 is only established when the coordinated movement is started; axis 6 has no influence beforehand at all.

When the G code is started, the milling depth is determined by the G code. The height sensor constantly checks the material height and as long as the sensor measures Zero, this means the material is perfectly flat and therefore there is no need to correct the Z Level. If the material is curled up or down, the height sensor measures a value. This value would have to be subtracted or added from Pos of the Z-axis so that the corrugation is compensated and the milling cutter always dips just as deep into the material as with a perfect flat material.

Would this be possible with a dual loop approach, or is there a different way it can be done?

Best Regards
Thomas

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

Re: Z-Axis: Level compensation for uneven surfaces

Post by TomKerekes » Mon Feb 22, 2021 4:08 pm

Hi Thomas,

Its not clear to me why the Dual Loop method wouldn't work for you. For example you wish the cutter to be 1mm below the surface. The outer loop is commanded to -1mm. The inner loop moves axis 2 up/down until the cutter is 1mm below the surface. If the surface is currently at 0 that would position axis 2 at -1 mm. if the surface is currently at +3mm that would position axis 2 at +2mm. You said you tried it. What happened?

I suppose there might be some performance benefit when raising/lowering the cutter rapidly using a single loop with an offset as you seem to describe. That would be the case if the outer loop is tuned to make only gradual corrections. But if tuned well I would think that should not be an issue. If you prefer that method KFLOP Axes have an DestOffset parameter that may work for you in that manner.
Regards,

Tom Kerekes
Dynomotion, Inc.

McScotty
Posts: 11
Joined: Fri Feb 19, 2021 1:18 pm

Re: Z-Axis: Level compensation for uneven surfaces

Post by McScotty » Tue Feb 23, 2021 2:45 pm

Hi Tom,

I connected the two axes by ch2->Dest += ch6->Output, Definition of CoordSystem is (0,1,6). CoordSystem (0,1,-1,6) works also, but is no option, because manual operation of Z only.

The dual loop method works in principle. The Z axis perfectly follows the height probe and the G codes arrive at the axes. The prerequisite is that the height probe is always in contact with the material surface. If you have to go over obstacles or want to do fast rapids, that can break the probe. My height probe has a measuring range of 10mm. Therefore, Z cannot be higher than this. Maybe there is a way to switch off tracking by the probe for the Rapids only, so that rapids can be done without the probe down?

The probe is also a glass scale like the Z axis, but it has twice the resolution and therefore Z moves are only half the size they should be. Can the resolution be changed temporarily in the INI file so that Mach3 understands it?

If there was a solution for these two topics, the Dual Loop method should work for me and there was no need to think about DestOffset alternatives.

Best regards an Thanks for Your support in advance
Thomas

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

Re: Z-Axis: Level compensation for uneven surfaces

Post by TomKerekes » Tue Feb 23, 2021 3:47 pm

Hi Thomas,
I connected the two axes by ch2->Dest += ch6->Output, Definition of CoordSystem is (0,1,6). CoordSystem (0,1,-1,6) works also, but is no option, because manual operation of Z only.
I assume you meant: CoordSystem is (0,1,6,-1) ? The second option should work if you change your G Code to command the A axis.
Maybe there is a way to switch off tracking by the probe for the Rapids only, so that rapids can be done without the probe down?
The original MCodes I posted should allow switching modes. There will be a slight delay however. But now I realize you aren't using KMotionCNC. With Mach3 you would used MCodes->Basic->NotifyPlugin->KFLOP to execute a Notifiy C Program in KFLOP passing a code to tell KFLOP what it should do. Consider using KMotionCNC you should get better trajectory planning and performance.
The probe is also a glass scale like the Z axis, but it has twice the resolution and therefore Z moves are only half the size they should be. Can the resolution be changed temporarily in the INI file so that Mach3 understands it?
You should be able to change KFLOP's Axis 6 InputGain0 to 0.5 to solve this.
Regards,

Tom Kerekes
Dynomotion, Inc.

McScotty
Posts: 11
Joined: Fri Feb 19, 2021 1:18 pm

Re: Z-Axis: Level compensation for uneven surfaces

Post by McScotty » Wed Feb 24, 2021 9:42 am

Hi Tom,

now I understand that GAIN can do more than just reverse the encoder. Thank you, now the resolution issue is solved and values are correct.
I also understand that KMotionCNC has advantages. I am considering switching.
I would like to learn more about DestOffset and try a few things. But I can hardly find any information about it. Is that a parameter for the axis, for example ch2-> DestOffset = XXXXX? Is there a description anywhere?

Regards
Thomas

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

Re: Z-Axis: Level compensation for uneven surfaces

Post by TomKerekes » Wed Feb 24, 2021 4:08 pm

Hi Thomas,

Yes it is a parameter for each axis. Its defined in KMotionDef.h

It's not commonly used. Its main purpose is to inject a disturbance for Bode Plot Stimulation.

The Servo Axis should always move to (ch2->Dest + ch2->DestOffset). So if KMotionCNC commands an axis to 1000 and the DestOffset is 100 the axis should move to 1100. Note if you read back the encoder position it would read 1100 not 1000. I don't think that should be a problem but I'm not sure. You might need to take care to set DestOffset back to zero before re-initializing and such. DestOffset should also only be changed gradually. Suddenly changing by a large amount will create a step in the commanded position and possibly exceed velocity/acceleration limits for your system.
Regards,

Tom Kerekes
Dynomotion, Inc.

McScotty
Posts: 11
Joined: Fri Feb 19, 2021 1:18 pm

Re: Z-Axis: Level compensation for uneven surfaces

Post by McScotty » Thu Feb 25, 2021 8:41 pm

Hi Tom,

thanks a lot for the comprehensive explanation. I've been working with KFLOP / KANALOG for many years now, but with the help of the community and with your help, I always keep discovering something new. That is actually priceless. The control for the "Follow-Me" function for the Z-axis now works almost perfectly. Now some adjustments on the mechanics for the height sensor and then we will see how practice looks like.

Regards
Thomas

Post Reply