diff --git a/.vscode/launch.json b/.vscode/launch.json index e81cbac..ee74907 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,24 +3,22 @@ "configurations": [ { "name": "Python: Current File", - "type": "python", + "type": "debugpy", "request": "launch", "program": "/${file}", "console": "integratedTerminal" }, { "name": "Python: Module", - "type": "python", + "type": "debugpy", "request": "launch", "module": "module.name", "console": "integratedTerminal" }, { "name": "Python: Attach", - "type": "python", + "type": "debugpy", "request": "attach", - "port": 3000, - "host": "localhost" } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index c1e1aef..43280d8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,7 @@ "editor.formatOnType": true, "editor.defaultFormatter": "ms-python.black-formatter", "editor.codeActionsOnSave": { - "source.organizeImports": true + "source.organizeImports": "explicit" }, "editor.insertSpaces": true, "editor.tabSize": 4 diff --git a/README.md b/README.md index ad32028..296cfca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # machinistcalc MachinistCalc: a Python3 Machinist Calculator for doing plenty of machining and fabricating calculations. + +# Features + +- Bolt Circle calculator +- Lathe Speed & Feed calculator +- Milling Speed & Feed calculator +- Punch Press / Punch tonnage calculator +- Sheet Metal Usage calculator +- Gear calculator diff --git a/app.py b/app.py index ef12209..bb17abf 100644 --- a/app.py +++ b/app.py @@ -3,10 +3,8 @@ from app.lathecalc import lathe_calc from app.punchtonnage import punch_tonnage from app.sheetmetalcalc import sheetmetal_calc -from app.speedfeed import (calculate_afpt, calculate_feed, calculate_hp, - calculate_ipt, calculate_mrr, calculate_sfm, - calculate_speed, speed_feed) - +from app.lathecalc import lathe_calc +from app.millingcalc import milling_calc def menu(): while True: @@ -22,31 +20,21 @@ def menu(): choice = input("Enter your choice: ") if choice == "1": - # Call the bend calculator function from bendcalc.py bend_calc() elif choice == "2": - # Call the lathe calculator function from lathecalc.py lathe_calc() elif choice == "3": - # Call the lathe calculator function from lathecalc.py sheetmetal_calc() elif choice == "4": - # Call the speed and feed calculator function from speedfeed.py - calculate_afpt() - calculate_feed() - calculate_hp() - calculate_ipt() - calculate_mrr() - calculate_speed() - calculate_sfm() - speed_feed() - # Add other functions as needed + milling_calc() elif choice == "5": - # Call the lathe calculator function from lathecalc.py punch_tonnage() elif choice == "6": - # Call the lathe calculator function from lathecalc.py - bolt_circle() + diameter = float(input("Enter the diameter of the bolt circle: ")) + num_holes = int(input("Enter the number of holes: ")) + coordinates = bolt_circle(diameter, num_holes) + for i, (x, y) in enumerate(coordinates, start=1): + print(f"Hole {i}: ({x:.2f}, {y:.2f})") elif choice == "7": print("Quitting the application") break @@ -55,3 +43,4 @@ def menu(): if __name__ == "__main__": menu() + diff --git a/app/__init__.py b/app/__init__.py index 2327cfe..59b4c87 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,9 +1,6 @@ -# __init__.py - -# Importing modules from the package from app.bendcalc import bend_calc from app.lathecalc import lathe_calc +from app.millingcalc import milling_calc from app.punchtonnage import punch_tonnage from app.sheetmetalcalc import sheetmetal_calc -from app.speedfeed import speed_feed from app.boltcircle import bolt_circle diff --git a/app/__pycache__/__init__.cpython-37.pyc b/app/__pycache__/__init__.cpython-37.pyc index 93d85c9..e6eef6f 100644 Binary files a/app/__pycache__/__init__.cpython-37.pyc and b/app/__pycache__/__init__.cpython-37.pyc differ diff --git a/app/boltcircle.py b/app/boltcircle.py index aef3e8a..54642c0 100644 --- a/app/boltcircle.py +++ b/app/boltcircle.py @@ -9,10 +9,3 @@ def bolt_circle(diameter, num_holes): coordinates.append((x, y)) return coordinates -# Example usage -if __name__ == "__main__": - diameter = float(input("Enter the diameter of the bolt circle: ")) # Accept user input for the diameter - num_holes = int(input("Enter the number of holes: ")) # Accept user input for the number of holes - coordinates = bolt_circle(diameter, num_holes) - for i, (x, y) in enumerate(coordinates, start=1): - print(f"Hole {i}: ({x:.2f}, {y:.2f})") diff --git a/app/lathecalc.py b/app/lathecalc.py index 585c740..155a776 100644 --- a/app/lathecalc.py +++ b/app/lathecalc.py @@ -1,21 +1,54 @@ import math +from typing import Tuple +def lathe_calc(): + # Prompt the user for inputs + rpm = float(input("Enter the RPM: ")) + ipr = float(input("Enter the inches per revolution: ")) + diameter = float(input("Enter the workpiece diameter before machining: ")) + feed_rate = float(input("Enter the feed rate: ")) + depth_of_cut = float(input("Enter the depth of cut: ")) + metal_removal_rate = float(input("Enter the metal removal rate: ")) + spindle_rpm = input("Enter the available spindle rpm range: ") + surface_finish_unit = input("Enter the unit, UM or RA, for surface finish (µm or Ra): ").upper() + tooling_material = input("Enter the tooling material: ") + calculated_feed_per_rev = calculate_feed_per_rev(ipr, rpm) -def lathe_calc(diameter, surface_speed, feed_rate, number_of_teeth): - # Calculate spindle speed - spindle_speed = (surface_speed * 12) / (math.pi * diameter) + # Calculate sfpm + sfpm = calculate_sfpm(diameter, rpm) - # Calculate cutting speed - cutting_speed = spindle_speed * math.pi * diameter + # Prompt for surface finish value based on user preference + if surface_finish_unit == "UM": + surface_finish = float(input("Enter the required surface finish in micrometers (µm): ")) + print(f"Using micrometers (µm) for surface finish.") + elif surface_finish_unit == "RA": + surface_finish = float(input("Enter the required surface finish (Ra): ")) + print(f"Using Roughness Average (Ra) for surface finish.") + else: + print(f"Invalid unit entered. Please enter 'µm' or 'Ra'.") + # Handle the case where the user enters an invalid unit - # Calculate feed rate - feed_rate = feed_rate * spindle_speed * number_of_teeth + # Calculate ipm (if needed) + ipm = calculate_ipm(sfpm, calculated_feed_per_rev) - # Calculate chip load - chip_load = feed_rate / (number_of_teeth * spindle_speed) + # Print the results + print(f"Calculated feed rate: {feed_rate}") + print(f"Calculated spindle RPM: {spindle_rpm}") + print(f"Calculated material removal rate: {metal_removal_rate}") + print(f"Calculated Inches per Revolution: {ipr:.2f}") + print(f"Calculated Surface Feet per Minute: {sfpm:.2f}") + print(f"Calculated Inches per Minute: {ipm:.2f}") # Print ipm only if calculated + print(f"Calculated Feed per Revolution: {calculated_feed_per_rev:.2f}") - # Print results - print("Spindle speed: {:.2f} RPM".format(spindle_speed)) - print("Cutting speed: {:.2f} feet per minute".format(cutting_speed)) - print("Feed rate: {:.4f} inches per minute".format(feed_rate)) - print("Chip load: {:.4f} inches per tooth".format(chip_load)) + +def calculate_sfpm(diameter, rpm): + sfpm = (diameter * math.pi * rpm) / 12 + return sfpm + +def calculate_ipm(sfpm, feed_per_rev): + ipm = sfpm * feed_per_rev + return ipm + +def calculate_feed_per_rev(ipr, rpm): + feed_per_rev = ipr * rpm + return feed_per_rev diff --git a/app/lathespeed.py b/app/lathespeed.py deleted file mode 100644 index 06d5080..0000000 --- a/app/lathespeed.py +++ /dev/null @@ -1,28 +0,0 @@ -import math -from typing import Tuple - - -def calculate_sfpm(diameter, rpm): - sfpm = (diameter * math.pi * rpm) / 12 - return sfpm - -def calculate_ipm(sfpm, feed_per_rev): - ipm = sfpm * feed_per_rev - return ipm - -def calculate_feed_per_rev(ipr, rpm): - feed_per_rev = ipr * rpm - return feed_per_rev - -def lathe_speed_feed_calc(): - diameter = float(input("Enter the diameter: ")) - rpm = float(input("Enter the RPM: ")) - ipr = float(input("Enter the inches per revolution: ")) - - sfpm = calculate_sfpm(diameter, rpm) - ipm = calculate_ipm(sfpm, ipr) - feed_per_rev = calculate_feed_per_rev(ipr, rpm) - - print(f"Surface Feet per Minute: {sfpm:.2f}") - print(f"Inches per Minute: {ipm:.2f}") - print(f"Feed per Revolution: {feed_per_rev:.2f}") diff --git a/app/millingcalc.py b/app/millingcalc.py new file mode 100644 index 0000000..8bc093d --- /dev/null +++ b/app/millingcalc.py @@ -0,0 +1,2 @@ +def milling_calc(): + pass diff --git a/app/speedfeed.py b/app/speedfeed.py deleted file mode 100644 index 67fd126..0000000 --- a/app/speedfeed.py +++ /dev/null @@ -1,104 +0,0 @@ -import math -from typing import Tuple - - -def get_input(prompt): - while True: - try: - value = float(input(prompt)) - return value - except ValueError: - print("Invalid input. Please enter a number.") - -def calculate_speed(rpm=None, sfm=None, d=None): - if rpm is None or sfm is None or d is None: - # handle missing parameters - return None - speed = (rpm * sfm) / (3.82 * d) - return speed - -def calculate_sfm(rpm=None, d=None): - if rpm is None or d is None: - return None - sfm = (3.82 * rpm * d) / 12 - return sfm - -def calculate_feed(rpm=None, fpt=None, z=None): - if rpm is None or fpt is None or z is None: - return None - feed = rpm * fpt * z - return feed - -def calculate_ipt(ipm=None, rpm=None, z=None): - if ipm is None or rpm is None or z is None: - return None - ipt = (ipm * 12) / (rpm * z) - return ipt - -def calculate_mrr(ipm=None, woc=None, doc=None): - if ipm is None or woc is None or doc is None: - return None - mrr = ipm * woc * doc - return mrr - -def calculate_afpt(ipm=None, d=None, woc=None): - if ipm is None or d is None or woc is None: - return None - afpt = (ipm * 12) / (d * woc) - return afpt - -def calculate_hp(mrr=None, mf=None): - if mrr is None or mf is None: - return None - hp = (mrr * mf) / 33000 - return hp - -def speed_feed(): - rpm = None - ipm = None - sfm = None - d = 0.0 # Initialize d to a default value - - while rpm is None or ipm is None or sfm is None: - rpm_input = input("Enter RPM (leave blank if unknown): ") - ipm_input = input("Enter IPM (leave blank if unknown): ") - sfm_input = input("Enter SFM (leave blank if unknown): ") - - if rpm_input: - rpm = float(rpm_input) - if ipm_input: - ipm = float(ipm_input) - if sfm_input: - sfm = float(sfm_input) - - d = get_input("Enter D: ") - - rpm = calculate_speed(rpm, sfm, d) - sfm = calculate_sfm(rpm, d) - - fpt = get_input("Enter FPT: ") - z = get_input("Enter Z: ") - woc = get_input("Enter WOC: ") - doc = get_input("Enter DOC: ") - - ipm = calculate_feed(rpm, fpt, z) - ipt = calculate_ipt(ipm, rpm, z) - mrr = calculate_mrr(ipm, woc, doc) - afpt = calculate_afpt(ipm, d, woc) - - mf_values = { - "steel": 1, - "gray iron": 0.65, - "aluminum": 0.3 - } - - mf = get_input("Enter mf value (steel=1, gray iron=0.65, aluminum=0.3): ") - hp = calculate_hp(mrr, mf) - - print(f"RPM: {rpm:.5f}") - print(f"IPM: {ipm:.5f}") - print(f"SFM: {sfm:.5f}") - print(f"IPT: {ipt:.5f}") - print(f"MRR: {mrr:.5f}") - print(f"AFPT: {afpt:.5f}") - print(f"HP: {hp:.5f}") diff --git a/ask.txt b/ask.txt index 1dd927b..fdeab26 100644 --- a/ask.txt +++ b/ask.txt @@ -1,4 +1,4 @@ -I am creating a python3 application for Shortwave Radio listeners and Amateur radio operators called RadioLogger. I am using +I am creating a python3 application for pyton3 3.7.3 diff --git a/requirements.txt b/requirements.txt index b13cfbe..a75861b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ -black -flake8 -pytest -pylint \ No newline at end of file +black +flake8 +pytest +pylint +pycache +pyright diff --git a/tests/test.py b/tests/test.py index 528368e..b448d18 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,12 +1,12 @@ -import pytest -from machinistcalc.app.speedfeed import calculate_speed, calculate_feed - -def test_calculate_speed(): - result = calculate_speed(1000, 2) - expected = 500 - assert result == expected - -def test_calculate_feed(): - result = calculate_feed(1000, 2) - expected = 2000 - assert result == expected \ No newline at end of file +import pytest +from app.lathecalc import calculate_sfpm, calculate_feed, calculate_speed + +def test_calculate_speed(): + result = calculate_speed(1000, 2) + expected = 500 + assert result == expected + +def test_calculate_feed(): + result = calculate_feed(1000, 2) + expected = 2000 + assert result == expected