Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions docs/Cosmos3D_PostProcessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Cosmos3D Embedded Post-Processing

This feature adds embedded C++ post-processing specifically for Cosmos3D printers.

## Overview

The Cosmos3D post-processing script is embedded directly in the source code and automatically runs for any printer with "Cosmos" in its `printer_model` configuration. This provides printer-specific optimizations without requiring external script files.

## Features

### Automatic Detection
- Detects Cosmos3D printers by checking if `printer_model` contains "Cosmos"
- Runs automatically during the post-processing phase
- Does not interfere with regular post-processing scripts

### G-Code Cleaning Algorithm
The embedded script performs aggressive G-code cleaning specifically for concrete printing:

1. **Content Filtering**
- Removes all lines before the "COSMOS" marker
- Only processes G-code after the COSMOS marker is found

2. **Layer Change Modification**
- Converts `;LAYER_CHANGE` to `;LAYER_CHANGE M3`
```gcode
;LAYER_CHANGE M3
```

3. **Comment Removal**
- Strips all comment lines (starting with semicolon) except layer changes
- Removes clutter from the G-code file

4. **Progress Command Removal**
- Removes M73 progress update commands
- Reduces file size and processing overhead

5. **G1 Command Filtering**
- Removes extruder (E) values from all G1 commands
- Keeps G1 lines containing X or Y coordinates
- Removes G1 lines with only Z movement (with or without F parameter)
- Removes G1 lines with only feed rate (F parameter)
- **Filters consecutive dots**: Removes G1 commands where X/Y coordinates are closer than 1.5mm to the previous point
```gcode
G1 X10 Y10 E2 F1800 → G1 X10 Y10 F1800
G1 Z5 F300 → [removed]
G1 F1500 → [removed]
G1 X10.5 Y10.3 → [removed if < 1.5mm from last point]
```

6. **Command Preservation**
- Maintains all other G-code commands (M104, M106, M84, etc.)
- Ensures compatibility with printer firmware

### Example Transformation

**Input G-code:**
```gcode
; generated by OrCa Slicer
; FLAVOR:Marlin
; initial comments before COSMOS
COSMOS
; This comment should be removed
G1 X0 Y0 E2 F1800
G1 X1 Y0 E2.5 F1800
G1 X1.2 Y0.2 E3 F1800
G1 X3 Y0 E4 F1800
G1 Z5 F300
G1 F1500
;LAYER_CHANGE
M73 P50
G1 X10 Y10 E5 F1800
G1 X10.5 Y10.3 E5.5 F1800
G1 X20 Y20 E6 F1800
M104 S210
M84
```

**Output G-code:**
```gcode
G1 X0 Y0 F1800
G1 X3 Y0 F1800
;LAYER_CHANGE M3
G1 X10 Y10 F1800
G1 X20 Y20 F1800
M104 S210
M84
```

**Explanation:**
- All content before "COSMOS" removed
- Comments and M73 commands removed
- E values removed from G1 commands
- Z-only and F-only G1 commands removed
- Consecutive points closer than 1.5mm filtered out:
- (1, 0) is 1.0mm from (0, 0) - filtered
- (1.2, 0.2) is 1.22mm from (0, 0) - filtered
- (3, 0) is 3.0mm from (0, 0) - kept
- (10.5, 10.3) is 0.58mm from (10, 10) - filtered
- (20, 20) is 14.14mm from (10, 10) - kept

## Integration with Existing System

### Execution Order
1. Regular environment setup
2. **Cosmos3D embedded processing** (if applicable)
3. Regular post-processing scripts (if defined)
4. Output file handling

### Compatibility
- Works alongside existing post-processing scripts
- Does not break existing functionality
- Gracefully handles failures (logs warning and continues)

## Implementation Details

### Files Modified
- `src/libslic3r/GCode/PostProcessor.hpp` - Added function declaration
- `src/libslic3r/GCode/PostProcessor.cpp` - Added implementation and integration

### Key Functions
- `run_cosmos_post_processing()` - Main embedded processing function
- Modified `run_post_process_scripts()` - Integrated cosmos processing

### Printer Configuration
Example printer configuration in `resources/profiles/Cosmos3D/machine/Cosmos3D.json`:
```json
{
"printer_model": "Cosmos3D v1",
"printer_variant": "0.4",
...
}
```

## Testing

The implementation includes comprehensive tests verifying:
- Cosmos3D printers are correctly detected and processed
- Non-Cosmos3D printers are skipped
- Regular post-processing scripts continue to work
- Both embedded and script processing can run together
- No processing occurs when no scripts are defined for non-Cosmos printers

## Usage

1. Configure a printer with "Cosmos" in the `printer_model` name
2. The embedded post-processing will automatically run during G-code generation
3. Optional: Add additional post-processing scripts as usual
4. Generated G-code will include Cosmos3D-specific optimizations

No additional configuration or external files are required.
92 changes: 46 additions & 46 deletions resources/profiles/Cosmos3D.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"name": "Cosmos3D",
"version": "02.01.01.00",
"force_update": "0",
"description": "Cosmos3D configurations",
"machine_model_list": [
{
"name": "Cosmos3D X1",
"sub_path": "machine/Cosmos3D X1.json"
}
],
"process_list": [
{
"name": "fdm_process_common",
"sub_path": "process/fdm_process_common.json"
},
{
"name": "Concrete Printing @Cosmos3D X1 60 nozzle",
"sub_path": "process/Concrete Printing @Cosmos3D X1 60 nozzle.json"
}
],
"filament_list": [
{
"name": "fdm_filament_common",
"sub_path": "filament/fdm_filament_common.json"
},
{
"name": "fdm_filament_concrete",
"sub_path": "filament/fdm_filament_concrete.json"
},
{
"name": "Generic Concrete",
"sub_path": "filament/Generic Concrete.json"
}
],
"machine_list": [
{
"name": "fdm_machine_common",
"sub_path": "machine/fdm_machine_common.json"
},
{
"name": "Cosmos3D X1 60 nozzle",
"sub_path": "machine/Cosmos3D X1 60 nozzle.json"
}
]
}
{
"name": "Cosmos3D",
"version": "02.01.01.00",
"force_update": "0",
"description": "Cosmos3D configurations",
"machine_model_list": [
{
"name": "Cosmos3D X1",
"sub_path": "machine/Cosmos3D X1.json"
}
],
"process_list": [
{
"name": "fdm_process_common",
"sub_path": "process/fdm_process_common.json"
},
{
"name": "Concrete Printing @Cosmos3D X1 60 nozzle",
"sub_path": "process/Concrete Printing @Cosmos3D X1 60 nozzle.json"
}
],
"filament_list": [
{
"name": "fdm_filament_common",
"sub_path": "filament/fdm_filament_common.json"
},
{
"name": "fdm_filament_concrete",
"sub_path": "filament/fdm_filament_concrete.json"
},
{
"name": "Generic Concrete",
"sub_path": "filament/Generic Concrete.json"
}
],
"machine_list": [
{
"name": "fdm_machine_common",
"sub_path": "machine/fdm_machine_common.json"
},
{
"name": "Cosmos3D X1 60 nozzle",
"sub_path": "machine/Cosmos3D X1 60 nozzle.json"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@
"prime_tower_width": "35",
"xy_hole_compensation": "0",
"xy_contour_compensation": "0",
"compatible_printers": ["Cosmos3D X1 60 nozzle"]
"compatible_printers": ["Cosmos3D X1 60 nozzle"],
"post_process": ""
}
Loading