G-codes/offsets/tools with .Net
Moderators: TomKerekes, dynomotion
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
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.
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.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G-codes/offsets/tools with .Net
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
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?
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?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
Hi Moray,
HTH
The Interpreter does some offset conversions and such when changing units with the GCodes that wouldn't occur if just changing the LengthUnits value.is there any reason why KMCNC does it via MDI/DoGCode, rather than via LengthUnits?
You might use StartRelativeMoveTo() to avoid blocking. To stop a move, command the axis to zero velocity with Jog(0.0).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?
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G-codes/offsets/tools with .Net
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.
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
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?
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?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
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()?
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()?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: G-codes/offsets/tools with .Net
It's the seemingly simple things that cause the problems!TomKerekes wrote: ↑Wed Jan 08, 2020 1:52 amMaybe in C# you are using the Button Changed event or something instead of Clicked Event to execute the DoGCodeLine()?
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
Hi Tom,TomKerekes wrote: ↑Sat Jan 04, 2020 6:08 pmYou might use StartRelativeMoveTo() to avoid blocking. To stop a move, command the axis to zero velocity with Jog(0.0).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?
HTH
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);
}
}
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);
}
}
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.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: G-codes/offsets/tools with .Net
Hi Moray,
I don't see any harm in commanding all the axes to stop even though they might not be moving.Is simply getting an axis for every axis the easiest way that will reliably do this?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.