Hello Guest it is December 05, 2024, 12:13:07 PM

Author Topic: Automated start at a specific line in the gcode program  (Read 3702 times)

0 Members and 1 Guest are viewing this topic.

Automated start at a specific line in the gcode program
« on: July 21, 2022, 04:08:18 AM »
Hi

We need a piece of advice to see if an automated defect detection and correction program can run in Mach4. For example, our current gcode program has different sections such as:
Section 1 – Gcode blocks (lines 1-10)
Section 2 – Gcode blocks (lines 11-20)
Section 3 - Gcode blocks (lines 21-30)
Etc.

Defect Scanning
To implement the defect detection, we can easily insert a block that activates and output (M64 p#) and waits a specific time to do a scanning (G4 P#). It is just moving the piece below the camera and scanning. Easy. The new program should be written as:
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21)
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
Etc.

Defect detection and correction
Then, the post-processing of the image will be done in another software (python, Matlab, etc). It will detect if there is an error, and here is our problem, How do we inform Mach4 there is an error and how to correct it.
Problem 1. How do we inform mach4 there is an error? 
I think it will be easy to write on the signal script to actively search for a digital input to STOP the program. This is something similar than having a limit switch. We are using soft limits because we have absolute encoders, and the systems works perfectly with that. Can we use a limit axis input if the soft limits are active? I think this would be the fastest solution. However, if a limit switch is activated, it disables mach4 rather than stopping the program, and restart the program from a different gcode line, which is the stated in the problem 2.

Problem 2. How to correct the defect.

Our strategy to correct the defect is “simple” as we only need to Re-Start the gcode program in a previous section decided by the external software. We can do it manually once we see the software indicates an error, but the idea is to automate it and eliminate human interaction. In the following program, the first phase corresponds to “defect detection and stopping the program”, and the second phase correspond to start the program in a previous fcode line commanded by the software as shown below:
(First phase: defect detection)
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21)
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
(-comment: defect detected, digital input is activaded, program is stopped)
Section 4 - Gcode blocks (lines 33-42)
   Subsection 1 – gcode block for defect detection
Etc

(second phase: defect detection)
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21) – New start of the program
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
Section 4 - Gcode blocks (lines 33-42)
   Subsection 1 – gcode block for defect detection
Etc

The question here is how we can tell mach4 to start the program at a specific line? Which communication to use? We are using an EtherCAT controller with several several GPIO, also we can have analog inputs and outputs. Maybe, there is another type of communication to inform mach4 which line to start in the program. I believe it shouldn’t be something that complicated, but not sure if mach4 can do it.

The second option is if the loading and running of a gcode program can be automated. Python, Matlab, etc then will chop the original program and upload the new one. is it possible?

What thoughts do you have? is it possible?

Kind regards


Pablo