In the following, we explain how a thread spec (i.e., an entry in THREAD_TABLE.scad) is created. First, we will explain the basics of threads and how they are specified in the norms. Then, we will elaborate on how to translate those into threadlib thread specs.
As an example, we use British Standard Pipe parallel (BSPP) thread (see drawing below). The black curve shows the parting line between internal and external thread. In an ideal world, both threads are created according to the parting line. For BSP thread it is based on a fundamental triangle with a 55-degree angle rounded to a radius r.
Reality is a bit more complicated: If one of the threads deviates only a little in the wrong direction, the threads collide. Therefore, the pitch radius r_pitch (radius where distance between falling and rising edges is exactly P/2) of the external thread has to be reduced a little bit (and vice versa for the internal thread). Also, major- and minor radii are adjusted so that the real thread is guaranteed to remain on its own side of the theoretical parting line.
Of course, it is not ok to introduce arbitrarily large allowances: The norm (BS EN ISO 228-1: 2003 in this case) gives the necessary constraints. Quoting Maryland Metrics thread data charts for BSP thread (which used to be [here](http://mdmetric.com/tech/thddat7.htm)):
We want to approximate the thread profile by straight-line segments as shown in the sketch in red and blue (internal and external thread, respectively).
To explain the choice of r_major and r_minor for both external and internal threads simultaneously, we use the terms r_crest and r_valley. r_crest is the major/minor radius (external/internal) and r_valley is the minor/major radius (external/internal). The norm does not give limits for r_valley. But threadlib requires that the thread profile covers *less* than 1 pitch of thread. Therefore, we arbitrarily choose a small but finite width of "valley floor" that leaves ample clearance to the parting line. For r_crest, we to take into account
The former is simple: We aim for the center. The latter requires a little math: We want our piecewise linear profile to remain on one side of the (true) BSP profile. Therefore, our crest radius has to be equal to the radius where the straight rising edge of the BSP profile touches the circle of the rounding (see sketch at the top of this page).
To get the threads into threadlib, we do the following:
- Tabulate specs as given in norm => design/newthreads.csv
- Write design/newthreads.awk => translates design/newthreads.csv to tabular threadlib specs (see next step).
- Add instructions to Makefile:
`cat design/newthreads.csv | awk -f design/newthreads.awk >> design/THREAD_TABLE.csv` Now, `make` will automatically run the script.
- design/autogenerate.awk will translate the resulting THREAD_TABLE.csv into the final THREAD_TABLE.scad (same as the .csv but with added quoting and bracketing). This script is already there, you should not need to modify it.
Furthermore, we should extend tests/test_table.awk to test our newly created threads. The very minimum is to add a test for the thread angles. Perform the tests by running `make test` in the top-level directory or `make` inside the tests subdirectory. If it prints "TESTS SUCCESSFUL" you are probably fine. Note: If you have a thread spec that is not tested at all, the tests will fail, too.