CauldronDevelopmentLLC / CAMotics

Open-Source Simulation & Computer Aided Machining - A 3-axis CNC GCode simulator
Other
602 stars 138 forks source link

Auto-detect workpiece height is broken if toolPath.Z > 0 #355

Closed thekroko closed 2 years ago

thekroko commented 2 years ago

The auto-detect workpiece logic always results in a bounding box with a height of z=2.1mm (latest Windows build), which - looking at the code - seems to be the default min if boundary.height < 2mm (2mm + 5%).

From a quick glance, it looks like the clamping code in Workpiece.cpp might not be able to handle the situation where the workpiece/cutting happens at a Z>0, and the wasteboard is at Z=0?

 // Start from z = 0
 Vector3D bMin = bounds.getMin();
 Vector3D bMax = bounds.getMax();
 bounds = Rectangle3D(bMin, Vector3D(bMax.x(), bMax.y(), 0));

Example gcode snippet that fails:

G21 G90
G0 Z30.0
T101 M6 (Part1\3DSurface1\3.18mm 1/8" 2F End Mill\3.175)
( 3DSurface1 )
G17
M3 S1000
G0 X87.7475 Y87.7475
G0 Z21.0 
G1 F700.0 Z20.0   <<< Cutting starts at Z=20, working downwards. Wasteboard is at Z=0
G1 F1700.0 Y88.2525 Z19.9934
G1 X171.2525 Z18.9
G1 Y87.7475 Z18.8934
G1 X87.7475 Z17.8
G1 Y88.2525
G1 X171.2525
G1 Y87.7475
[...]

Maybe this code should be changed to only raise bMax.z to 0 if bMax.z < 0?

jcoffland commented 2 years ago

See my above commit. The reason for assuming z max is zero is that many GCodes move down with a cutting move. Start from the highest z cut point makes for poor simulations in many cases. However, you are right about GCodes that expect the workpiece to be above zero. Thanks!