CNC Knurling

Advert

CNC Knurling

Home Forums Workshop Techniques CNC Knurling

Viewing 25 posts - 1 through 25 (of 33 total)
  • Author
    Posts
  • #561478
    John Haine
    Participant
      @johnhaine32865

      The recent thread on knurling tools triggered me to go back to a project I had in mind to try knurling on my CNC mill using the rotary axis.

      pxl_20210410_115434268.jpg

      I wrote a little spreadsheet to generate the g-code. Basically it uses an engraving cutter to mill a spiral groove along the workpiece whilst rotating it – initially for simplicity I'm making it move for one full lead while rotating 1 turn. On a half inch bit of brass that's ~41mm lead The cutter has a 90 degree point with a small flat (basically a PCB engraver). Hare are some pics of the first trial.

      pxl_20210905_211158063.jpg

      pxl_20210905_211253512.jpg

      Came out quite well though it took a long time – just over an hour. I wound't want to do it much faster as the spindle speed is a bit low (~6000 rpm) for the cutter. Also the depth of cut is slightly too large as I forgot the flat on the end of the cutter, and the number of "teeth" could probably be reduced. Sufficiently good though that a better "wizard" that can generate shorter knurls is probably worth writing, though the calculations are more involved. I now have some knurled bar to make a small batch of thumb nuts!

      Mod edit: rotated photo.

      Edited By SillyOldDuffer on 06/09/2021 10:50:04

      Advert
      #16315
      John Haine
      Participant
        @johnhaine32865
        #561488
        Ian Johnson 1
        Participant
          @ianjohnson1

          That turned out nice, the crests look sharp and well formed.

          I did something similar with my 4th axis to produce spliced thumb nuts. I used the corner of a 6mm end mill. I wonder if it would work on a spiral to produce a knurl like yours?

          splined thumb screw on the kx1 cnc mill.jpg

          IanJ

          #561495
          John Haine
          Participant
            @johnhaine32865

            I have seen something on the web about using an endmill, but have never been able to find it again! Difficult to do a fine knurl as I think you have to have the cutter offset to one side and at 45* to the axis, so anything but a small cutter produces quite a wide tooth. The engraving cutters are carbide and about a fiver for 10 from China!

            #561502
            IanT
            Participant
              @iant

              John,

              I'm not a CNC user but I am curious how you use a spreadsheet to generate G code? Is this process automated or are you just doing the calculations in the spreadsheet and then hand coding the results into your G code?

              Regards,

              IanT

              #561509
              DC31k
              Participant
                @dc31k

                Could you write a few words on the 'number of starts' to diameter ratio you have chosen please. I think that equates to where you say "the number of "teeth" could probably be reduced" .

                In principle, this would be possible on a manual lathe with live tooling (Dremel in the toolpost) but a major challenge is indexing the part for the multiple starts. I wonder if it would be possible to use an internal gear meshing with an external gear of the same number of teeth between chuck and backplate.

                #561512
                Martin Connelly
                Participant
                  @martinconnelly55370

                  img_20180720_144821.jpg

                  The photo shows the process using a marker pen on some tube.

                  The example looks to have about 36 passes in each direction, 10° offset per pass. A spreadsheet could be used to calculate the data for different angles and pitches for each pass as a function of the number of passes in each direction. You probably need to start off with this figure since you want an integer number of passes so an offset for each start where the offset angle divides into 360° without a remainder. So for example 13° would be no good. You then need to calculate the lead per rev to give the required helix angle which then gives rise to the total number of degrees for the given axis travel. Write a gcode program with a couple of simple loops, one for left hand spirals and one for right hand spirals that takes the given data to produce the knurls. You could probably write a fully parameterised gcode program to do the calculations rather than use a spreadsheet but that only becomes preferable if you are going to do a lot of CNC knurling.

                  Martin C

                  Edited By Martin Connelly on 06/09/2021 12:40:38

                  #561513
                  John Haine
                  Participant
                    @johnhaine32865

                    Ian, the sheet does both. It has a section that calculates the dimensions, feeds etc needed, then these are converted into g code using formulas such as this:

                    ="G00 X1 Y0 Z"&($H$3+1+C3/2)

                    The first bit quotes just writes G00 X1 Y0 Z into the cell. The & symbol in Excel concantenates this with what comes afterwards, which is the result of the calculation in the brackets which just contains standard cell references. The result in this case (for certain parameters) is

                    G00 X1 Y0 Z67.595

                    I'm cheating here because I've inserted some of the numbers by hand, but in other examples I've done all the numeric values are inserted from other cells in the sheet. So once I've built the sheet I can generate the code for specific dimensions by just changing the parameters. Done things like tapers, cams, crossing out, special pallet profiles for clocks etc.

                    #561516
                    John Haine
                    Participant
                      @johnhaine32865

                      Martin, actually it's 42 passes in each direction and the "tooth angle" is 8.571 degrees. It makes one cut right-to-left turning 360*, then another L-R turning another 360 in the same direction. Then advances by 8.571* and repeats. Since the diameter is 12.7mm the leads is pi x 12.7 = 39.898 mm for 90* diamond knurls. The A axis always goes the same way to avoid backlash problems.

                      This works when the length is equal to the lead, for shorter lengths it's more involved especially if you want to avoid lots of waits while the rotary axis moves to the next position.

                      DC31K, I started by thinking how deep the "teeth" should be for comfy gripping – I decided no more than 0.5mm. Then had some geometry for the depth of cut for a square tooth and used a spreadsheet goal-seek to find a convenient cut depth to give an integer number of teeth. Bit of trial and error gave me 42 and a cut depth of 0.492 mm. Actually it's less than this as the geometry isn't quite as I thought when you cut crossing "threads" and the peak diameter is reduced to 12.15mm.

                      Edited By John Haine on 06/09/2021 12:56:22

                      #561520
                      JasonB
                      Moderator
                        @jasonb

                        From a previous thread trying to do it on a lathe is not ideal a syou need a faster helix more like 0.25tpi for a 1/2" piece of stock.

                        These sketches were doen at the time, left and right hand cut at largest tpi on thelathe

                        screw1.jpg

                        Same thing but with multiple starts gives very long diamond shapes

                        screw5.jpg

                        But if you can increase the lead the single left and right cut looks more like thios

                        screw2.jpg

                        and with multiple starts you get the usual pattern from wheels with 45deg teeth

                        screw6.jpg

                        If you have CAD then it's quite easy to play about with the depth of the Vee cut, helix angle and number of starts so you get a pointed crest.

                        John I wonder if a chamfer mill with it's two flutes would speed things up for you as they are a bit more robust than engraving cutters and having two flutes can be fed at twice the rate

                        #561521
                        IanT
                        Participant
                          @iant

                          Thank you John – I used to know Excel reasonably well – so I might actually be able to figure this out.

                          I have been tempted into thinking about a really cheapie CNC engraver just to learn a little more. I have found the 3D Printer useful for specific things (it's certainly not a do-all solution of course) but I'd have to dust off the few remaining spare brain cells to cram anymore in !

                          Regards,

                          IanT

                          #561529
                          DC31k
                          Participant
                            @dc31k
                            Posted by IanT on 06/09/2021 13:08:30:

                            Thank you John – I used to know Excel reasonably well – so I might actually be able to figure this out.

                            Could I bang the drum a little for learning a programming language (e.g. Python) for this task?

                            The code used to make the above is a bit of preamble – setting up your variables – and then a lot of looping, with one parameter increasing each time until the loop is finished. In a programming language with inbuilt looping capability, this is easy. In a spreadsheet, it is more difficult.

                            I would say using a spreadsheet to produce G-code is comparable to milling in a lathe: possible but hard work.

                            Would it be correct to say that if you want a square base to your pyramid, the helix angle of the thread has to be 45 degrees? So in that sense, it is not a variable – you have to pick a lead that results in a 45 degree helix angle for your diameter.

                            #561537
                            John Haine
                            Participant
                              @johnhaine32865

                              Actually no looping at all in the spreadsheet, the g code uses a subroutine and the calling statement includes an L word, L42 in this case, which calls the subroutine 42 times.

                              But I agree that a programming language would be better. In this case Mach3 includes an ancient dialect of Visual Basic which is the natural though unfortunate choice as all its native wizards use it.

                              #561552
                              JasonB
                              Moderator
                                @jasonb
                                Posted by DC31k on 06/09/2021 14:18:52:

                                Would it be correct to say that if you want a square base to your pyramid, the helix angle of the thread has to be 45 degrees? So in that sense, it is not a variable – you have to pick a lead that results in a 45 degree helix angle for your diameter.

                                You want a helix with a pitch calculated by the dia of the workpiece less twice Vee deep x pi

                                So for example 12mm dia work with 1mm deep V would be 10 x 3.142 or 31.42mm pitch

                                #561665
                                John Haine
                                Participant
                                  @johnhaine32865

                                  Jason, thanks for the tool suggestion, I'll investigate.

                                  #562015
                                  John Haine
                                  Participant
                                    @johnhaine32865
                                    Posted by DC31k on 06/09/2021 14:18:52:

                                    Could I bang the drum a little for learning a programming language (e.g. Python) for this task?

                                    I'm looking further into writing a wizard for this – not a true wizard since it won't run inside Mach3 since I don't want to lose it when my Mach3 PC finally collapses and I move to a different CNC package. Also don't want to tie the code to a superannuated visual basic (not even Microsoft's). So I think Python, I've done a little bit of Python programming and I like the language. So what I want to do is to write code that asks for input parameters such as diameter, knurl length, and number of teeth, plus a few other things, and generates the g code as a text file. I have written code that writes data to a csv file but don't have experience with text files in Python.

                                    I know there are Pythoneers here, could anyone point me at or otherwise give an example of code that writes to a text file? I'd rather have an example to "be inspired by" (= copy!) than links to tutorial stuff, since the latter in my experience assumes Python knowledge I don't have!

                                    Thanks in advance!

                                    #562038
                                    Dave S
                                    Participant
                                      @daves59043

                                      This is microPython, rather than Python, but the file handling is the same IIRC.

                                      file writing on a pico

                                      The code snippet (culled from that link):

                                      #This writes whatever is passed to it to the file     
                                      def WriteFile(passed):
                                          log = open(LogFileName,"a&quot #open in append - creates if not existing, will append if it exists
                                          log.write(passed)
                                          log.close()
                                      
                                      should help 
                                      

                                       

                                      Dave

                                      Edited By Dave S on 09/09/2021 13:01:19

                                      #562044
                                      blowlamp
                                      Participant
                                        @blowlamp

                                        I tried to replicate this in CamBam and it looks like it should work OK.

                                        I drew a 45 degree line and replicated it at the correct spacing, to give a total of 42 lines. I then mirrored, copied & pasted them over the first set, to give a diamond pattern.

                                        All the lines can be engraved in one operation, by using the wrapped Rotary X post processor.

                                        Here's the gcode from CamBam, but it is very long so feel free to cut or truncate:

                                        Martin.

                                        ( Made using CamBam – http://www.cambam.co.uk )
                                        ( Untitled 9/9/2021 1:42:11 PM )
                                        ( Post processor: RotaryX )
                                        ( T0 : 0.0 )
                                        G21 G90 G64 G40
                                        G0 Z8.0
                                        ( T0 : 0.0 )
                                        T0 M6
                                        ( NOTE – assume rotating about X axis )
                                        G0 X0
                                        ( 45 Deg Knurl 12.732mm Diam Bar. 0.4mm Depth Cut. )
                                        G17
                                        M3 S0
                                        G0 A0.0
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-360.0112
                                        G0 Z8.0
                                        G0 A-364.2967
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-724.3078
                                        G0 Z8.0
                                        G0 A-728.5933
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-1088.6045
                                        G0 Z8.0
                                        G0 A-1067.1753
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-707.1641
                                        G0 Z8.0
                                        G0 A-702.8786
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-342.8674
                                        G0 Z8.0
                                        G0 A-321.4382
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-681.4494
                                        G0 Z8.0
                                        G0 A-685.7349
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-1045.7461
                                        G0 Z8.0
                                        G0 A-1024.3169
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-664.3057
                                        G0 Z8.0
                                        G0 A-660.0202
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-300.009
                                        G0 Z8.0
                                        G0 A-278.5798
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-638.591
                                        G0 Z8.0
                                        G0 A-642.8765
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-1002.8876
                                        G0 Z8.0
                                        G0 A-981.4584
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-621.4473
                                        G0 Z8.0
                                        G0 A-617.1618
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-257.1506
                                        G0 Z8.0
                                        G0 A-235.7214
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-595.7326
                                        G0 Z8.0
                                        G0 A-600.018
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-960.0292
                                        G0 Z8.0
                                        G0 A-938.6
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-578.5888
                                        G0 Z8.0
                                        G0 A-574.3033
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-214.2922
                                        G0 Z8.0
                                        G0 A-192.8629
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-552.8741
                                        G0 Z8.0
                                        G0 A-557.1596
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-917.1708
                                        G0 Z8.0
                                        G0 A-900.0271
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-1260.0382
                                        G0 Z8.0
                                        G0 A-1238.609
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-878.5978
                                        G0 Z8.0
                                        G0 A-874.3124
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-514.3012
                                        G0 Z8.0
                                        G0 A-510.0157
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-150.0045
                                        G0 Z8.0
                                        G0 A-171.4337
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-531.4449
                                        G0 Z8.0
                                        G0 A-535.7304
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-895.7416
                                        G0 Z8.0
                                        G0 A-857.1686
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-1217.1798
                                        G0 Z8.0
                                        G0 A-1195.7506
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-835.7394
                                        G0 Z8.0
                                        G0 A-831.4539
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-471.4427
                                        G0 Z8.0
                                        G0 A-467.1573
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-107.1461
                                        G0 Z8.0
                                        G0 A-128.5753
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-488.5865
                                        G0 Z8.0
                                        G0 A-492.872
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-852.8831
                                        G0 Z8.0
                                        G0 A-814.3102
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-1174.3214
                                        G0 Z8.0
                                        G0 A-1152.8922
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-792.881
                                        G0 Z8.0
                                        G0 A-788.5955
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X0.0 A-428.5843
                                        G0 Z8.0
                                        G0 A-424.2988
                                        G0 Z7.366
                                        G1 F120.0 Z5.966
                                        G1 F160.0 X-40.0 A-64.2876

                                        #562045
                                        blowlamp
                                        Participant
                                          @blowlamp

                                          Continued from above post.

                                          G0 Z8.0
                                          G0 A-42.8584
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-402.8696
                                          G0 Z8.0
                                          G0 A-407.1551
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-767.1663
                                          G0 Z8.0
                                          G0 A-771.4518
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-1131.4629
                                          G0 Z8.0
                                          G0 A-1110.0337
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-750.0225
                                          G0 Z8.0
                                          G0 A-745.7371
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-385.7259
                                          G0 Z8.0
                                          G0 A-381.4404
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-21.4292
                                          G0 Z8.0
                                          G0 A0.0
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-360.0112
                                          G0 Z8.0
                                          G0 A-364.2967
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-724.3078
                                          G0 Z8.0
                                          G0 A-728.5933
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-1088.6045
                                          G0 Z8.0
                                          G0 A-1067.1753
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-707.1641
                                          G0 Z8.0
                                          G0 A-702.8786
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-342.8674
                                          G0 Z8.0
                                          G0 A-321.4382
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-681.4494
                                          G0 Z8.0
                                          G0 A-685.7349
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-1045.7461
                                          G0 Z8.0
                                          G0 A-1024.3169
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-664.3057
                                          G0 Z8.0
                                          G0 A-660.0202
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-300.009
                                          G0 Z8.0
                                          G0 A-278.5798
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-638.591
                                          G0 Z8.0
                                          G0 A-642.8765
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-1002.8876
                                          G0 Z8.0
                                          G0 A-981.4584
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-621.4473
                                          G0 Z8.0
                                          G0 A-617.1618
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-257.1506
                                          G0 Z8.0
                                          G0 A-235.7214
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-595.7326
                                          G0 Z8.0
                                          G0 A-600.018
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-960.0292
                                          G0 Z8.0
                                          G0 A-938.6
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-578.5888
                                          G0 Z8.0
                                          G0 A-574.3033
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-214.2922
                                          G0 Z8.0
                                          G0 A-192.8629
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-552.8741
                                          G0 Z8.0
                                          G0 A-557.1596
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-917.1708
                                          G0 Z8.0
                                          G0 A-900.0271
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-1260.0382
                                          G0 Z8.0
                                          G0 A-1238.609
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-878.5978
                                          G0 Z8.0
                                          G0 A-874.3124
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-514.3012
                                          G0 Z8.0
                                          G0 A-510.0157
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-150.0045
                                          G0 Z8.0
                                          G0 A-171.4337
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-531.4449
                                          G0 Z8.0
                                          G0 A-535.7304
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-895.7416
                                          G0 Z8.0
                                          G0 A-857.1686
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-1217.1798
                                          G0 Z8.0
                                          G0 A-1195.7506
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-835.7394
                                          G0 Z8.0
                                          G0 A-831.4539
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-471.4427
                                          G0 Z8.0
                                          G0 A-467.1573
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-107.1461
                                          G0 Z8.0
                                          G0 A-128.5753
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-488.5865
                                          G0 Z8.0
                                          G0 A-492.872
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-852.8831
                                          G0 Z8.0
                                          G0 A-814.3102
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-1174.3214
                                          G0 Z8.0
                                          G0 A-1152.8922
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-792.881
                                          G0 Z8.0
                                          G0 A-788.5955
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-428.5843
                                          G0 Z8.0
                                          G0 A-424.2988
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-64.2876
                                          G0 Z8.0
                                          G0 A-42.8584
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-402.8696
                                          G0 Z8.0
                                          G0 A-407.1551
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-767.1663
                                          G0 Z8.0
                                          G0 A-771.4518
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-1131.4629
                                          G0 Z8.0
                                          G0 A-1110.0337
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-750.0225
                                          G0 Z8.0
                                          G0 A-745.7371
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-385.7259
                                          G0 Z8.0
                                          G0 A-381.4404
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-21.4292
                                          G0 Z8.0
                                          G0 A-85.7169
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-445.728
                                          G0 Z8.0
                                          G0 A-450.0135
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X0.0 A-810.0247
                                          G0 Z8.0
                                          G0 A-450.0135
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-810.0247
                                          G0 Z8.0
                                          G0 X0.0 A-445.728
                                          G0 Z7.366
                                          G1 F120.0 Z5.966
                                          G1 F160.0 X-40.0 A-85.7169
                                          G0 Z8.0
                                          M5
                                          M30

                                          Edited By blowlamp on 09/09/2021 13:46:14

                                          #562061
                                          SillyOldDuffer
                                          Moderator
                                            @sillyoldduffer
                                            Posted by John Haine on 09/09/2021 11:01:29:

                                            Posted by DC31k on 06/09/2021 14:18:52:

                                            Could I bang the drum a little for learning a programming language (e.g. Python) for this task?

                                            I know there are Pythoneers here, could anyone point me at or otherwise give an example of code that writes to a text file? I'd rather have an example to "be inspired by" (= copy!) than links to tutorial stuff, since the latter in my experience assumes Python knowledge I don't have!

                                            Thanks in advance!

                                            Not that it matters for small files, but Dave's example is slow because the file is opened and closed for each append. As open and close are expensive operations involving the operating system in permission checks and resource management, it's usual to open files once at the beginning and close them only at the end.

                                            My example writes 30 'hello' lines to a file once per second. It uses print() rather than write(), which I pedantically reserve for binary output. Omitting file=myFile, or setting file=sys.stdout, writes to the screen, which is useful whilst debugging.

                                            pyexample.jpg

                                            Dave

                                            #562063
                                            John Haine
                                            Participant
                                              @johnhaine32865

                                              Thanks Martin. The code I used from the spreadsheet, using a subroutine, is this.

                                              G00 X1 Y0 Z67.595 (Start position)
                                              G91 (Incremental)
                                              G00 A5 (Take out angular backlash)
                                              F100
                                              G01 Z-1.492 (Apply downfeed)
                                              G01 A360 (Cut groove)
                                              G00 Z1.492 (Lift tool)
                                              G00 X40.898 (Move for other groove)
                                              G01 Z-1.492 (Apply downfeed)
                                              G01 A360 (Cut groove)
                                              M98 p2000 L42 (Call helix sub)
                                              G00 X1 Y0 Z67.595 (Start)
                                              G90 (Absolute mode)

                                              o2000 (Helix sub)
                                              G91 (Enter incremental mode)
                                              G01 X-39.898 A360 (Cut helix at current depth)
                                              G01 X39.898 A360 (Cut back to start)
                                              G01 A8.571 (feed one tooth)
                                              M99 (Return)

                                              One thing to try to avoid in this is long positioning rotations of the A axis which take a long time. This is avoided in my code in this case by making 360 degree rotations as part of the cut but I am aking a long knurl for demo purposes. I've realised that if one slightly constrains the problem one can make shorter knurls with no re-positioning of the rotary axis at all. The subroutine though only works as long as the controller supports them – Mach 3 does but GRBL for example doesn't, so I'd like to produce in-line code as you have which has no looping or branching. Still I think one should need only twice as many G-code lines as there are "teeth" around the knurl except for a few extras at the start and end.

                                              #562072
                                              John Haine
                                              Participant
                                                @johnhaine32865
                                                Posted by SillyOldDuffer on 09/09/2021 15:58:42:

                                                pyexample.jpg

                                                Dave

                                                Thanks Dave. Does "print" put a newline after each instance or should that be added? And I notice you are using a "w" method, would it be better to use "a"?

                                                #562074
                                                Dave S
                                                Participant
                                                  @daves59043

                                                  w is write, and will trash an existing file of the same name, a is append – so open if the file is there and write to the end, otherwise create a new one.

                                                  It makes little difference if you are creating the whole file at once.

                                                  My earlier example was for a rolling log file, where you actually want to keep the existing data – just the handiest example I had around.

                                                  edited to say I think in Python there is an implicit newline in a print

                                                   

                                                  Dave

                                                   

                                                  Edited By Dave S on 09/09/2021 17:18:11

                                                  #562094
                                                  John Haine
                                                  Participant
                                                    @johnhaine32865

                                                    Thanks!

                                                    #562096
                                                    SillyOldDuffer
                                                    Moderator
                                                      @sillyoldduffer

                                                      By default print() terminates with end-of-line

                                                      It can be turned off, or changed to something else, by adding an end parameter:

                                                      print('hello', end = ""    )  # end-of line is nothing

                                                      Dave

                                                      pesky smiley!

                                                      Edited By SillyOldDuffer on 09/09/2021 19:34:28

                                                    Viewing 25 posts - 1 through 25 (of 33 total)
                                                    • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

                                                    Advert

                                                    Latest Replies

                                                    Home Forums Workshop Techniques Topics

                                                    Viewing 25 topics - 1 through 25 (of 25 total)
                                                    Viewing 25 topics - 1 through 25 (of 25 total)

                                                    View full reply list.

                                                    Advert

                                                    Newsletter Sign-up