Height Map Tool - Surface Compensation for CNC Milling#798
Open
krudoy wants to merge 3 commits intoSienci-Labs:masterfrom
Open
Height Map Tool - Surface Compensation for CNC Milling#798krudoy wants to merge 3 commits intoSienci-Labs:masterfrom
krudoy wants to merge 3 commits intoSienci-Labs:masterfrom
Conversation
## Summary This PR adds a complete **Height Map** feature to gSender that allows users to compensate for uneven stock surfaces by probing a grid of points and automatically adjusting G-code Z-heights during job execution. ## Features ### Grid Configuration - Define probing area with X/Y min/max bounds - Set grid resolution via spacing or point count - **@grab** button to capture current machine XY position for min bounds - **Use File Bounds** button to automatically set bounds from loaded G-code file ### Probing System - Automated probe routine that visits each grid point sequentially - Safe Z clearance movement between probe points (raise Z first, then move XY, then probe) - Real-time progress tracking with visual feedback - Abort capability during probing - Configurable parameters: - Z clearance height - Probe feed rate - Maximum probe depth ### Height Map Processing - Z-value normalization (lowest probed point becomes Z=0) - Bilinear interpolation for Z adjustments between probe points - Save/load height map files (.map JSON format) - Visual grid representation with color-coded height values ### G-code Transformation - Apply height map compensation to loaded G-code - Segment subdivision for accuracy on long moves - Double-apply warning protection (prevents applying height map twice) - Preview transformed toolpath in secondary visualizer - Export transformed G-code to file - Load transformed G-code directly to main visualizer for execution ## Technical Implementation ### New Files | File | Description | |------|-------------| | src/app/src/features/HeightMap/index.tsx | Main HeightMap component with UI and probing logic | | src/app/src/features/HeightMap/definitions.ts | TypeScript types and interfaces | | src/app/src/features/HeightMap/components/GridVisualizer.tsx | Grid visualization with height colors | | src/app/src/features/HeightMap/components/ToolpathVisualizer.tsx | Toolpath preview component | | src/app/src/features/HeightMap/utils/gcodeTransformer.ts | G-code transformation with Z-offset application | | src/app/src/features/HeightMap/utils/interpolation.ts | Bilinear interpolation and grid calculation | | src/app/src/features/HeightMap/utils/probeRoutine.ts | Probe command generation and height map utilities | ### Modified Files | File | Changes | |------|---------| | src/app/src/react-routes.tsx | Added HeightMap route and ToolCard entry | | src/app/src/store/definitions.ts | Added HeightMapState to store interface | | src/app/src/store/defaultState/index.ts | Added default heightMap state values | | src/app/src/store/index.ts | Added Heightmap toolbar command | ### Key Technical Details 1. **Probe Response Handling**: Listens to serialport:read events and parses PRB responses in format [PRB:x.xxx,y.yyy,z.zzz:result] 2. **Safe Probing Sequence**: Each probe point follows the sequence: - Raise Z to clearance height - Move XY to probe position - Execute probe command (G38.2) 3. **Height Map Normalization**: After probing completes, Z values are normalized so the lowest point becomes Z=0, making the map relative to the stock surface 4. **G-code Transformation**: - Parses G-code lines for movement commands (G0, G1, G2, G3) - Subdivides long segments based on configurable segment length - Applies bilinear interpolated Z-offset at each point - Preserves original G-code structure and comments ## Testing The feature has been tested with: - Various grid configurations (spacing-based and point-count-based) - Different probe feed rates and depths - G-code files with various toolpath patterns - Save/load of height map files ## Screenshots The Height Map tool is accessible from the Tools menu with a landscape icon. The interface includes: - Grid bounds configuration panel - Probing parameters panel - Grid size mode toggle (spacing vs point count) - Visual grid display with probe points - Action buttons for probing, saving, loading, and applying ## Breaking Changes None - this is a new feature addition. ## Dependencies No new dependencies added.
The import used 'app/lib/fileUpload' (camelCase) but the actual file is 'app/lib/fileupload' (lowercase). This broke the build on Linux CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
When machining on surfaces that are not perfectly flat (e.g., PCB blanks, warped stock, uneven wasteboard), the Z-height variations cause inconsistent cut depths. This is especially critical for shallow operations like PCB trace isolation where even 0.1mm of surface variation can ruin a job.
Solution
A dedicated Height Map tool that:
G38.2probe commandFeatures
Surface Probing Workflow
Bilinear Interpolation Engine
G-code Transformation
Height Map Persistence
.gshmapJSON files including all configuration values.gshmap,.json,.mapformats) with full config restorationDouble-Apply Protection
_heightmapin its nameUnit Support
UI Layout
Two-panel design:
VisualizercomponentGrid Visualizer (SVG)
Files Changed
New Files (9)
src/app/src/features/HeightMap/definitions.tsHeightMapPoint,HeightMapBounds,HeightMapConfig,HeightMapState, etc.)src/app/src/features/HeightMap/index.tsxsrc/app/src/features/HeightMap/components/GridVisualizer.tsxsrc/app/src/features/HeightMap/components/ToolpathVisualizer.tsxVisualizercomponentsrc/app/src/features/HeightMap/utils/interpolation.tssrc/app/src/features/HeightMap/utils/probeRoutine.tssrc/app/src/features/HeightMap/utils/gcodeTransformer.tssrc/app/src/features/HeightMap/REQUIREMENTS.mdsrc/app/src/features/HeightMap/__tests__/HeightMap.test.mdModified Files (4)
src/app/src/react-routes.tsxMdLandscapeicon) and/tools/height-maproutesrc/app/src/store/defaultState/index.tsheightMapwidget default state to the global storesrc/app/src/store/definitions.tsHeightMapStatetype to the globalStateinterface.gitignore/.claudedirectoryArchitecture Decisions
controller.command()and serial port event infrastructurelucide-react,react-icons,react-router,lodash,pubsub-js,react-redux)WidgetConfigsystem for automatic persistence across sessionsTest Plan