Gcode generation from Excellon file - Improvements

Issue #186 new
Marius Stanciu created an issue

I've made a few modification to the camlib.py file (after seeing some reference from JP that there was the place where the drill gcode "magic" is happening.

I am sharing them here in the hope that they may find way into the next release.

In the CNCJob class , the "generate_from_excellon_by_tool" function, I made the following modifications:

  1. From
up = "G01 Z%.4f\n" % self.z_move

to:

up = "G00 Z%.4f\n" % self.z_move

EFFECT: the retract to the travel position is made with G00 command which means it is made very fast.

REASON: Because I make boards with a lot of via's and drill holes (hundreds of them :)) ), by doing this modification I practically halved the time required to drill the holes. Also, if I have holes with larger diameter and use a lower feedrate, it is taking too long to come back to the travel depth position.

2 . From:

# Tool change sequence (optional)
            if toolchange:
                gcode += "G00 Z%.4f\n" % toolchangez
                gcode += "T%d\n" % int(tool)  # Indicate tool slot (for automatic tool changer)
                gcode += "M5\n"  # Spindle Stop
                gcode += "M6\n"  # Tool change
                gcode += "(MSG, Change to tool dia=%.4f)\n" % exobj.tools[tool]["C"]
                gcode += "M0\n"  # Temporary machine stop

to:

# Tool change sequence (optional)
            if toolchange:
                gcode += "G00 Z%.4f\n" % toolchangez
                gcode += "G00 X0Y0\n" #Go to X0 Y0 point
                gcode += "T%d\n" % int(tool)  # Indicate tool slot (for automatic tool changer)
                gcode += "M5\n"  # Spindle Stop
                gcode += "M6\n"  # Tool change
                gcode += "(MSG, Change to tool dia=%.4f)\n" % exobj.tools[tool]["C"]
                gcode += "G01 Z0\n" # Go to zero depth (on Z axis) in order to adjust the drill bit height
                gcode += "M0\n"  # Temporary machine stop
                gcode += "G00 Z%.4f\n" % toolchangez # Go to toolchange position to tighten the nut
                gcode += "M0\n"  # Temporary machine stop

                gcode += "G00 Z%.4f\n" % self.z_move # Move to travel depth

EFFECT: Manual toolchange. When the toolchange event appear, the CNC will move to the toolchange depth (set in software) and then will travel to origin (X0Y0). There will wait for me to change the drill bit. I mount the drill into the chuck a little loose and I will not tighten the nut. After I hit Cycle start (in MACH3 software) it will move to the Z0 depth with the feedrate set in software (G01 command). Here I make the adjustment so the drill bit tip touch the PCB and then tighten the nut a bit so it stays in position. After that I hit again Cycle start button and then the drill bit will travel again to the toolchange depth position. Here I tighten the nut in a serious way, and hit again the Cycle start. After that the drill bit will go to the travel depth and the router will start the drilling action with the new drill bit.

REASON: If my PCB have different drill diameters (the usual) I get to adjust the drill bit in the chuck without too many operations (manual entering commands G01Z0 and back to the toolchange position and so on). Not all the drill bits have collars and even then, there is no guarantee that all collars are at the same location (especially with the drill bits bought from China).

Comments (7)

  1. Marius Stanciu reporter

    3 . From:

            gcode += t % (0, 0)
            gcode += "M05\n"  # Spindle stop
    

    to:

            gcode += t % (0, 0)
            gcode += "G00 Z%.4f\n" % toolchangez # Go to toolchange position as the final move, to remove the drill bit     
            gcode += "M05\n"  # Spindle stop
    

    EFFECT: at the end of the drill program, the drill bit will be raised to the toolchange position.

    REASON: just because the program can do it so I don't have to go to the computer and manually raise the drill bit so I can remove it from the chuck.

  2. Marius Stanciu reporter

    After some testing I found that it is better to have the last line in case 2 (from above) changed from:

    gcode += "G00 Z%.4f\n" % self.z_move # Move to travel depth
    

    to

    gcode += "G01 Z%.4f\n" % self.z_move # Move to travel depth
    

    It is safer to go down slower since if something went wrong (like changing the wrong drill bit :) ) at least you have the time to hit the Emergency Stop button ...

  3. Victor Lorenzo

    In your second code change (2), in my opinion it is dangerous to make a travel to Z=0 after changing the drill bit. Not all drill bits have the same length. Drills from LPKF use to be of similar length and use to have the same shaft diameter but standard precision drills have a length which is dependent on the drill diameter (e.g. my 0.5mm drills are less than 30mm long while the 3.2mm ones are almost three times longer).

    I've created an auto tool zero script for Mach3 which I use for this purpose, but I use it manually after the head is moved to tool change Z.

  4. Marius Stanciu reporter

    Victor, first "Happy New Year!"

    Actually this modification works very well for my modified Flatcam version.

    I understand your point of view but here is what I do, and it is very safe for my use case:

    1. When a toolchange command is encountered,the spindle will go to the toolchange height.
    2. Next move is to go to X0 - Y0 point (the origin point).
    3. In this point (X=0, Y=0, Z= toolchange height) the spindle is stopping and waiting for me to remove the current drill bit and mount the next drill bit into the chuck. I do this, but here is the important thing: I do not tighten the drill bit, I let it loose and use one of my hands to keep it in place. Then I hit continue on Mach3 and after that,
    4. The spindle will be lowered at Z=0. Here I let the drill bit loose, it will fall a bit and once it touch the material (PCB) I tighten the chuck nut a bit, enough that the drill bit will not move. The fact the drill bit will fall a bit comes from the fact that when I make the zero of Z axis, I take care so all the drill bit's have enough clearance between the chuck and the drill bit collar.
    5. I hit continue on Mach3 and it will go at Z=toolchange depth and here I tighten the nut enough for a good drilling behavior.
    6. Hit continue and the router will resume drilling from where it stopped.

    Now, if you use drill bits with significant tail length difference then of course, this mod will not work. But since FlatCAM target PCB production, almost everybody I know or talked with, use carbide drill bits with 3.125mm tail diameter that have a standardized length. Even cheap carbide drill bits bought on eBay from China do not vary much in length. The worst can happen is a drill bit that will break and for the other issues, there is a reason for the presence of the EMERGENCY STOP button.

    But you can make a selection of your drill bits based on length, group them and create different drilling GCODE files for those groups that imply a different zero depth for the Z axis. Then you will not have issues with manual changing of the drill bits.

    Using a CNC router can be a dangerous thing if people don't know what they are doing. Never use a tool that you are not familiar with. Nothing is really "safe" unless we know what we are doing. This is why a user manual is essential and using software development versions can create all sort of problems.

  5. Victor Lorenzo

    Happy new year for you too, Marius!

    I understand your point and your solution. Mine is one of those possibly rare cases as I use drill bits with different tail lengths. I spent a few years designing machines for automating several processes in smartcards manufacturing so I had to learn, and learn as well as I could, the principle of "safety goes first".

    I have one personal project with plans to complete this or next month, a sensor and a set of Mach3 macros for complete semi-automatic tool change. That means, you make the first calibration, then on every Tn M6 the machine moves the tool to a safe location, you change the tool, and the machines does the rest of the calibration process automatically. I already have completed the sensor design but still need some time for prototyping it.

    Thanks for sharing your thoughts.

  6. Log in to comment