Skip to content

Commit

Permalink
Measure (#16)
Browse files Browse the repository at this point in the history
* pass mysql

* use new path

* update gcode&db

* update tests
  • Loading branch information
yuichiroaoki authored Oct 22, 2023
1 parent 548f366 commit c2ad2df
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 116 deletions.
66 changes: 0 additions & 66 deletions cnceye/arc.py

This file was deleted.

16 changes: 9 additions & 7 deletions cnceye/edge/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def find_edge(filepath: str, minimal_diff: float = 5.0):
previous_distance = distance


def find_edges(minimal_diff: float = 5.0, mysql_config=MYSQL_CONFIG):
def find_edges(mysql_config: dict = MYSQL_CONFIG, minimal_diff: float = 5.0):
cnx = mysql.connector.connect(**mysql_config, database="coord")
cursor = cnx.cursor()
query = "SELECT * FROM sensor"
Expand Down Expand Up @@ -106,7 +106,7 @@ def find_lines(filepath: str, edge_count: int, minimal_diff: float = 5.0):
def get_edge_data(mysql_config=MYSQL_CONFIG):
cnx = mysql.connector.connect(**mysql_config, database="coord")
cursor = cnx.cursor()
query = "SELECT id,side_id,x,y,z FROM edge"
query = "SELECT id,x,y,z FROM edge"
cursor.execute(query)
edges = cursor.fetchall()
cursor.close()
Expand All @@ -116,7 +116,7 @@ def get_edge_data(mysql_config=MYSQL_CONFIG):

def identify_close_edge(edges, measured_edges, distance_threshold=2.5):
update_list = []
for id, side_id, x, y, z in edges:
for id, x, y, z in edges:
min_distance = 999999.0
data_with_min_distance = []
for measured_edge in measured_edges:
Expand Down Expand Up @@ -146,11 +146,13 @@ def add_measured_edge_coord(edge_list: list, mysql_config=MYSQL_CONFIG):
cnx.close()


def process_edges():
def process_edges(mysql_config: dict, minimal_diff: float = 5.0) -> int:
"""
Identify the edges from the sensor data and add the coordinates to the database
"""
measured_edges = find_edges()
edge_data = get_edge_data()
measured_edges = find_edges(mysql_config, minimal_diff)
edge_data = get_edge_data(mysql_config)
update_list = identify_close_edge(edge_data, measured_edges)
add_measured_edge_coord(update_list)
add_measured_edge_coord(update_list, mysql_config)
edge_count = len(edge_data)
return edge_count
6 changes: 6 additions & 0 deletions mysql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ CREATE TABLE IF NOT EXISTS `side` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `pair` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `sensor` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`x` FLOAT NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cnceye"
version = "0.4.0"
version = "0.4.1"
description = "CMM python library"
license = "MIT"
authors = ["yuichiroaoki <[email protected]>"]
Expand Down
Binary file modified tests/fixtures/db/listener.db
Binary file not shown.
80 changes: 63 additions & 17 deletions tests/fixtures/gcode/edge.gcode
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
%
O0001
G1 X-52.5 Y0.0 Z10.0 F600
G1 X-47.5 Y0.0 Z10.0 F300
G1 X-27.5 Y38.0 Z10.0 F600
G1 X-22.5 Y38.0 Z10.0 F300
G1 X0.0 Y-67.5 Z10.0 F600
G1 X0.0 Y-62.5 Z10.0 F300
G1 X0.0 Y20.5 Z10.0 F600
G1 X0.0 Y25.5 Z10.0 F300
G1 X0.0 Y50.5 Z10.0 F600
G1 X0.0 Y55.5 Z10.0 F300
G1 X0.0 Y62.5 Z10.0 F600
G1 X0.0 Y67.5 Z10.0 F300
G1 X22.5 Y38.0 Z10.0 F600
G1 X27.5 Y38.0 Z10.0 F300
G1 X47.5 Y0.0 Z10.0 F600
G1 X52.5 Y0.0 Z10.0 F300
O2320
G1 X-52.5 Y-21.667 Z10.0 F600
G1 X-47.5 Y-21.667 Z10.0 F300
G1 X-52.5 Y21.667 Z10.0 F600
G1 X-47.5 Y21.667 Z10.0 F300
G1 X-27.5 Y28.0 Z10.0 F600
G1 X-22.5 Y28.0 Z10.0 F300
G1 X-27.5 Y34.667 Z10.0 F600
G1 X-22.5 Y34.667 Z10.0 F300
G1 X-27.5 Y41.333 Z10.0 F600
G1 X-22.5 Y41.333 Z10.0 F300
G1 X-26.615 Y51.535 Z10.0 F600
G1 X-22.205 Y49.179 Z10.0 F300
G1 X-26.433 Y24.144 Z10.0 F600
G1 X-22.145 Y26.714 Z10.0 F300
G1 X-23.856 Y54.433 Z10.0 F600
G1 X-21.286 Y50.145 Z10.0 F300
G1 X-23.535 Y21.385 Z10.0 F600
G1 X-21.179 Y25.795 Z10.0 F300
G1 X-20.0 Y55.5 Z10.0 F600
G1 X-20.0 Y50.5 Z10.0 F300
G1 X-16.667 Y-67.5 Z10.0 F600
G1 X-16.667 Y-62.5 Z10.0 F300
G1 X-16.667 Y62.5 Z10.0 F600
G1 X-16.667 Y67.5 Z10.0 F300
G1 X-6.667 Y20.5 Z10.0 F600
G1 X-6.667 Y25.5 Z10.0 F300
G1 X-6.667 Y50.5 Z10.0 F600
G1 X-6.667 Y55.5 Z10.0 F300
G1 X-5.75 Y-39.956 Z10.0 F600
G1 X-3.25 Y-35.626 Z10.0 F300
G1 X-5.75 Y-20.038 Z10.0 F600
G1 X-3.25 Y-24.368 Z10.0 F300
G1 X6.667 Y20.5 Z10.0 F600
G1 X6.667 Y25.5 Z10.0 F300
G1 X6.667 Y50.5 Z10.0 F600
G1 X6.667 Y55.5 Z10.0 F300
G1 X11.5 Y-29.997 Z10.0 F600
G1 X6.5 Y-29.997 Z10.0 F300
G1 X16.667 Y-67.5 Z10.0 F600
G1 X16.667 Y-62.5 Z10.0 F300
G1 X16.667 Y62.5 Z10.0 F600
G1 X16.667 Y67.5 Z10.0 F300
G1 X20.0 Y20.5 Z10.0 F600
G1 X20.0 Y25.5 Z10.0 F300
G1 X23.535 Y54.615 Z10.0 F600
G1 X21.179 Y50.205 Z10.0 F300
G1 X23.856 Y21.567 Z10.0 F600
G1 X21.286 Y25.855 Z10.0 F300
G1 X26.433 Y51.856 Z10.0 F600
G1 X22.145 Y49.286 Z10.0 F300
G1 X26.615 Y24.465 Z10.0 F600
G1 X22.205 Y26.821 Z10.0 F300
G1 X22.5 Y34.667 Z10.0 F600
G1 X27.5 Y34.667 Z10.0 F300
G1 X22.5 Y41.333 Z10.0 F600
G1 X27.5 Y41.333 Z10.0 F300
G1 X27.5 Y48.0 Z10.0 F600
G1 X22.5 Y48.0 Z10.0 F300
G1 X47.5 Y-21.667 Z10.0 F600
G1 X52.5 Y-21.667 Z10.0 F300
G1 X47.5 Y21.667 Z10.0 F600
G1 X52.5 Y21.667 Z10.0 F300
M30
%
43 changes: 33 additions & 10 deletions tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def copy_sqlite_db_to_mysql():
def test_find_edges():
copy_sqlite_db_to_mysql()
measured_edges = find.find_edges()
assert len(measured_edges) == 16
assert len(measured_edges) > 32


def test_find_edge():
Expand All @@ -41,20 +41,43 @@ def test_find_edge_from_sqlite():
db_path = "tests/fixtures/db/listener.db"
measured_edges = find.find_edges_from_sqlite(db_path, 100.0)
print(measured_edges)
assert len(measured_edges) == 16
assert len(measured_edges) > 32


def test_add_measured_edge_coord():
measured_edges = find.find_edges()
edge_data = [
(1, 6, -50.0, 0.0, 10.0),
(2, 8, -25.0, 38.0, 10.0),
(3, 2, 0.0, -65.0, 10.0),
(4, 3, 0.0, 23.0, 10.0),
(5, 4, 0.0, 53.0, 10.0),
(6, 1, 0.0, 65.0, 10.0),
(7, 7, 25.0, 38.0, 10.0),
(8, 5, 50.0, 0.0, 10.0),
(1, -50.0, -21.667, 10.0),
(2, -50.0, 21.667, 10.0),
(3, -25.0, 34.667, 10.0),
(4, -25.0, 41.333, 10.0),
(5, -16.667, -65.0, 10.0),
(6, -16.667, 65.0, 10.0),
(7, -6.667, 23.0, 10.0),
(8, -6.667, 53.0, 10.0),
(9, 6.667, 23.0, 10.0),
(10, 6.667, 53.0, 10.0),
(11, 16.667, -65.0, 10.0),
(12, 16.667, 65.0, 10.0),
(13, 25.0, 34.667, 10.0),
(14, 25.0, 41.333, 10.0),
(15, 50.0, -21.667, 10.0),
(16, 50.0, 21.667, 10.0),
(17, -25.0, 28.0, 10.0),
(18, -24.289, 25.429, 10.0),
(19, -22.357, 23.59, 10.0),
(20, 20.0, 23.0, 10.0),
(21, 22.571, 23.711, 10.0),
(22, 24.41, 25.643, 10.0),
(23, 25.0, 48.0, 10.0),
(24, 24.289, 50.571, 10.0),
(25, 22.357, 52.41, 10.0),
(26, -20.0, 53.0, 10.0),
(27, -22.571, 52.289, 10.0),
(28, -24.41, 50.357, 10.0),
(29, 9.0, -29.997, 10.0),
(30, -4.5, -22.203, 10.0),
(31, -4.5, -37.791, 10.0),
]
# edge_data = find.get_edge_data()
update_list = find.identify_close_edge(edge_data, measured_edges)
Expand Down
15 changes: 0 additions & 15 deletions tests/test_gcode.py

This file was deleted.

0 comments on commit c2ad2df

Please sign in to comment.