-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get edges from db * simulation with gcode * add measured data * use predefined data
- Loading branch information
1 parent
6a3a031
commit cc13f1c
Showing
9 changed files
with
238 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "cnceye" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
description = "" | ||
authors = ["yuichiroaoki <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
""" | ||
Simulate the measurement of the 3D model by moving the sensor with G-code | ||
""" | ||
import bpy | ||
from mathutils import Vector | ||
import sqlite3 | ||
import csv | ||
import sys | ||
|
||
# Get the active object (the 3D model) | ||
obj = bpy.data.objects["test-part"] | ||
|
||
ray_direction = Vector((0, 0, -1)) | ||
|
||
# x, y, z, distance | ||
data = [] | ||
|
||
# Ensure the object has a mesh | ||
assert obj.type == "MESH" | ||
|
||
|
||
def distance_to_analog_output(distance: float): | ||
distance = distance * 1000 * 135 # m to mm, distance to analog output | ||
return float(round(distance)) | ||
|
||
|
||
def load_gcode(filepath: str): | ||
with open(filepath, newline="") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=" ") | ||
gcode = list(reader) | ||
gcode.pop(0) | ||
gcode.pop() | ||
return gcode | ||
|
||
|
||
def move_start_point(_start_point, xyz, feedrate: float): | ||
""" | ||
Move the start point to the given direction | ||
_start_point: Vector (x, y, z) in m (relative to obj.location) | ||
xyz: tuple (x, y, z) in mm | ||
feedrate: float (mm/min) | ||
sensor response time is 10ms | ||
""" | ||
one_step_distance = feedrate / 1000 / 60 * 0.01 # m/step | ||
destination = Vector(tuple([x / 1000 for x in xyz])) | ||
total_distance_to_move = (destination - _start_point).length | ||
loop_count = int(total_distance_to_move // one_step_distance) | ||
move_vector = (destination - _start_point) / loop_count | ||
for _ in range(loop_count): | ||
distance = 0.14 # 140 mm | ||
# Calculate the intersection point with the face | ||
(hit, intersection_point, *_) = obj.ray_cast(_start_point, ray_direction) | ||
|
||
if hit: | ||
distance = start_point[2] - intersection_point[2] | ||
|
||
# m to mm and round to 3 decimal places | ||
xyz = [_start_point.x, _start_point.y, _start_point.z] | ||
xyz = [round(x * 1000, 3) for x in xyz] | ||
|
||
data.append([*xyz, distance_to_analog_output(distance)]) | ||
_start_point = _start_point + move_vector | ||
|
||
return destination # _start_point not may not become exactly the destination | ||
|
||
|
||
def row_to_xyz_feedrate(row): | ||
x = float(row[1][1:]) | ||
y = float(row[2][1:]) | ||
z = float(row[3][1:]) | ||
feedrate = float(row[4][1:]) | ||
return (x, y, z, feedrate) | ||
|
||
|
||
# get filepath from arguments | ||
argv = sys.argv | ||
argv = argv[argv.index("--") + 1 :] | ||
assert len(argv) == 1 | ||
gcode = load_gcode(argv[0]) | ||
|
||
# Define the ray's starting point in object space | ||
first_row = gcode[0] | ||
(x, y, z, feedrate) = row_to_xyz_feedrate(first_row) | ||
start_point = Vector((x / 1000, y / 1000, 0.206)) | ||
|
||
|
||
# start_point = Vector(initial_coord) - obj.location | ||
gcode = gcode[1:] | ||
|
||
for row in gcode: | ||
(x, y, z, feedrate) = row_to_xyz_feedrate(row) | ||
z = 206.0 # ignore z | ||
start_point = move_start_point(start_point, (x, y, z), feedrate) | ||
|
||
conn = sqlite3.connect("listener.db") | ||
cur = conn.cursor() | ||
cur.executemany("INSERT INTO coord(x, y, z, distance) VALUES (?, ?, ?, ?)", data) | ||
conn.commit() | ||
conn.close() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 | ||
M30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters