-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
327 lines (256 loc) · 8.71 KB
/
Copy pathmodels.py
File metadata and controls
327 lines (256 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Literal
import numpy as np
ClockwiseEffect = Literal["raise", "lower"]
Viewpoint = Literal["above", "below"]
EdgeReference = Literal["top", "bottom"]
ModelSource = Literal["baseline", "physical"]
MaterialChoiceKind = Literal["library", "custom"]
ConfidenceLevel = Literal["high", "medium", "low"]
@dataclass(slots=True)
class BedConfig:
width_mm: float
height_mm: float
@dataclass(slots=True)
class ScrewMeasurement:
name: str
left_mm: float
y_measure_mm: float
@property
def top_mm(self) -> float:
return self.y_measure_mm
@dataclass(slots=True)
class ScrewTurnConfig:
pitch_mm_per_turn: float
clockwise_effect: ClockwiseEffect = "raise"
viewpoint: Viewpoint = "above"
fraction_denominator: int = 16
hold_threshold_mm: float = 0.01
@dataclass(slots=True)
class CoordinateConvention:
screw_y_reference_edge: EdgeReference = "top"
display_front_edge: EdgeReference = "top"
@dataclass(slots=True)
class MaterialResponseOverride:
self_multiplier: float = 1.0
neighbor_multiplier: float = 1.0
decay_multiplier: float = 1.0
step_multiplier: float = 1.0
self_temp_coeff: float = 0.0
neighbor_temp_coeff: float = 0.0
step_temp_coeff: float = 0.0
absolute_cap_turns: float | None = None
@dataclass(slots=True)
class MaterialChoice:
kind: MaterialChoiceKind = "library"
library_key: str = "other"
label: str = ""
custom_response: MaterialResponseOverride | None = None
@dataclass(slots=True)
class BedAssemblyConfig:
plate_material: MaterialChoice = field(default_factory=MaterialChoice)
surface_material: MaterialChoice = field(default_factory=lambda: MaterialChoice(library_key="none", label="None"))
@dataclass(slots=True)
class SupportAssemblyConfig:
mount_type: str = ""
support_material: MaterialChoice = field(default_factory=MaterialChoice)
support_stack_height_mm: float = 12.0
@dataclass(slots=True)
class FastenerConfig:
screw_material: MaterialChoice = field(default_factory=MaterialChoice)
@dataclass(slots=True)
class RawMechanicalModelConfig:
enabled: bool = True
preset_name: str = "other"
self_gain: float = 0.85
neighbor_gain: float = 0.12
decay_length_mm: float = 140.0
max_step_turns: float = 0.0625
regularization_lambda: float = 1e-5
use_advanced_override: bool = False
MechanicalModelConfig = RawMechanicalModelConfig
@dataclass(slots=True)
class EnvironmentMetadata:
bed_assembly: BedAssemblyConfig = field(default_factory=BedAssemblyConfig)
support_assembly: SupportAssemblyConfig = field(default_factory=SupportAssemblyConfig)
fastener: FastenerConfig = field(default_factory=FastenerConfig)
bed_temperature_c: float | None = None
chamber_temperature_c: float | None = None
@property
def bed_material(self) -> str:
return self.bed_assembly.plate_material.label or self.bed_assembly.plate_material.library_key
@property
def mount_type(self) -> str:
return self.support_assembly.mount_type
@property
def standoff_material(self) -> str:
return self.support_assembly.support_material.label or self.support_assembly.support_material.library_key
@property
def screw_material(self) -> str:
return self.fastener.screw_material.label or self.fastener.screw_material.library_key
@dataclass(slots=True)
class MeshGrid:
z_values: list[list[float]]
x_min_mm: float
x_max_mm: float
y_min_mm: float
y_max_mm: float
top_row_is_y_max: bool = True
@property
def row_count(self) -> int:
return len(self.z_values)
@property
def column_count(self) -> int:
return len(self.z_values[0]) if self.z_values else 0
def x_coordinates(self) -> np.ndarray:
return np.linspace(self.x_min_mm, self.x_max_mm, self.column_count, dtype=float)
def y_coordinates(self) -> np.ndarray:
ascending = np.linspace(self.y_min_mm, self.y_max_mm, self.row_count, dtype=float)
return ascending[::-1] if self.top_row_is_y_max else ascending
def z_array(self) -> np.ndarray:
return np.asarray(self.z_values, dtype=float)
def contains_point(self, x_mm: float, y_mm: float) -> bool:
return self.x_min_mm <= x_mm <= self.x_max_mm and self.y_min_mm <= y_mm <= self.y_max_mm
@dataclass(slots=True)
class CalibrationTrial:
name: str
before_mesh: MeshGrid
after_mesh: MeshGrid
applied_turns: dict[str, float]
bed: BedConfig
screws: list[ScrewMeasurement]
turn_config: ScrewTurnConfig
reference_screw_name: str
coordinate_convention: CoordinateConvention = field(default_factory=CoordinateConvention)
metadata: EnvironmentMetadata = field(default_factory=EnvironmentMetadata)
@dataclass(slots=True)
class ProjectData:
bed: BedConfig
screws: list[ScrewMeasurement]
turn_config: ScrewTurnConfig
reference_screw_name: str
coordinate_convention: CoordinateConvention = field(default_factory=CoordinateConvention)
mechanical_model: RawMechanicalModelConfig = field(default_factory=RawMechanicalModelConfig)
metadata: EnvironmentMetadata = field(default_factory=EnvironmentMetadata)
mesh: MeshGrid | None = None
calibration_trials: list[CalibrationTrial] = field(default_factory=list)
schema_version: int = 4
upgraded_from_schema: int | None = field(default=None, repr=False, compare=False)
@dataclass(slots=True)
class GeometryScrewStatus:
name: str
left_mm: float
y_measure_mm: float
x_mm: float
y_mm: float
inside_bed: bool
inside_mesh: bool | None = None
duplicate_with: list[str] = field(default_factory=list)
quadrant: str | None = None
@dataclass(slots=True)
class GeometryReport:
screw_statuses: list[GeometryScrewStatus]
blocking_errors: list[str] = field(default_factory=list)
warnings: list[str] = field(default_factory=list)
@dataclass(slots=True)
class ProbeAreaSummary:
probe_width_mm: float
probe_height_mm: float
coverage_ratio: float
warning_level: Literal["none", "partial", "strong"]
@dataclass(slots=True)
class PlaneFit:
a: float
b: float
c: float
@dataclass(slots=True)
class ResidualStats:
max_abs_mm: float
rms_mm: float
peak_to_valley_mm: float
plane_slope_magnitude: float
@dataclass(slots=True)
class QuadraticFit:
a_x2: float
b_y2: float
c_xy: float
d_x: float
e_y: float
f_constant: float
r_squared: float
@dataclass(slots=True)
class WarpReport:
enabled: bool
classification: str
confidence: str
summary: str
fit: QuadraticFit | None = None
@dataclass(slots=True)
class ScrewInstruction:
name: str
x_mm: float
y_mm: float
plane_height_mm: float
delta_height_mm: float
action: str
direction: str
signed_turns: float
decimal_turns: float
rounded_turns: str
source_model: ModelSource = "baseline"
expected_achieved_delta_mm: float | None = None
local_residual_mm: float | None = None
notes: list[str] = field(default_factory=list)
@dataclass(slots=True)
class TurnStep:
pass_index: int
screw_name: str
action: str
rotation: str
turns_this_pass: float
remaining_after_pass: float
note: str | None = None
@dataclass(slots=True)
class TurnPlan:
source_model: ModelSource
total_target_turns: dict[str, float]
first_pass_steps: list[TurnStep]
requires_remesh_after_pass: bool
warnings: list[str] = field(default_factory=list)
@dataclass(slots=True)
class MechanicalConfidence:
score: float
level: ConfidenceLevel
reasons: list[str] = field(default_factory=list)
@dataclass(slots=True)
class EffectiveMechanicalModel:
enabled: bool = True
preset_name: str = "other"
self_gain: float = 0.85
neighbor_gain: float = 0.12
decay_length_mm: float = 140.0
max_step_turns: float = 0.0625
regularization_lambda: float = 1e-5
thermal_index: float = 0.0
reasons: list[str] = field(default_factory=list)
@dataclass(slots=True)
class AnalysisResult:
plane_fit: PlaneFit
residual_stats: ResidualStats
warp_report: WarpReport
baseline_instructions: list[ScrewInstruction]
physical_instructions: list[ScrewInstruction]
baseline_turn_plan: TurnPlan
physical_turn_plan: TurnPlan | None
geometry_report: GeometryReport
probe_area_summary: ProbeAreaSummary
effective_mechanical_model: EffectiveMechanicalModel | None
mechanical_confidence: MechanicalConfidence | None
warnings: list[str]
divergence_warnings: list[str]
plane_surface: list[list[float]]
residual_surface: list[list[float]]
@property
def instructions(self) -> list[ScrewInstruction]:
return self.baseline_instructions