Program to Calculate all Possible Lathe Thread Pitches

Advert

Program to Calculate all Possible Lathe Thread Pitches

Home Forums Suggested Online Resources Program to Calculate all Possible Lathe Thread Pitches

Viewing 25 posts - 1 through 25 (of 38 total)
  • Author
    Posts
  • #316934
    richardandtracy
    Participant
      @richardandtracy

      Some while ago I became suspicious of one of the thread pitches quoted in my Warco WMT300 handbook, the 3mm pitch thread was wrong by close on to 15%, and (embarrassingly) I discovered that 10 years after getting the lathe, it hadn't been delivered with all the wheels it should have been – I didn't check when I got the lathe, just counted the wheels without opening the wrapping plastic – and it did have unexpected duplicates. This meant that I couldn't cut half the metric threads in the lathe manual. After enquiring as to the price of the wheels I needed (after 10 years I couldn't reasonably ask for them to be supplied FOC), and gulping loudly, I decided to write a spreadsheet to check the accuracy of the pitches in the manual and try to work out wheel combinations to make up some of the other threads for nothing instead. The manual threads were fairly consistent in being 1.59% in error, except the 3mm pitch which had a 70 tooth wheel instead of 63, which was the cause of the pitch error. After a good deal of trial and error I found alternatives for most of the metric threads I wanted, but it stuck me that it was more error than success & there must be a better way of doing things.

      You may be aware that every screw cutting lathe can actually cut a lot more threads than the manufacturer usually specifies in the handbook, and with pen making I wanted quite a number of non-standard threads. After the hours trying, I had proved trial & error was not a viable method, as it took too long to find the pitch I wanted, so what I really wanted was a method of quickly calculating every possible pitch, searching through the list and selecting the ones I want. So.. how to do it?

      Well, I wrote a program that used the brute ignorance & force method to try every possible combination of wheel in the lathe and calculate the pitch for it. The program is pretty simple and does not check if the wheels will actually fit in the available space (it would require too much detail about gear module, distance between shafts etc to be entered, to be worth programming for a program that really only runs once per lathe), but it does check every theoretical combination and allow the user to try them out quickly & easily. There are usually many alternatives giving the same pitch, so if one combination won't fit, another probably will.

      It turned out there were quite a few combinations for my lathe – the 755,160 possible combinations led, due to duplication of wheels, to about 230,000 distinct different combinations producing around 30,000 different pitches (I'm guessing, I haven't counted), and I found I was able to get thread pitches from 0.0708 mm to 5.185mm (358 to 4.898tpi). At the 1.5mm pitch range I particularly wanted, there are 356 different combinations to try that all produce exactly 1.5mm pitch to 14 decimal places, and then a further thousand or so giving a perfectly viable error of less than 1%.

      So, what has this to do with the ME forum?

      Well, I thought other people may be able to use the program. It is certainly applicable to the Warco WMT300/1 & WMT300/2 Combi's and all other badged alternatives of the lathe (Clarke CL430/500M, Chester Model B, Sealey SM27). It is also applicable to every single lathe that uses 4 gear wheels with a drive train similar to that shown schematically in the diagram below:

      The program directly applies to the Seig SC2, SC3 and SC4. With a bit of thought it could probably be applied to the SC6. It also applies to the Warco Super Mini, WMT500 Combi and WM150. It may apply to the WM180 with thought.The program does apply directly to the Chester Centurion 3 in 1 & long bed Centurion, Conquest Lathe Super & Superior, DB7, DB8 and DB11. It applies equally to many Grizzly & US badged lathes with the same drive train layout.

      The program window looks as below (with all the data for my Warco filled in):

      I have added a 2 page help file accessed through the 'Schematic and Help' button, made the data entry a bit easier than when I initially wrote the program, and programmed in two different output formats for the available thread pitches. The program can output to a PDF or CSV file for further manipulation in a spreadsheet. The PDF file can be quite big, so do not be surprised if there are 1000 pages in it, for my lathe and rather odd wheel combinations, I get 2991 A4 pages at 76 combinations per page, and a file size of 125Mb. On opening the pdf file, Adobe Acrobat Reader states that there is an error in the pdf file and 'repairs' the file. It speaks with forked tongue – it doesn't; it just wants to convert it from the uncompressed version 1.3 file format to a more recent and verbose compressed format and thereby slow the opening and responsiveness of the file (I had to know the v1.3 pdf format inside out before I could programme the unit to create a pdf file, and I know it's right – no other PDF reader objects to the files created by the pdf code I wrote).

      You can download a zip file of the program here:

      http://www.chestnutpens.co.uk/downloads/ThreadPitchProgram.zip

      [continues] 

      Advert
      #21552
      richardandtracy
      Participant
        @richardandtracy
        #316935
        richardandtracy
        Participant
          @richardandtracy

          The program is a self contained 32 bit Windows program that should run on any version of Windows from Win95 onwards and should also run under WINE on Linux. I have tried the program on Win7 (64bit) and WinXP (32 bit), and it definitely works on both operating systems. The zip file includes a readme file, the help file, executable file, and calculation unit source code (so you can check that the code does nothing nasty to your machine if you want to). The program creates a file in its own directory called 'data.ini' to keep the gear wheel sizes and pdf file preferences for next use. If you have any of my CNC programs and put the program in the same directory, they will all share the same 'data.ini' file, keeping the clutter down.

          Instructions for how to use the program are given on page 2 of the help file. Please note that the program can take a while to run, and Windows occasionally gets bored, looses focus and the program does not update the progress indicators. Just leave it to run, if there is a problem it will exit cleanly and tell you what happened in the box at the bottom, but if it seems frozen, that's simply a symptom of Windows not knowing how to cope with a calculation intensive task and it behaving like it has the attention span of a goldfish.

          I hope you find it useful when you need an odd thread pitch, loose a wheel or simply want to play.

          Regards,

          Richard.

          #317016
          Thor 🇳🇴
          Participant
            @thor

            Hi Richard,

            I downloaded and tried your program, for some reason it outputs zero (0) pages in the PDF file?

            Thor

            #317020
            Les Jones 1
            Participant
              @lesjones1

              If you go to this page of the "Lathes.co" website you can download a program called NthreadsP.exe that should do what you want. I use it with my Chester DB-10G lathe and it normally finds a combination that will produce the thread I want.

              Les.

              Edited By Les Jones 1 on 14/09/2017 18:06:27

              #317021
              SillyOldDuffer
              Moderator
                @sillyoldduffer

                Hi Richard.

                After a brief tussle I have it working with wine. Initially same problem as Thor, but on the second attempt it fired up OK. Something to do with populating data.ini on first use?

                Dave

                #317023
                Thor 🇳🇴
                Participant
                  @thor

                  Dave, same experience as you, except with data.ini populated I get lots of PDF pages, but all are empty.

                  Thor

                  Edited By Thor on 14/09/2017 18:27:53

                  #317041
                  richardandtracy
                  Participant
                    @richardandtracy

                    That is one problem I have never had. It's amazing how people come across problems that seem baffling and shouldn't happen.

                    Could you try with outputting to a .CSV file?

                    The other option I can think of is, have you put in a 'final ratio'? Needs to be 1 if no other value is put in. A final possibility is is a font selected from the three options. It should default to 'Helvetica' but may not.

                    If that doesn't work, could you post the contents of data.INI, so I can try it myself?

                    Regards

                    Richard.

                     

                    Edited By richardandtracy on 14/09/2017 19:49:19

                    #317098
                    Thor 🇳🇴
                    Participant
                      @thor

                      Hi Richard,

                      I have sent you a PM with the .INI file. I have also tried your program on a computer running Windows 10, the result won't display in Edge (just get an error message), but I can view the result in FireFox?

                      Thor

                      #317101
                      not done it yet
                      Participant
                        @notdoneityet

                        After a brief tussle I have it working with wine.

                        Dave,

                        Was that red or white?smiley Or maybe the wine caused the typo?smiley

                        #317121
                        richardandtracy
                        Participant
                          @richardandtracy

                          As a result of Thor's .ini file I discovered that it did not respond well to decimal commas being used in the input. I have changed the program to include a text parse to convert any inputted commas into decimal points.

                          While looking for the source of Thor's problem, I did notice a silly bug in the pdf output if no initial gearbox was specified where I had misplaced a closing brace so it didn't include a statement it should have done. I have corrected that.

                          To prevent the apparent problems of data.ini not being present, I've included a really basic one that works in the zip file with 5 tooth numbers in it. If the teeth are not in your list, delete them and add the ones you want.

                          I will try to get the modified file uploaded this evening.

                          Regards,

                          Richard.

                          #317124
                          richardandtracy
                          Participant
                            @richardandtracy

                            Thor,

                            I don't know why the PDF file won't work on 'edge' – though it's one I've not heard of.

                            Possibly the file format is too old.

                            I deliberately went to a pdf format as early as possible for several reasons. I hoped for maximum compatibility (therefore early format) and my mind goes completely to mush when I try to understand how run-length, variable byte length zip compression works in a file. Apparently the byte length supported by the pdf zip compression can be between 9 and 12 bits, and varies as the stream progresses before re-setting to 9 bits when the 12 bit bytes cannot contain the encoded data. Unfortunately the pdf spec I read had been written by someone who didn't seem to understand it well (or understood it too well) and I couldn't get head nor tail of the explanation. All pdf formats after v1.3 use compression in the object data streams, but it's optional in the 1.3 format. Because I don't understand it, I opt out.

                            Regards,

                            Richard.

                             

                            Edited By richardandtracy on 15/09/2017 10:07:18

                            #317126
                            SillyOldDuffer
                            Moderator
                              @sillyoldduffer
                              Posted by richardandtracy on 14/09/2017 19:41:07:

                              It's amazing how people come across problems that seem baffling and shouldn't happen.

                              Regards

                              Richard.

                              Edited By richardandtracy on 14/09/2017 19:49:19

                              Something to do with the way our minds work when we write. I always check my forum posts before hitting the send button. Despite checking beforehand, reading my own post after it's gone public often reveals obvious errors. What the Flip is going on? I have the same problem with proof reading and even more so with software. I seem to read what I think I said rather than what's actually there, my mind automatically correcting the mistakes so I don't see them.

                              It's quite interesting to experiment with deliberately mangled text. Ti semes msot poeple acn reda wrdos prvoided thye hvae teh rihgt lettres. Humans are good at pattern recognition, but it seems to create serious blindspots. I think the problem is most severe with software because it contains loops, conditions, sequences, interfaces, coupling and structure as well as spelling. Even worse, most programmers have to test their own work, so the testing may also be unconciously biased to skip conditions that would flush out the bug.

                              The most amazing thing to me about software is that it works at all!

                              Dave

                              PS. A thought about the 'Windows Hanging, be patient' issue. It's because the operating system expects GUI programs to be interactive and thinks they've crashed if they spend too much CPU time in background . I'm not familiar with VCL but I expect it has a function that allows code to check the event queue. If you call that function periodically during a long calculation, Windows (and Linux) will know that the GUI hasn't crashed, thus avoiding the 'Not Responding' warning. You don't have to handle the events.

                              #317127
                              Thor 🇳🇴
                              Participant
                                @thor

                                Thanks Richard,

                                I will try your new version of the program.

                                Thor

                                #317129
                                richardandtracy
                                Participant
                                  @richardandtracy

                                  Dave,

                                  There is a function applied to each form (read 'Window' )    in the VCL library, and it's the 'Refresh()' method built into the TForm object, which I call up every 10 pdf pages or so. Amongst other things it sends Windows a WM_PAINT message to trigger a redraw and halts the process to flush the message buffer. But somehow Windows forgets this.

                                  I will admit that I am a 'hobby' programmer, and it has taken me a good few years to get to the limited programming capability I have. Due to the lack of programming finesse I have, I tend to err of the side of brute ignorance & force to get things done. (The programming equivalent of using a sledgehammer for all jobs requiring a hammer.)

                                  Regards,

                                  Richard.

                                  Edited to kill a rogue emoticon

                                  Edited By richardandtracy on 15/09/2017 11:00:27

                                  #317139
                                  SillyOldDuffer
                                  Moderator
                                    @sillyoldduffer
                                    Posted by richardandtracy on 15/09/2017 10:59:35:

                                    Dave,

                                    There is a function applied to each form (read 'Window' ) in the VCL library, and it's the 'Refresh()' method built into the TForm object, which I call up every 10 pdf pages or so. Amongst other things it sends Windows a WM_PAINT message to trigger a redraw and halts the process to flush the message buffer. But somehow Windows forgets this.

                                    I will admit that I am a 'hobby' programmer, and it has taken me a good few years to get to the limited programming capability I have. Due to the lack of programming finesse I have, I tend to err of the side of brute ignorance & force to get things done. (The programming equivalent of using a sledgehammer for all jobs requiring a hammer.)

                                    Regards,

                                    Richard.

                                    Edited to kill a rogue emoticon

                                    Edited By richardandtracy on 15/09/2017 11:00:27

                                    You are too modest Richard!

                                    I've not done much GUI programming and most of it was simple. Although I've delved into GDI, OWL, Qt and others my training was in X-Windows. I know what I know is superficial.

                                    Anyway, there's a real problem with using any of the Frameworks, which is seeing the wood for the trees. Deciding what to use may not be at all obvious until you're thoroughly familiar with it and that's hard work cubed. Reasonable to expect that refresh() and WM_PAINT would do the job; I guess they don't because they're output activities whilst Windows still 'knows' that input events are being ignored.

                                    Dave

                                    #317173
                                    richardandtracy
                                    Participant
                                      @richardandtracy

                                      New version can now be downloaded via the same link.

                                      Regards

                                      Richard

                                      #317186
                                      Thor 🇳🇴
                                      Participant
                                        @thor

                                        Thanks Richard, I have downloaded the new version and will test it.

                                        Thor

                                        #317220
                                        Thor 🇳🇴
                                        Participant
                                          @thor

                                          Hi Richard,

                                          Thanks for posting a new version. I have done a bit more testing, and still get trouble when using PDF output, the CSV format seems to work Ok.

                                          Thor

                                          #317495
                                          richardandtracy
                                          Participant
                                            @richardandtracy

                                            For some reason I can't yet identify, the pdf output does not always work. I shall work on it, but as I have no idea of what the cause may be, the solution may be difficult to come by. So, in the mean time, can I suggest that you try the pdf output and if it doesn't work, resort to the csv output.

                                            Regards,

                                            Richard.

                                            #317497
                                            Ady1
                                            Participant
                                              @ady1

                                              May help?

                                              Sometimes PDF is configured to open automatically in HTML. Sometimes it is blocked completely and needs a manual over ride from the computer user to create/open PDF in a non html environment

                                              #317506
                                              richardandtracy
                                              Participant
                                                @richardandtracy

                                                I had an idea this morning about the cause, and think it may be related to pdf page location co-ordinates being converted to use decimal commas. I am hoping Thor will respond to a PM so I can check whether this may be the cause of one/all of the problems.

                                                I am not sure that HTML opening is likely to be the problem as the pdf file with the problems opens (if it opens at all) just shows blank pages. However, there is such diversity in setups that I am increasing less sure about anything!

                                                Regards,

                                                Richard

                                                #317511
                                                Thor 🇳🇴
                                                Participant
                                                  @thor

                                                  Hi Richard,

                                                  Thanks for taking time to iron out the PDF problems. I will try and find one of the failed PDF files and e-mail to you.

                                                  Ady, the problem isn't that PDFs are set to open automatically in a browser. I tried several PDF readers, the only one that gave any other output than a blank screen  was FireFox.

                                                  Thor

                                                  Edited By Thor on 18/09/2017 11:34:36

                                                  #317514
                                                  SillyOldDuffer
                                                  Moderator
                                                    @sillyoldduffer

                                                    Wild suggestion: Richard's code sets the font by name ('Helvetica' ) without checking that it actually exists. (It should but…)

                                                    I don't know what the PDF library does if it can't find a font, but I suppose writing a document full blank glyphs is a possibility. (I've never understood how PDF files handle fonts; whether they load a copy of the font into the document, or just provide a link and expect the PDF reader to find it on the other system.)

                                                    Might be worth initialising the PDFObject without setting a font at all. With luck a portable default will be used.

                                                    Dave

                                                    Edit: I hate automatic smileys!!!

                                                    Edited By SillyOldDuffer on 18/09/2017 11:46:34

                                                    #317517
                                                    richardandtracy
                                                    Participant
                                                      @richardandtracy

                                                      There are four fonts that are 'built in' with the PDF spec, Helvetica, Times, Courier and ZapfDingbats. On Apple systems, they exist, I think, by virtue of being loaded with the OS. On Windows there are auto substitutions of Arial, Times New Roman, Courier New and Symbol, which are all loaded by the OS. The four fonts are part of the core PDF definition – and I use them for simplicity, programming in the font embedding is interesting, but getting the information to embed the fonts from Windows is a non-trivial exercise which I'd prefer to avoid.

                                                      A font can be embedded in the pdf file in the manner described below.

                                                      Each character is stored as an object in the file. It is stored as an array of co-ordinates marking the perimeter of the object, this is done clockwise. Any 'holes' in the filled in character (eg for 'A' etc) are another group of co-ordinates where the perimeter is drawn anti-clockwise. The co-ordinates are all in points from the character origin, which is on the line and permits the correct character spacing from the previous character. The character is defined at 1 point font size. There is another co-ordinate for the 'End of character' point.

                                                      Each font is defined as a series of objects and they are mapped onto letters. The font need not be complete, just cover every letter that is used. The font is given an external designation (eg 'Arial' ) , and an internal name (eg 'Font1' )

                                                      When text is used in a pdf file you get an uncompressed entry in the 'Page Object Contents Stream' similar to that below (anything after a % character is a comment that the reader ignores):

                                                      'BT' %Begin Text
                                                      /Font1 10 Tf %Use Font 'Font1' which has already been defined, and scale it up by a factor of 10 to get 10 point.
                                                      1 0 0 1 17.008 814.869 Tm %Rotate text using 2×2 text rotation matrix 1 0 0 1 [no rotation] and put the first character's origin at 17.008,814.869 points (1point = 1/72" ) from the bottom left corner of the page.
                                                      0.00 0.00 0.00 rg %Colour black, 0.00 red, 0.00 green, 0.00 blue from a range 0.00-1.00
                                                      (Pitch (mm)) Tj %draw the text and fill it in. The text to be drawn with Font1 is 'Pitch (mm)'. Outline fonts are possible by changing the 'Tj' to 'TJ' I think (can't remember at the moment).

                                                      Then at the end of any group of text there is an

                                                      'ET'

                                                      before any line drawing can occur. There must be an 'ET' before the end of each page that has a 'BT'.

                                                      Regards,

                                                      Richard

                                                      Edited to kill rogue emoticons

                                                      Edited By richardandtracy on 18/09/2017 12:45:08

                                                    Viewing 25 posts - 1 through 25 (of 38 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

                                                    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