Checking for Resume Circumstances from Halt.
Posted: Sun Nov 08, 2020 2:38 am
Tom,
For the past few months I have been working on writing a .Net application similar to your KMotionCNC. I started with the SimpleGCodeWPF example and it evolved from there.
I have been trying to copy a lot of the functionality of KMotionCNC and have so far been fairly successful. I can currently home my machine, Jog with buttons or my MPG, the Spindle responds to M3, M4, M5 and S commands and I can load and execute GCode. I have a manual G Code line working, and I can single step Feed hold, move forwards and backwards in feedhold (your solution for this is quite clever!) and can halt and resume.
But I am having a problem with the halt and resume. I re-implemented the section from KMotionCNC that checks to see if the position has changed since the interpreter was halted, trying to copy what was done in KMotionCNC. My CheckforResumeCircumstances method looks like this.
This mostly works. The problem that I am having is that when the Move to safe Z height is selected
When I have Move to save Z height selected the interpreter halts again and gives a message that says "Soft Limit Z - Rapid Traverse Job Halted" It then resets interpreter back to the beginning of the GCode file.
It doesn't seem to matter what number I put in for the safe z height or the state of ResumeSafeRelAbs, if the safe Z height is selected it gives me the error, if it is not selected everything else works.
When I try to do the same thing in KMotionCNC with the same KFLOP C code, ie run a small GCode program, halt, jog a bit and resume, KMotionCNC runs without a hitch.
Any help would be appreciated!
The entire code is available on my github page:
https://github.com/xdmattz/KFLOP_Test3
I'm using Visual Studio Community 2015. Everthing is in WPF - this is my first real project with WPF... I'm sure it's pretty ugly to real programmers.
The C code for the KFLOP board is at:
https://github.com/xdmattz/BP308/tree/m ... 20C%20Code
All the design files for the machine I'm working on are at:
https://github.com/xdmattz/BP308
you can see the current state of the machine here:
This is very much a work in progress but I'm having a good time with it.
Thanks
Dan Matthews
PS I'm having trouble getting images to show up in this post. Are there some instructions somewhere that show how to do it properly?
For the past few months I have been working on writing a .Net application similar to your KMotionCNC. I started with the SimpleGCodeWPF example and it evolved from there.
I have been trying to copy a lot of the functionality of KMotionCNC and have so far been fairly successful. I can currently home my machine, Jog with buttons or my MPG, the Spindle responds to M3, M4, M5 and S commands and I can load and execute GCode. I have a manual G Code line working, and I can single step Feed hold, move forwards and backwards in feedhold (your solution for this is quite clever!) and can halt and resume.
But I am having a problem with the halt and resume. I re-implemented the section from KMotionCNC that checks to see if the position has changed since the interpreter was halted, trying to copy what was done in KMotionCNC. My CheckforResumeCircumstances method looks like this.
Code: Select all
private bool CheckforResumeCircumstances()
{
double cx, cy, cz, ca, cb, cc; // current axis values
cx = cy = cz = ca = cb = cc = 0;
// trying to copy the functionality of KMotionCNC
if(KM.CoordMotion.IsPreviouslyStopped == PREV_STOP_TYPE.Prev_Stopped_None)
{
//KM.CoordMotion.Interpreter.ReadAndSynchCurInterpreterPosition(ref cx, ref cy, ref cz, ref ca, ref cb, ref cc);
//KM.CoordMotion.Interpreter.SetupParams.X_AxisPosition = cx;
//KM.CoordMotion.Interpreter.SetupParams.Y_AxisPosition = cy;
//KM.CoordMotion.Interpreter.SetupParams.Z_AxisPosition = cz;
//KM.CoordMotion.Interpreter.SetupParams.A_AxisPosition = ca;
//KM.CoordMotion.Interpreter.SetupParams.B_AxisPosition = cb;
//KM.CoordMotion.Interpreter.SetupParams.C_AxisPosition = cc;
MessageBox.Show("previously stopped");
return false;
}
// read the current position
KM.CoordMotion.UpdateCurrentPositionsABS(ref cx, ref cy, ref cz, ref ca, ref cb, ref cc, true);
int dx, dy, dz, da, db, dc;
dx = dy = dz = da = db = dc = 0;
KM.CoordMotion.GetAxisDefinitions(ref dx, ref dy, ref dz, ref da, ref db, ref dc);
//string msg;
//msg = "check for movement\n";
//msg += string.Format("X def:{0} {1:F7} {2:F7}\n", dx, round(cx), round(Stopped_X));
//msg += string.Format("Y def:{0} {1:F7} {2:F7}\n", dy, round(cy), round(Stopped_Y));
//msg += string.Format("Z def:{0} {1:F7} {2:F7}\n", dz, round(cz), round(Stopped_Z));
//msg += string.Format("A def:{0} {1:F7} {2:F7}\n", da, round(ca), round(Stopped_A));
//msg += string.Format("B def:{0} {1:F7} {2:F7}\n", db, round(cb), round(Stopped_B));
//msg += string.Format("C def:{0} {1:F7} {2:F7}\n", dc, round(cc), round(Stopped_C));
//MessageBox.Show(msg);
// if the axis is enabled and hasn't moved...
if (((dx < 0) || (round(cx) == round(Stopped_X))) &&
((dy < 0) || (round(cy) == round(Stopped_Y))) &&
((dz < 0) || (round(cz) == round(Stopped_Z))) &&
((da < 0) || (round(ca) == round(Stopped_A))) &&
((db < 0) || (round(cb) == round(Stopped_B))) &&
((dc < 0) || (round(cc) == round(Stopped_C))))
{
MessageBox.Show("No movement");
return true; // return without modification
}
// show the resume dialog
// if cancel then return false
//
MessageBox.Show("Something moved!");
ResumeDialog Resume = new ResumeDialog();
Resume.SafeZ = KM.CoordMotion.Interpreter.InchesToUserUnits(m_Safe_Z);
Resume.SafeRelAbs = m_SafeRelAbs;
Resume.DoSafeZ = true;
Resume.TraverseXY = true;
Resume.Metric = KM.CoordMotion.Interpreter.SetupParams.LengthUnits == CANON_UNITS.CANON_UNITS_MM;
Resume.SafeX = StoppedIX;
Resume.SafeY = StoppedIY;
if(StoppedSpindleDirection == CANON_DIRECTION.CANON_STOPPED)
{
Resume.SafeSpindleStart = false;
Resume.SafeSpindleCWCCW = true;
}
else if(StoppedSpindleDirection == CANON_DIRECTION.CANON_CLOCKWISE)
{
Resume.SafeSpindleStart = true;
Resume.SafeSpindleCWCCW = true;
}
else
{
Resume.SafeSpindleStart = true;
Resume.SafeSpindleCWCCW = false;
}
Resume.SafeSpindleSpeed = StoppedSpindleSpeed;
Resume.DoSafeFeedZ = true;
Resume.SafeFeedZ = StoppedIZ;
Resume.ResumeFeedRate = StoppedFeedrate;
Resume.SafeFeedZRate = StoppedFeedrate;
Resume.RestoreFeedRate = true;
bool? ResumeResult = Resume.ShowDialog();
if(ResumeResult == false)
{
MessageBox.Show("False");
return false;
}
else
{
MessageBox.Show("True!");
// get the results back from the dialog box
KM.CoordMotion.Interpreter.CanResume = true;
KM.CoordMotion.Interpreter.ResumeFeedSafeZ = Resume.SafeZ;
if(Resume.SafeRelAbs)
{ KM.CoordMotion.Interpreter.ResumeSafeRelAbs = 1; }
else { KM.CoordMotion.Interpreter.ResumeSafeRelAbs = 0; }
KM.CoordMotion.Interpreter.ResumeTraverseXY = Resume.TraverseXY;
KM.CoordMotion.Interpreter.ResumeTraverseSafeX = Resume.SafeX;
KM.CoordMotion.Interpreter.ResumeTraverseSafeY = Resume.SafeY;
KM.CoordMotion.Interpreter.ResumeSafeStartSpindle = Resume.SafeSpindleStart;
if (Resume.SafeSpindleCWCCW) // this looks backwards - but it is correct.
{ KM.CoordMotion.Interpreter.ResumeSafeSpindleCWCCW = 0; }
else { KM.CoordMotion.Interpreter.ResumeSafeSpindleCWCCW = 1; }
// what about the spindle speed?
KM.CoordMotion.Interpreter.ResumeMoveToSafeZ = Resume.DoSafeZ;
KM.CoordMotion.Interpreter.ResumeDoSafeFeedZ = Resume.DoSafeFeedZ;
KM.CoordMotion.Interpreter.ResumeFeedSafeZ = Resume.SafeFeedZ;
KM.CoordMotion.Interpreter.ResumeZFeedRate = Resume.SafeFeedZRate;
KM.CoordMotion.Interpreter.ResumeFeedRate = Resume.ResumeFeedRate;
KM.CoordMotion.Interpreter.ResumeRestoreFeedRate = Resume.RestoreFeedRate;
}
return true;
}
When I have Move to save Z height selected the interpreter halts again and gives a message that says "Soft Limit Z - Rapid Traverse Job Halted" It then resets interpreter back to the beginning of the GCode file.
It doesn't seem to matter what number I put in for the safe z height or the state of ResumeSafeRelAbs, if the safe Z height is selected it gives me the error, if it is not selected everything else works.
When I try to do the same thing in KMotionCNC with the same KFLOP C code, ie run a small GCode program, halt, jog a bit and resume, KMotionCNC runs without a hitch.
Any help would be appreciated!
The entire code is available on my github page:
https://github.com/xdmattz/KFLOP_Test3
I'm using Visual Studio Community 2015. Everthing is in WPF - this is my first real project with WPF... I'm sure it's pretty ugly to real programmers.
The C code for the KFLOP board is at:
https://github.com/xdmattz/BP308/tree/m ... 20C%20Code
All the design files for the machine I'm working on are at:
https://github.com/xdmattz/BP308
you can see the current state of the machine here:
This is very much a work in progress but I'm having a good time with it.
Thanks
Dan Matthews
PS I'm having trouble getting images to show up in this post. Are there some instructions somewhere that show how to do it properly?