Halt and resume GCodes
Moderators: TomKerekes, dynomotion
-
- Posts: 25
- Joined: Wed Sep 04, 2019 11:56 am
Halt and resume GCodes
Hello again,
In KMCNC I can see how you can run GCode step by step and I am trying to imitate that feature.
In my application, I can run GCodes and stop the running using KM_Interpreter.Halt(). I would like to resume running from the point where it has stopped after halt. In the documentation I found KM_Interpret(String fname, Int32 start, Int32 end, Int32 restart) but to use it I need to know the line where the program stopped, and I don't understand how to use the last int restart.
How can I solve this? Is there any method or property I am missing?
Thanks again!
In KMCNC I can see how you can run GCode step by step and I am trying to imitate that feature.
In my application, I can run GCodes and stop the running using KM_Interpreter.Halt(). I would like to resume running from the point where it has stopped after halt. In the documentation I found KM_Interpret(String fname, Int32 start, Int32 end, Int32 restart) but to use it I need to know the line where the program stopped, and I don't understand how to use the last int restart.
How can I solve this? Is there any method or property I am missing?
Thanks again!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Halt and resume GCodes
Hi Juanjo-Lasing,
If you register for the Interpreter Complete Callback then the Interpreter will make a call back to your application when the Interpreter stops executing. The callback will pass the line number, any error status etc. You might see how the function Interpreter_InterpreterCompleted in the KMotion_dotNet Console Example handles this.
The restart parameter is used to re-initialize the Interpreter. It basically resets the Interpreter settings based on the Interpreter's setup file. This is normally set when executing the first line of the File and not set when executing other lines.
Note that single-stepping GCode is fairly straightforward, however random Halt/Resume is more complicated because of the issue where the tool may stop part way through a line of GCode. In these cases re-executing the same line of GCode or the next line of GCode may cause undesirable results.
If you register for the Interpreter Complete Callback then the Interpreter will make a call back to your application when the Interpreter stops executing. The callback will pass the line number, any error status etc. You might see how the function Interpreter_InterpreterCompleted in the KMotion_dotNet Console Example handles this.
The restart parameter is used to re-initialize the Interpreter. It basically resets the Interpreter settings based on the Interpreter's setup file. This is normally set when executing the first line of the File and not set when executing other lines.
Note that single-stepping GCode is fairly straightforward, however random Halt/Resume is more complicated because of the issue where the tool may stop part way through a line of GCode. In these cases re-executing the same line of GCode or the next line of GCode may cause undesirable results.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Wed Sep 04, 2019 11:56 am
Re: Halt and resume GCodes
Hey, Tom,
I review the example and see that the function is used with the KM_GCodeInterpreterCompleteHandler and that it is somehow added to the main controller using
_Controller.CoordMotion.Interpreter.Interpreter.InterpreterCompleted += new KMotion_dotNet.KM_Interpreter.KM_GCodeInterpreterCompleteHandler(Interpreter_InterpreterComplete);
With that the controller knows the line where the program stopped?
What I'm trying to do is to be able to pause a GCode program, waiting to finish the instruction that the program is running when I pause it, to avoid the problems you've mentioned, and then resume it from the next line to the end of the program.
Thanks.
I review the example and see that the function is used with the KM_GCodeInterpreterCompleteHandler and that it is somehow added to the main controller using
_Controller.CoordMotion.Interpreter.Interpreter.InterpreterCompleted += new KMotion_dotNet.KM_Interpreter.KM_GCodeInterpreterCompleteHandler(Interpreter_InterpreterComplete);
With that the controller knows the line where the program stopped?
What I'm trying to do is to be able to pause a GCode program, waiting to finish the instruction that the program is running when I pause it, to avoid the problems you've mentioned, and then resume it from the next line to the end of the program.
Thanks.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Halt and resume GCodes
Hi Juanjo-Lasing,
Actually the Interpreter has a HaltNextLine() function but it is not currently exported to .NET. KMotionCNC uses it to allow KFLOP User C Programs to halt on the next line. This sometimes makes sense as the User Program knows the Interpreter has invoked the program via an MCode and is waiting on that line for the MCode to complete.
Consider using the Halt mechanism that KMotionCNC uses. This allows instant halting and resuming. Halting the Interpreter handles most of the messy details for you. The Halt mechanism in the Interpreter immediately performs a FeedHold. It then rewinds the Interpreter (from the lookahead) back to the exact point the motion came to a stop. It records enough information to allow automatically resuming from that point as long as nothing is moved.
KMotionCNC has code to check if it is resuming after a halt and something has been moved. If so, it prompts the Operator on how it should move back to the point it was. This information can then be set into the Interpreter for it to be executed when the Interpreter begins. See the "Resume" methods in the Interpreter Class. Another option may be to simply not allow to resume if anything moved. You might see the KMotionCNC C++ CheckForResumeCircumstances() function.
HTH
YesI review the example and see that the function is used with the KM_GCodeInterpreterCompleteHandler and that it is somehow added to the main controller using
_Controller.CoordMotion.Interpreter.Interpreter.InterpreterCompleted += new KMotion_dotNet.KM_Interpreter.KM_GCodeInterpreterCompleteHandler(Interpreter_InterpreterComplete);
With that the controller knows the line where the program stopped?
There isn't currently a method of doing this because the Interpreter and Trajectory Planner have look ahead and may be many GCode lines ahead of what is being executed. Also a line of GCode could possibly take a very long time to execute.What I'm trying to do is to be able to pause a GCode program, waiting to finish the instruction that the program is running when I pause it, to avoid the problems you've mentioned, and then resume it from the next line to the end of the program.
Actually the Interpreter has a HaltNextLine() function but it is not currently exported to .NET. KMotionCNC uses it to allow KFLOP User C Programs to halt on the next line. This sometimes makes sense as the User Program knows the Interpreter has invoked the program via an MCode and is waiting on that line for the MCode to complete.
Consider using the Halt mechanism that KMotionCNC uses. This allows instant halting and resuming. Halting the Interpreter handles most of the messy details for you. The Halt mechanism in the Interpreter immediately performs a FeedHold. It then rewinds the Interpreter (from the lookahead) back to the exact point the motion came to a stop. It records enough information to allow automatically resuming from that point as long as nothing is moved.
KMotionCNC has code to check if it is resuming after a halt and something has been moved. If so, it prompts the Operator on how it should move back to the point it was. This information can then be set into the Interpreter for it to be executed when the Interpreter begins. See the "Resume" methods in the Interpreter Class. Another option may be to simply not allow to resume if anything moved. You might see the KMotionCNC C++ CheckForResumeCircumstances() function.
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Wed Sep 04, 2019 11:56 am
Re: Halt and resume GCodes
Hi Tom,
Thank you for your replies.
I am using the FeedHold() and ResumeFeedHold() methods to pause and resume the program. It's not exactly what I wanted to do, but I can handle it and it's enough for now.
Another feature in KMotionCNC that interests me is that the program indicates the GCode line that is currently running. I would like to include it in my application. I have already done a function that executes the GCode line by line by pressing a Step button using KM_Interpret(String fname, Int32 start, Int32 end, Int32 restart), and I highlight that line while it is running. But when I run the full GCode using KM_Interpret(String fname) I can't do it because I can't know which line is running at any instant. Is there any way to know which line is running at any instant while running a full GCode program?
Thank you for your replies.
I am using the FeedHold() and ResumeFeedHold() methods to pause and resume the program. It's not exactly what I wanted to do, but I can handle it and it's enough for now.
Another feature in KMotionCNC that interests me is that the program indicates the GCode line that is currently running. I would like to include it in my application. I have already done a function that executes the GCode line by line by pressing a Step button using KM_Interpret(String fname, Int32 start, Int32 end, Int32 restart), and I highlight that line while it is running. But when I run the full GCode using KM_Interpret(String fname) I can't do it because I can't know which line is running at any instant. Is there any way to know which line is running at any instant while running a full GCode program?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Halt and resume GCodes
Hi Juanjo-Lasing,
There is another call back for the Interpreter that you can register to receive status including the line number that was processed. See the KMotion_dotNet Console Example.Another feature in KMotionCNC that interests me is that the program indicates the GCode line that is currently running. I would like to include it in my application. I have already done a function that executes the GCode line by line by pressing a Step button using KM_Interpret(String fname, Int32 start, Int32 end, Int32 restart), and I highlight that line while it is running. But when I run the full GCode using KM_Interpret(String fname) I can't do it because I can't know which line is running at any instant. Is there any way to know which line is running at any instant while running a full GCode program?
Code: Select all
static void Interpreter_InterpreterStatusUpdated(int lineno, string msg)
{
Console.WriteLine("Interpreter Status Update:");
Console.WriteLine(lineno);
Console.WriteLine(msg);
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Wed Sep 04, 2019 11:56 am
Re: Halt and resume GCodes
Hello Tom,
I tested that method, printing the line number while running a GCode, and it seems that the number increases faster than the movement.
For example, with this GCode for a square:
I think this is because this call back returns the line that has been processed by Kflop but not the actual motion line. Probably, with longer GCode instructions, this difference will increase.
Is there any way to know the exact line that is currently running, not the one that has been processed?
Thanks again.
I tested that method, printing the line number while running a GCode, and it seems that the number increases faster than the movement.
For example, with this GCode for a square:
When it is still running the line 3G0 X0 Y0 Z0
F50
G1 X5 Y0
G1 X5 Y5
G1 X0 Y5
G1 X0 Y0
the line number changes to 4 before line 3 movement ends.G1 X5 Y0
I think this is because this call back returns the line that has been processed by Kflop but not the actual motion line. Probably, with longer GCode instructions, this difference will increase.
Is there any way to know the exact line that is currently running, not the one that has been processed?
Thanks again.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Halt and resume GCodes
Hi Juanjo-Lasing,
Sorry my mistake. The callback occurs when the Intrepreter processes the line so it will be working ahead.
You should be able to use the Interpreter's CurrentLine property to get the real-time line number that the tool is currently executing.
ie.
_Controller.CoordMotion.Interpreter.SetupParams.CurrentLine
HTH
Sorry my mistake. The callback occurs when the Intrepreter processes the line so it will be working ahead.
You should be able to use the Interpreter's CurrentLine property to get the real-time line number that the tool is currently executing.
ie.
_Controller.CoordMotion.Interpreter.SetupParams.CurrentLine
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 25
- Joined: Wed Sep 04, 2019 11:56 am
Re: Halt and resume GCodes
Hello Tom,
That worked perfectly, thank you!
That worked perfectly, thank you!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Halt and resume GCodes
Hi Juanjo-Lasing,
Great. Thanks for taking the time to post back.
Great. Thanks for taking the time to post back.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.