Page 4 of 8

Re: G-codes/offsets/tools with .Net

Posted: Wed Jan 01, 2020 1:35 am
by TomKerekes
Hi Moray,

Hmmm we could expose those if necessary.

You might be able to use KM_CoordMotion.UpdateCurrentPositionsABS which reads the current Destination Machine counts from KFLOP does the Transform and returns absolute CAD machine position.

Or KM_Interpreter.ReadCurInterpreterPosition which reads the current Destination Machine counts from KFLOP does the Transform and returns GCode CAD position including GCode Offsets and such.

Those wouldn't permit using actual measured positions (encoder positions) instead of commanded positions as KMotionCNC allows.

Re: G-codes/offsets/tools with .Net

Posted: Wed Jan 01, 2020 5:54 pm
by Moray
It's not necessary right now, as I've created my own TransformActuatorsToCAD function, copying the non-geo corrected option in the original function, which leaves open the option to implement it later.

Re: G-codes/offsets/tools with .Net

Posted: Fri Jan 03, 2020 10:39 pm
by Moray
I've not yet implemented the functionality to switch to mm, however is there any reason why KMCNC does it via MDI/DoGCode, rather than via LengthUnits?

Also for now I'm looking at using the KM_axis MoveTo() or RelativeMoveTo() to implement step jogging. I see it's noted that it blocks the commanding thread, so I'll need to trigger it via another thread to avoid lock ups, but can a MoveTo be stopped by then issuing a Halt via the main/another thread?

Re: G-codes/offsets/tools with .Net

Posted: Sat Jan 04, 2020 6:08 pm
by TomKerekes
Hi Moray,
is there any reason why KMCNC does it via MDI/DoGCode, rather than via LengthUnits?
The Interpreter does some offset conversions and such when changing units with the GCodes that wouldn't occur if just changing the LengthUnits value.


so for now I'm looking at using the KM_axis MoveTo() or RelativeMoveTo() to implement step jogging. I see it's noted that it blocks the commanding thread, so I'll need to trigger it via another thread to avoid lock ups, but can a MoveTo be stopped by then issuing a Halt via the main/another thread?
You might use StartRelativeMoveTo() to avoid blocking. To stop a move, command the axis to zero velocity with Jog(0.0).

HTH

Re: G-codes/offsets/tools with .Net

Posted: Sat Jan 04, 2020 8:41 pm
by Moray
Thanks for that.
I kind of guessed there would some reason why the change wasn't done the simple way.

And I never even noticed the Start.. commands.


Just to give an update on how things are progressing, I'm now at the point where I've got DROs, continuous jogging, tool offsets, user buttons, and config working, but need to add work offsets, handle the whole mm/inch conversions where needed, and then I can start work on GCode parsing/viewing, followed by graphics.

Re: G-codes/offsets/tools with .Net

Posted: Tue Jan 07, 2020 10:51 pm
by Moray
I'm needing a little bit clarification on how KMCNC handles G20/21.

What I understand, is if you check Inch/mm radio buttons, it triggers a DoGCodeLine() for the relevant change, and after various checks, the temp gcode file is launched.
Then for keeping the Inch/mm selection accurate, as part of a timer, length_units is monitored, and the relevant radio button checked.

I've got that functioning, but what I don't understand is how does KMCNC prevent a G20/21 block in a gcode program from triggering the action attached to the relevant radio button?

I've implemented a barebones version of this to test things, but when I hit a G20/21 in a gcode file, it triggers the function attached to the radiobutton, which then causes problems.
I know how I can work around this, but I'm curious how KMCNC doesn't trigger an error, as going by my understanding of the KMCNC code, the DoGCodeLine() G20/21 call should timeout and trigger an error message, due to ThreadIsExecuting being set true.

Is this some feature/quirk of C++/MVC, whereby changing the radiobutton selection by code doesn't trigger the attached checked handler, or is there something in the code I'm missing/not understanding?

Re: G-codes/offsets/tools with .Net

Posted: Wed Jan 08, 2020 1:52 am
by TomKerekes
Hi Moray,

I'm not sure. KMotionCNC uses the MFC event ON_BN_CLICKED to execute the DoGCodeLine(). The timer continuously calls MFC CheckRadioButton to update the screen. I'm guessing that the CheckRadioButton updates the states without triggering the ON_BN_CLICKED event.

Maybe in C# you are using the Button Changed event or something instead of Clicked Event to execute the DoGCodeLine()?

Re: G-codes/offsets/tools with .Net

Posted: Wed Jan 08, 2020 9:15 pm
by Moray
TomKerekes wrote:
Wed Jan 08, 2020 1:52 am
Maybe in C# you are using the Button Changed event or something instead of Clicked Event to execute the DoGCodeLine()?
It's the seemingly simple things that cause the problems!
You are correct, I was using the Checked event. Swapping to the Click event has solved the problem.

Re: G-codes/offsets/tools with .Net

Posted: Mon Mar 09, 2020 10:30 pm
by Moray
TomKerekes wrote:
Sat Jan 04, 2020 6:08 pm
so for now I'm looking at using the KM_axis MoveTo() or RelativeMoveTo() to implement step jogging. I see it's noted that it blocks the commanding thread, so I'll need to trigger it via another thread to avoid lock ups, but can a MoveTo be stopped by then issuing a Halt via the main/another thread?
You might use StartRelativeMoveTo() to avoid blocking. To stop a move, command the axis to zero velocity with Jog(0.0).

HTH
Hi Tom,

I've been getting some more work done on this, but I'm not entirely sure how best to handle the jogging stop button.
For testing I'm only working on the X axis, so have the following code to stop a move -

Code: Select all

private void Button_JogStop_Click(object sender, RoutedEventArgs e)
        {
            var JA = KM.GetAxis(0, "X");
            if (Connected)
            {
                JA.Jog(0);
            }
        }
        
However, that same button has to cover all axes.
Is simply getting an axis for every axis the easiest way that will reliably do this?
I.e.-

Code: Select all

private void Button_JogStop_Click(object sender, RoutedEventArgs e)
        {
            var JA0 = KM.GetAxis(0, "X");
            var JA1 = KM.GetAxis(1, "Y");
            var JA2 = KM.GetAxis(2, "Z");
            if (Connected)
            {
                JA0.Jog(0);
                JA1.Jog(0);
                JA2.Jog(0);

            }
            
        }
(and expand it even further to ABC etc)
Is this likely to cause any issues with any undefined axis?
Or is there a more effective method to handle this?

This is only a basic implementation for now, as the jogging makes no allowance for geo correction, which is something I'd like to revisit at a later point, so I'm just trying to achieve something useable and reliable for now.

Re: G-codes/offsets/tools with .Net

Posted: Tue Mar 10, 2020 4:06 pm
by TomKerekes
Hi Moray,
Is simply getting an axis for every axis the easiest way that will reliably do this?
I don't see any harm in commanding all the axes to stop even though they might not be moving.