From 15cc5831660c531029b5436244f84698db91c870 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Thu, 17 Oct 2024 08:53:51 -0700 Subject: [PATCH] start of templating for bambu based on the nozzle type Signed-off-by: Jess Frazelle --- bambulabs/src/message.rs | 21 +++++++++-- config/bambu/filament-0.2-nozzle.json | 26 ++++++++++++++ config/bambu/machine-0.2-nozzle.json | 35 +++++++++++++++++++ .../{machine.json => machine-0.4-nozzle.json} | 0 config/bambu/process-0.10mm.json | 22 ++++++++++++ .../{process.json => process-0.20mm.json} | 0 src/any_machine.rs | 9 ++++- src/bambu/control.rs | 16 +++++++-- src/bin/machine-api/cmd_serve.rs | 14 ++++---- src/machine.rs | 7 ++-- src/moonraker/control.rs | 11 ++++-- src/moonraker/temperature.rs | 6 ++-- src/noop.rs | 12 +++++-- src/server/context.rs | 3 +- src/server/mod.rs | 8 ++--- src/slicer/mod.rs | 15 +++++--- src/slicer/noop.rs | 8 +++-- src/slicer/orca.rs | 34 ++++++++++++++---- src/slicer/prusa.rs | 8 +++-- src/sync.rs | 7 +++- src/tests.rs | 9 ++--- src/traits.rs | 11 ++++++ src/usb/control.rs | 10 ++++-- 23 files changed, 245 insertions(+), 47 deletions(-) create mode 100644 config/bambu/filament-0.2-nozzle.json create mode 100644 config/bambu/machine-0.2-nozzle.json rename config/bambu/{machine.json => machine-0.4-nozzle.json} (100%) create mode 100644 config/bambu/process-0.10mm.json rename config/bambu/{process.json => process-0.20mm.json} (100%) diff --git a/bambulabs/src/message.rs b/bambulabs/src/message.rs index 9cc8518..938e0a9 100644 --- a/bambulabs/src/message.rs +++ b/bambulabs/src/message.rs @@ -420,7 +420,7 @@ pub struct PushStatus { /// The upload. pub upload: Option, /// The nozzle diameter. - pub nozzle_diameter: Option, + pub nozzle_diameter: NozzleDiameter, /// The nozzle temperature. pub nozzle_temper: Option, /// The nozzle type. @@ -945,6 +945,23 @@ pub enum NozzleType { StainlessSteel, } +/// A nozzle diameter. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Copy)] +pub enum NozzleDiameter { + /// 0.2mm. + #[serde(rename = "0.2")] + Diameter02, + /// 0.4mm. + #[serde(rename = "0.4")] + Diameter04, + /// 0.6mm. + #[serde(rename = "0.6")] + Diameter06, + /// 0.8mm. + #[serde(rename = "0.8")] + Diameter08, +} + #[cfg(test)] mod tests { use super::*; @@ -961,7 +978,7 @@ mod tests { #[test] fn test_deserialize_message_print() { let message = format!( - r#"{{ "print": {{ "bed_temper": 17.40625, "wifi_signal": "-59dBm", "command": "push_status", "msg": 1, "sequence_id": {} }}}}"#, + r#"{{ "print": {{"nozzle_diameter": "0.2", "bed_temper": 17.40625, "wifi_signal": "-59dBm", "command": "push_status", "msg": 1, "sequence_id": {} }}}}"#, 2 ); diff --git a/config/bambu/filament-0.2-nozzle.json b/config/bambu/filament-0.2-nozzle.json new file mode 100644 index 0000000..2909420 --- /dev/null +++ b/config/bambu/filament-0.2-nozzle.json @@ -0,0 +1,26 @@ +{ + "type": "filament", + "name": "Bambu PLA Basic @BBL X1C 0.2 nozzle", + "inherits": "Bambu PLA Basic @base", + "from": "system", + "setting_id": "GFSA00_00", + "instantiation": "true", + "filament_long_retractions_when_cut": [ + "1" + ], + "filament_retraction_distances_when_cut": [ + "18" + ], + "filament_max_volumetric_speed": [ + "2" + ], + "compatible_printers": [ + "Bambu Lab X1 Carbon 0.2 nozzle", + "Bambu Lab X1 0.2 nozzle", + "Bambu Lab P1S 0.2 nozzle", + "Bambu Lab X1E 0.2 nozzle" + ], + "filament_start_gcode": [ + "; filament start gcode\n{if (bed_temperature[current_extruder] >55)||(bed_temperature_initial_layer[current_extruder] >55)}M106 P3 S200\n{elsif(bed_temperature[current_extruder] >50)||(bed_temperature_initial_layer[current_extruder] >50)}M106 P3 S150\n{elsif(bed_temperature[current_extruder] >45)||(bed_temperature_initial_layer[current_extruder] >45)}M106 P3 S50\n{endif}\nM142 P1 R35 S40\n{if activate_air_filtration[current_extruder] && support_air_filtration}\nM106 P3 S{during_print_exhaust_fan_speed_num[current_extruder]} \n{endif}" + ] +} diff --git a/config/bambu/machine-0.2-nozzle.json b/config/bambu/machine-0.2-nozzle.json new file mode 100644 index 0000000..df0e59e --- /dev/null +++ b/config/bambu/machine-0.2-nozzle.json @@ -0,0 +1,35 @@ +{ + "type": "machine", + "name": "Bambu Lab X1 Carbon 0.2 nozzle", + "inherits": "Bambu Lab X1 Carbon 0.4 nozzle", + "from": "system", + "setting_id": "GM002", + "instantiation": "true", + "nozzle_diameter": [ + "0.2" + ], + "printer_model": "Bambu Lab X1 Carbon", + "printer_variant": "0.2", + "default_filament_profile": [ + "Bambu PLA Basic @BBL X1C 0.2 nozzle" + ], + "default_print_profile": "0.10mm Standard @BBL X1C 0.2 nozzle", + "max_layer_height": [ + "0.14" + ], + "min_layer_height": [ + "0.04" + ], + "nozzle_type": "stainless_steel", + "retraction_length": [ + "0.4" + ], + "upward_compatible_machine": [ + "Bambu Lab P1S 0.2 nozzle", + "Bambu Lab P1P 0.2 nozzle", + "Bambu Lab X1 0.2 nozzle", + "Bambu Lab X1E 0.2 nozzle", + "Bambu Lab A1 0.2 nozzle" + ], + "machine_start_gcode": ";===== machine: X1 ====================\n;===== date: 20240528 ==================\n;===== start printer sound ================\nM17\nM400 S1\nM1006 S1\nM1006 A0 B10 L100 C37 D10 M60 E37 F10 N60\nM1006 A0 B10 L100 C41 D10 M60 E41 F10 N60\nM1006 A0 B10 L100 C44 D10 M60 E44 F10 N60\nM1006 A0 B10 L100 C0 D10 M60 E0 F10 N60\nM1006 A46 B10 L100 C43 D10 M70 E39 F10 N100\nM1006 A0 B10 L100 C0 D10 M60 E0 F10 N100\nM1006 A43 B10 L100 C0 D10 M60 E39 F10 N100\nM1006 A0 B10 L100 C0 D10 M60 E0 F10 N100\nM1006 A41 B10 L100 C0 D10 M100 E41 F10 N100\nM1006 A44 B10 L100 C0 D10 M100 E44 F10 N100\nM1006 A49 B10 L100 C0 D10 M100 E49 F10 N100\nM1006 A0 B10 L100 C0 D10 M100 E0 F10 N100\nM1006 A48 B10 L100 C44 D10 M60 E39 F10 N100\nM1006 A0 B10 L100 C0 D10 M60 E0 F10 N100\nM1006 A44 B10 L100 C0 D10 M90 E39 F10 N100\nM1006 A0 B10 L100 C0 D10 M60 E0 F10 N100\nM1006 A46 B10 L100 C43 D10 M60 E39 F10 N100\nM1006 W\n;===== turn on the HB fan =================\nM104 S75 ;set extruder temp to turn on the HB fan and prevent filament oozing from nozzle\n;===== reset machine status =================\nM290 X40 Y40 Z2.6666666\nG91\nM17 Z0.4 ; lower the z-motor current\nG380 S2 Z30 F300 ; G380 is same as G38; lower the hotbed , to prevent the nozzle is below the hotbed\nG380 S2 Z-25 F300 ;\nG1 Z5 F300;\nG90\nM17 X1.2 Y1.2 Z0.75 ; reset motor current to default\nM960 S5 P1 ; turn on logo lamp\nG90\nM220 S100 ;Reset Feedrate\nM221 S100 ;Reset Flowrate\nM73.2 R1.0 ;Reset left time magnitude\nM1002 set_gcode_claim_speed_level : 5\nM221 X0 Y0 Z0 ; turn off soft endstop to prevent protential logic problem\nG29.1 Z{+0.0} ; clear z-trim value first\nM204 S10000 ; init ACC set to 10m/s^2\n\n;===== heatbed preheat ====================\nM1002 gcode_claim_action : 2\nM140 S[bed_temperature_initial_layer_single] ;set bed temp\nM190 S[bed_temperature_initial_layer_single] ;wait for bed temp\n\n{if scan_first_layer}\n;=========register first layer scan=====\nM977 S1 P60\n{endif}\n\n;=============turn on fans to prevent PLA jamming=================\n{if filament_type[initial_no_support_extruder]==\"PLA\"}\n {if (bed_temperature[initial_no_support_extruder] >45)||(bed_temperature_initial_layer[initial_no_support_extruder] >45)}\n M106 P3 S180\n {endif};Prevent PLA from jamming\n M142 P1 R35 S40\n{endif}\nM106 P2 S100 ; turn on big fan ,to cool down toolhead\n\n;===== prepare print temperature and material ==========\nM104 S[nozzle_temperature_initial_layer] ;set extruder temp\nG91\nG0 Z10 F1200\nG90\nG28 X\nM975 S1 ; turn on\nG1 X60 F12000\nG1 Y245\nG1 Y265 F3000\nM620 M\nM620 S[initial_no_support_extruder]A ; switch material if AMS exist\n M109 S[nozzle_temperature_initial_layer]\n G1 X120 F12000\n\n G1 X20 Y50 F12000\n G1 Y-3\n T[initial_no_support_extruder]\n G1 X54 F12000\n G1 Y265\n M400\nM621 S[initial_no_support_extruder]A\nM620.1 E F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4053*60} T{nozzle_temperature_range_high[initial_no_support_extruder]}\n\n\nM412 S1 ; ===turn on filament runout detection===\n\nM109 S250 ;set nozzle to common flush temp\nM106 P1 S0\nG92 E0\nG1 E50 F200\nM400\nM104 S[nozzle_temperature_initial_layer]\nG92 E0\nG1 E50 F200\nM400\nM106 P1 S255\nG92 E0\nG1 E5 F300\nM109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]-20} ; drop nozzle temp, make filament shink a bit\nG92 E0\nG1 E-0.5 F300\n\nG1 X70 F9000\nG1 X76 F15000\nG1 X65 F15000\nG1 X76 F15000\nG1 X65 F15000; shake to put down garbage\nG1 X80 F6000\nG1 X95 F15000\nG1 X80 F15000\nG1 X165 F15000; wipe and shake\nM400\nM106 P1 S0\n;===== prepare print temperature and material end =====\n\n\n;===== wipe nozzle ===============================\nM1002 gcode_claim_action : 14\nM975 S1\nM106 S255\nG1 X65 Y230 F18000\nG1 Y264 F6000\nM109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]-20}\nG1 X100 F18000 ; first wipe mouth\n\nG0 X135 Y253 F20000 ; move to exposed steel surface edge\nG28 Z P0 T300; home z with low precision,permit 300deg temperature\nG29.2 S0 ; turn off ABL\nG0 Z5 F20000\n\nG1 X60 Y265\nG92 E0\nG1 E-0.5 F300 ; retrack more\nG1 X100 F5000; second wipe mouth\nG1 X70 F15000\nG1 X100 F5000\nG1 X70 F15000\nG1 X100 F5000\nG1 X70 F15000\nG1 X100 F5000\nG1 X70 F15000\nG1 X90 F5000\nG0 X128 Y261 Z-1.5 F20000 ; move to exposed steel surface and stop the nozzle\nM104 S140 ; set temp down to heatbed acceptable\nM106 S255 ; turn on fan (G28 has turn off fan)\n\nM221 S; push soft endstop status\nM221 Z0 ;turn off Z axis endstop\nG0 Z0.5 F20000\nG0 X125 Y259.5 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y262.5\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y260.0\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y262.0\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y260.5\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y261.5\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 Z0.5 F20000\nG0 X125 Y261.0\nG0 Z-1.01\nG0 X131 F211\nG0 X124\nG0 X128\nG2 I0.5 J0 F300\nG2 I0.5 J0 F300\nG2 I0.5 J0 F300\nG2 I0.5 J0 F300\n\nM109 S140 ; wait nozzle temp down to heatbed acceptable\nG2 I0.5 J0 F3000\nG2 I0.5 J0 F3000\nG2 I0.5 J0 F3000\nG2 I0.5 J0 F3000\n\nM221 R; pop softend status\nG1 Z10 F1200\nM400\nG1 Z10\nG1 F30000\nG1 X128 Y128\nG29.2 S1 ; turn on ABL\n;G28 ; home again after hard wipe mouth\nM106 S0 ; turn off fan , too noisy\n;===== wipe nozzle end ================================\n\n;===== check scanner clarity ===========================\nG1 X128 Y128 F24000\nG28 Z P0\nM972 S5 P0\nG1 X230 Y15 F24000\n;===== check scanner clarity end =======================\n\n;===== bed leveling ==================================\nM1002 judge_flag g29_before_print_flag\nM622 J1\n\n M1002 gcode_claim_action : 1\n G29 A X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}\n M400\n M500 ; save cali data\n\nM623\n;===== bed leveling end ================================\n\n;===== home after wipe mouth============================\nM1002 judge_flag g29_before_print_flag\nM622 J0\n\n M1002 gcode_claim_action : 13\n G28\n\nM623\n;===== home after wipe mouth end =======================\n\nM975 S1 ; turn on vibration supression\n\n;=============turn on fans to prevent PLA jamming=================\n{if filament_type[initial_no_support_extruder]==\"PLA\"}\n {if (bed_temperature[initial_no_support_extruder] >45)||(bed_temperature_initial_layer[initial_no_support_extruder] >45)}\n M106 P3 S180\n {endif};Prevent PLA from jamming\n M142 P1 R35 S40\n{endif}\nM106 P2 S100 ; turn on big fan ,to cool down toolhead\n\nM104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]} ; set extrude temp earlier, to reduce wait time\n\n;===== mech mode fast check============================\nG1 X128 Y128 Z10 F20000\nM400 P200\nM970.3 Q1 A7 B30 C80 H15 K0\nM974 Q1 S2 P0\n\nG1 X128 Y128 Z10 F20000\nM400 P200\nM970.3 Q0 A7 B30 C90 Q0 H15 K0\nM974 Q0 S2 P0\n\nM975 S1\nG1 F30000\nG1 X230 Y15\nG28 X ; re-home XY\n;===== mech mode fast check============================\n\n{if scan_first_layer}\n;start heatbed scan====================================\nM976 S2 P1\nG90\nG1 X128 Y128 F20000\nM976 S3 P2 ;register void printing detection\n{endif}\n\n;===== nozzle load line ===============================\nM975 S1\nG90\nM83\nT1000\nG1 X18.0 Y1.0 Z0.8 F18000;Move to start position\nM109 S{nozzle_temperature[initial_no_support_extruder]}\nG1 Z0.2\nG0 E2 F300\nG0 X240 E15 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\nG0 Y11 E0.700 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\nG0 X239.5\nG0 E0.2\nG0 Y1.5 E0.700\nG0 X231 E0.700 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\nM400\n\n;===== for Textured PEI Plate , lower the nozzle as the nozzle was touching topmost of the texture when homing ==\n;curr_bed_type={curr_bed_type}\n{if curr_bed_type==\"Textured PEI Plate\"}\nG29.1 Z{-0.04} ; for Textured PEI Plate\n{endif}\n\n;===== draw extrinsic para cali paint =================\nM1002 judge_flag extrude_cali_flag\nM622 J1\n\n M1002 gcode_claim_action : 8\n\n T1000\n\n G0 F1200.0 X231 Y15 Z0.2 E0.741\n G0 F1200.0 X226 Y15 Z0.2 E0.275\n G0 F1200.0 X226 Y8 Z0.2 E0.384\n G0 F1200.0 X216 Y8 Z0.2 E0.549\n G0 F1200.0 X216 Y1.5 Z0.2 E0.357\n\n G0 X48.0 E12.0 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G0 X48.0 Y14 E0.92 F1200.0\n G0 X35.0 Y6.0 E1.03 F1200.0\n\n ;=========== extruder cali extrusion ==================\n T1000\n M83\n\t{if default_acceleration > 0}\n {if outer_wall_acceleration > 0}\n M204 S[outer_wall_acceleration]\n {else}\n M204 S[default_acceleration]\n {endif}\n {endif}\n G0 X35.000 Y6.000 Z0.300 F30000 E0\n G1 F1500.000 E0.800\n M106 S0 ; turn off fan\n G0 X185.000 E9.35441 F4800\n G0 X187 Z0\n G1 F1500.000 E-0.800\n G0 Z1\n G0 X180 Z0.3 F18000\n\n M900 L1000.0 M1.0\n M900 K0.160\n G0 X45.000 F30000\n G0 Y8.000 F30000\n G1 F1500.000 E0.800\n G1 X65.000 E1.24726 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X70.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X75.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X80.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X85.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X90.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X95.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X100.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X105.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X110.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X115.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X120.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X125.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X130.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X135.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X140.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X145.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X150.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X155.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X160.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X165.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X170.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X175.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X180.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 F1500.000 E-0.800\n G1 X183 Z0.15 F30000\n G1 X185\n G1 Z1.0\n G0 Y6.000 F30000 ; move y to clear pos\n G1 Z0.3\n M400\n\n G0 X45.000 F30000\n M900 K0.080\n G0 X45.000 F30000\n G0 Y10.000 F30000\n G1 F1500.000 E0.800\n G1 X65.000 E1.24726 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X70.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X75.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X80.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X85.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X90.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X95.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X100.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X105.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X110.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X115.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X120.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X125.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X130.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X135.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X140.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X145.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X150.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X155.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X160.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X165.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X170.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X175.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X180.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 F1500.000 E-0.800\n G1 X183 Z0.15 F30000\n G1 X185\n G1 Z1.0\n G0 Y6.000 F30000 ; move y to clear pos\n G1 Z0.3\n M400\n\n G0 X45.000 F30000\n M900 K0.000\n G0 X45.000 F30000\n G0 Y12.000 F30000\n G1 F1500.000 E0.800\n G1 X65.000 E1.24726 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X70.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X75.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X80.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X85.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X90.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X95.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X100.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X105.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X110.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X115.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X120.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X125.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X130.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X135.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X140.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X145.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X150.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X155.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X160.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X165.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X170.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X175.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X180.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 F1500.000 E-0.800\n G1 X183 Z0.15 F30000\n G1 X185\n G1 Z1.0\n G0 Y6.000 F30000 ; move y to clear pos\n G1 Z0.3\n\n G0 X45.000 F30000 ; move to start point\n\nM623 ; end of \"draw extrinsic para cali paint\"\n\nM1002 judge_flag extrude_cali_flag\nM622 J0\n G0 X231 Y1.5 F30000\n G0 X18 E14.3 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\nM623\n\nM104 S140\n\n\n;=========== laser and rgb calibration ===========\nM400\nM18 E\nM500 R\n\nM973 S3 P14\n\nG1 X120 Y1.0 Z0.3 F18000.0;Move to first extrude line pos\nT1100\nG1 X235.0 Y1.0 Z0.3 F18000.0;Move to first extrude line pos\nM400 P100\nM960 S1 P1\nM400 P100\nM973 S6 P0; use auto exposure for horizontal laser by xcam\nM960 S0 P0\n\nG1 X240.0 Y6.0 Z0.3 F18000.0;Move to vertical extrude line pos\nM960 S2 P1\nM400 P100\nM973 S6 P1; use auto exposure for vertical laser by xcam\nM960 S0 P0\n\n;=========== handeye calibration ======================\nM1002 judge_flag extrude_cali_flag\nM622 J1\n\n M973 S3 P1 ; camera start stream\n M400 P500\n M973 S1\n G0 F6000 X228.500 Y4.500 Z0.000\n M960 S0 P1\n M973 S1\n M400 P800\n M971 S6 P0\n M973 S2 P0\n M400 P500\n G0 Z0.000 F12000\n M960 S0 P0\n M960 S1 P1\n G0 X221.00 Y4.50\n M400 P200\n M971 S5 P1\n M973 S2 P1\n M400 P500\n M960 S0 P0\n M960 S2 P1\n G0 X228.5 Y11.0\n M400 P200\n M971 S5 P3\n G0 Z0.500 F12000\n M960 S0 P0\n M960 S2 P1\n G0 X228.5 Y11.0\n M400 P200\n M971 S5 P4\n M973 S2 P0\n M400 P500\n M960 S0 P0\n M960 S1 P1\n G0 X221.00 Y4.50\n M400 P500\n M971 S5 P2\n M963 S1\n M400 P1500\n M964\n T1100\n G0 F6000 X228.500 Y4.500 Z0.000\n M960 S0 P1\n M973 S1\n M400 P800\n M971 S6 P0\n M973 S2 P0\n M400 P500\n G0 Z0.000 F12000\n M960 S0 P0\n M960 S1 P1\n G0 X221.00 Y4.50\n M400 P200\n M971 S5 P1\n M973 S2 P1\n M400 P500\n M960 S0 P0\n M960 S2 P1\n G0 X228.5 Y11.0\n M400 P200\n M971 S5 P3\n G0 Z0.500 F12000\n M960 S0 P0\n M960 S2 P1\n G0 X228.5 Y11.0\n M400 P200\n M971 S5 P4\n M973 S2 P0\n M400 P500\n M960 S0 P0\n M960 S1 P1\n G0 X221.00 Y4.50\n M400 P500\n M971 S5 P2\n M963 S1\n M400 P1500\n M964\n T1100\n G1 Z3 F3000\n\n M400\n M500 ; save cali data\n\n M104 S{nozzle_temperature[initial_no_support_extruder]} ; rise nozzle temp now ,to reduce temp waiting time.\n\n T1100\n M400 P400\n M960 S0 P0\n G0 F30000.000 Y10.000 X65.000 Z0.000\n M400 P400\n M960 S1 P1\n M400 P50\n\n M969 S1 N3 A2000\n G0 F360.000 X181.000 Z0.000\n M980.3 A70.000 B{outer_wall_volumetric_speed/(1.75*1.75/4*3.14)*60/4} C5.000 D{outer_wall_volumetric_speed/(1.75*1.75/4*3.14)*60} E5.000 F175.000 H1.000 I0.000 J0.080 K0.160\n M400 P100\n G0 F20000\n G0 Z1 ; rise nozzle up\n T1000 ; change to nozzle space\n G0 X45.000 Y4.000 F30000 ; move to test line pos\n M969 S0 ; turn off scanning\n M960 S0 P0\n\n\n G1 Z2 F20000\n T1000\n G0 X45.000 Y4.000 F30000 E0\n M109 S{nozzle_temperature[initial_no_support_extruder]}\n G0 Z0.3\n G1 F1500.000 E3.600\n G1 X65.000 E1.24726 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X70.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X75.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X80.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X85.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X90.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X95.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X100.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X105.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X110.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X115.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X120.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X125.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X130.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X135.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n\n ; see if extrude cali success, if not ,use default value\n M1002 judge_last_extrude_cali_success\n M622 J0\n M400\n M900 K0.08 M{outer_wall_volumetric_speed/(1.75*1.75/4*3.14)*0.08}\n M623\n\n G1 X140.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X145.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X150.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X155.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X160.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X165.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X170.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X175.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X180.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X185.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X190.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X195.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X200.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X205.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X210.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X215.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n G1 X220.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5)/ 4 * 60}\n G1 X225.000 E0.31181 F{outer_wall_volumetric_speed/(0.3*0.5) * 60}\n M973 S4\n\nM623\n\n;========turn off light and wait extrude temperature =============\nM1002 gcode_claim_action : 0\nM973 S4 ; turn off scanner\nM400 ; wait all motion done before implement the emprical L parameters\n;M900 L500.0 ; Empirical parameters\nM109 S[nozzle_temperature_initial_layer]\nM960 S1 P0 ; turn off laser\nM960 S2 P0 ; turn off laser\nM106 S0 ; turn off fan\nM106 P2 S0 ; turn off big fan\nM106 P3 S0 ; turn off chamber fan\n\nM975 S1 ; turn on mech mode supression\nG90\nM83\nT1000\nG1 E{-retraction_length[initial_no_support_extruder]} F1800\nG1 X128.0 Y253.0 Z0.2 F24000.0;Move to start position\nG1 E{retraction_length[initial_no_support_extruder]} F1800\nM109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}\nG0 X253 E6.4 F{outer_wall_volumetric_speed/(0.3*0.6) * 60}\nG0 Y128 E6.4\nG0 X252.5\nG0 Y252.5 E6.4\nG0 X128 E6.4\n" +} diff --git a/config/bambu/machine.json b/config/bambu/machine-0.4-nozzle.json similarity index 100% rename from config/bambu/machine.json rename to config/bambu/machine-0.4-nozzle.json diff --git a/config/bambu/process-0.10mm.json b/config/bambu/process-0.10mm.json new file mode 100644 index 0000000..88077fd --- /dev/null +++ b/config/bambu/process-0.10mm.json @@ -0,0 +1,22 @@ +{ + "type": "process", + "name": "0.10mm High Quality @BBL X1C 0.2 nozzle", + "inherits": "fdm_process_bbl_0.10_nozzle_0.2", + "from": "system", + "setting_id": "GP111", + "instantiation": "true", + "description": "Compared with the default profile of a 0.2 mm nozzle, it has lower speeds and acceleration, and the sparse infill pattern is Gyroid. So, it results in much higher printing quality, but a much longer printing time.", + "default_acceleration": "4000", + "elefant_foot_compensation": "0.15", + "outer_wall_acceleration": "2000", + "outer_wall_speed": "60", + "sparse_infill_pattern": "gyroid", + "smooth_coefficient": "150", + "overhang_totally_speed": "50", + "compatible_printers": [ + "Bambu Lab X1 Carbon 0.2 nozzle", + "Bambu Lab X1 0.2 nozzle", + "Bambu Lab P1S 0.2 nozzle", + "Bambu Lab X1E 0.2 nozzle" + ] +} diff --git a/config/bambu/process.json b/config/bambu/process-0.20mm.json similarity index 100% rename from config/bambu/process.json rename to config/bambu/process-0.20mm.json diff --git a/src/any_machine.rs b/src/any_machine.rs index 9e0b920..15afbc9 100644 --- a/src/any_machine.rs +++ b/src/any_machine.rs @@ -1,6 +1,9 @@ use anyhow::Result; -use crate::{Control as ControlTrait, MachineInfo, MachineMakeModel, MachineState, MachineType, Volume}; +use crate::{ + traits::MachineSlicerInfo, Control as ControlTrait, MachineInfo, MachineMakeModel, MachineState, MachineType, + Volume, +}; /// AnyMachine is any supported machine. #[non_exhaustive] @@ -132,4 +135,8 @@ impl ControlTrait for AnyMachine { async fn state(&self) -> Result { for_all!(|self, machine| { machine.state().await }) } + + async fn slicer_info(&self) -> Result { + for_all!(|self, machine| { machine.slicer_info().await }) + } } diff --git a/src/bambu/control.rs b/src/bambu/control.rs index f78f8a7..29ab1d9 100644 --- a/src/bambu/control.rs +++ b/src/bambu/control.rs @@ -3,8 +3,9 @@ use bambulabs::{client::Client, command::Command}; use super::{PrinterInfo, X1Carbon}; use crate::{ - Control as ControlTrait, MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, - SuspendControl as SuspendControlTrait, ThreeMfControl as ThreeMfControlTrait, ThreeMfTemporaryFile, Volume, + traits::MachineSlicerInfo, Control as ControlTrait, MachineInfo as MachineInfoTrait, MachineMakeModel, + MachineState, MachineType, SuspendControl as SuspendControlTrait, ThreeMfControl as ThreeMfControlTrait, + ThreeMfTemporaryFile, Volume, }; impl X1Carbon { @@ -96,6 +97,17 @@ impl ControlTrait for X1Carbon { bambulabs::message::GcodeState::Failed => Ok(MachineState::Failed { message: more_string }), } } + + /// Return the information for the machine for the slicer. + async fn slicer_info(&self) -> Result { + let Some(status) = self.client.get_status()? else { + anyhow::bail!("Failed to get status"); + }; + + Ok(MachineSlicerInfo { + nozzle_diameter: status.nozzle_diameter, + }) + } } impl SuspendControlTrait for X1Carbon { diff --git a/src/bin/machine-api/cmd_serve.rs b/src/bin/machine-api/cmd_serve.rs index cb525dd..3f78202 100644 --- a/src/bin/machine-api/cmd_serve.rs +++ b/src/bin/machine-api/cmd_serve.rs @@ -1,17 +1,19 @@ -use super::{Cli, Config}; +use std::{ + collections::HashMap, + net::SocketAddr, + sync::{atomic::AtomicU64, Arc}, +}; + use anyhow::Result; use machine_api::{server, AnyMachine, TemperatureSensors}; use prometheus_client::{ metrics::gauge::Gauge, registry::{Registry, Unit}, }; -use std::{ - collections::HashMap, - net::SocketAddr, - sync::{atomic::AtomicU64, Arc}, -}; use tokio::sync::RwLock; +use super::{Cli, Config}; + /// Long-term this should get a new trait, and a MachineT: Metrics / generic /// param on this function. /// diff --git a/src/machine.rs b/src/machine.rs index fcdedb3..404ee9d 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,6 +1,8 @@ use anyhow::Result; -use crate::{AnyMachine, AnySlicer, DesignFile, GcodeControl, GcodeSlicer, ThreeMfControl, ThreeMfSlicer}; +use crate::{ + traits::Control, AnyMachine, AnySlicer, DesignFile, GcodeControl, GcodeSlicer, ThreeMfControl, ThreeMfSlicer, +}; /// Create a handle to a specific Machine which is capable of producing a 3D /// object in the real world from a specific [crate::DesignFile]. @@ -47,10 +49,11 @@ impl Machine { /// from it. pub async fn build(&mut self, job_name: &str, design_file: &DesignFile) -> Result<()> { tracing::debug!(name = job_name, "building"); + let slicer_info = self.machine.slicer_info().await?; match &mut self.machine { AnyMachine::BambuX1Carbon(machine) => { - let three_mf = ThreeMfSlicer::generate(&self.slicer, design_file).await?; + let three_mf = ThreeMfSlicer::generate(&self.slicer, design_file, &slicer_info).await?; ThreeMfControl::build(machine, job_name, three_mf).await } AnyMachine::Moonraker(machine) => { diff --git a/src/moonraker/control.rs b/src/moonraker/control.rs index 15c4e0e..7382603 100644 --- a/src/moonraker/control.rs +++ b/src/moonraker/control.rs @@ -5,8 +5,9 @@ use moonraker::InfoResponse; use super::Client; use crate::{ - Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, MachineInfo as MachineInfoTrait, - MachineMakeModel, MachineState, MachineType, SuspendControl as SuspendControlTrait, Volume, + traits::MachineSlicerInfo, Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, + MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, + SuspendControl as SuspendControlTrait, Volume, }; /// Information about the connected Moonraker-based printer. @@ -80,6 +81,12 @@ impl ControlTrait for Client { _ => MachineState::Unknown, }) } + + async fn slicer_info(&self) -> Result { + Ok(MachineSlicerInfo { + nozzle_diameter: bambulabs::message::NozzleDiameter::Diameter04, + }) + } } impl SuspendControlTrait for Client { diff --git a/src/moonraker/temperature.rs b/src/moonraker/temperature.rs index 099eae1..8cb1af4 100644 --- a/src/moonraker/temperature.rs +++ b/src/moonraker/temperature.rs @@ -1,7 +1,9 @@ +use std::collections::HashMap; + +use anyhow::Result; + use super::Client; use crate::{TemperatureSensor, TemperatureSensorReading, TemperatureSensors as TemperatureSensorsTrait}; -use anyhow::Result; -use std::collections::HashMap; impl Client { /// Return a handle to read the temperature information from the diff --git a/src/noop.rs b/src/noop.rs index dd43db7..6c2057b 100644 --- a/src/noop.rs +++ b/src/noop.rs @@ -4,9 +4,9 @@ use anyhow::Result; use crate::{ - Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, MachineInfo as MachineInfoTrait, - MachineMakeModel, MachineState, MachineType, SuspendControl as SuspendControlTrait, - ThreeMfControl as ThreeMfControlTrait, ThreeMfTemporaryFile, Volume, + traits::MachineSlicerInfo, Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, + MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, + SuspendControl as SuspendControlTrait, ThreeMfControl as ThreeMfControlTrait, ThreeMfTemporaryFile, Volume, }; /// Noop-machine will no-op, well, everything. @@ -74,6 +74,12 @@ impl ControlTrait for Noop { async fn state(&self) -> Result { Ok(MachineState::Unknown) } + + async fn slicer_info(&self) -> Result { + Ok(MachineSlicerInfo { + nozzle_diameter: bambulabs::message::NozzleDiameter::Diameter04, + }) + } } impl SuspendControlTrait for Noop { diff --git a/src/server/context.rs b/src/server/context.rs index cb2877e..796a47b 100644 --- a/src/server/context.rs +++ b/src/server/context.rs @@ -1,9 +1,10 @@ use std::{collections::HashMap, sync::Arc}; -use crate::Machine; use prometheus_client::registry::Registry; use tokio::sync::RwLock; +use crate::Machine; + /// Context for a given server -- this contains all the informatio required /// to serve a Machine-API request. pub struct Context { diff --git a/src/server/mod.rs b/src/server/mod.rs index 09af22f..5a9e222 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -5,18 +5,18 @@ mod cors; mod endpoints; mod raw; -pub use context::Context; -pub use cors::CorsResponseOk; -pub use raw::RawResponseOk; +use std::{collections::HashMap, env, net::SocketAddr, sync::Arc}; use anyhow::{anyhow, Result}; +pub use context::Context; +pub use cors::CorsResponseOk; use dropshot::{ApiDescription, ConfigDropshot, HttpServerStarter}; use prometheus_client::registry::Registry; +pub use raw::RawResponseOk; use signal_hook::{ consts::{SIGINT, SIGTERM}, iterator::Signals, }; -use std::{collections::HashMap, env, net::SocketAddr, sync::Arc}; use tokio::sync::RwLock; use crate::Machine; diff --git a/src/slicer/mod.rs b/src/slicer/mod.rs index d2d006f..2f28ee3 100644 --- a/src/slicer/mod.rs +++ b/src/slicer/mod.rs @@ -54,7 +54,7 @@ impl GcodeSlicerTrait for AnySlicer { match self { Self::Prusa(slicer) => GcodeSlicerTrait::generate(slicer, design_file).await, Self::Noop(slicer) => GcodeSlicerTrait::generate(slicer, design_file).await, - _ => Err(anyhow::anyhow!("slicer doesn't support 3mf")), + _ => Err(anyhow::anyhow!("slicer doesn't support gcode")), } } } @@ -63,11 +63,16 @@ impl ThreeMfSlicerTrait for AnySlicer { type Error = anyhow::Error; /// Generate gcode from some input file. - async fn generate(&self, design_file: &DesignFile) -> Result { + async fn generate( + &self, + design_file: &DesignFile, + + machine_info: &crate::traits::MachineSlicerInfo, + ) -> Result { match self { - Self::Prusa(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file).await, - Self::Orca(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file).await, - Self::Noop(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file).await, + Self::Prusa(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, machine_info).await, + Self::Orca(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, machine_info).await, + Self::Noop(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, machine_info).await, } } } diff --git a/src/slicer/noop.rs b/src/slicer/noop.rs index ef35785..eb53930 100644 --- a/src/slicer/noop.rs +++ b/src/slicer/noop.rs @@ -4,7 +4,7 @@ use anyhow::Result; use crate::{ - DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, + traits::MachineSlicerInfo, DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, }; @@ -40,7 +40,11 @@ impl GcodeSlicerTrait for Slicer { impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, _design_file: &DesignFile) -> Result { + async fn generate( + &self, + _design_file: &DesignFile, + _machine_info: &MachineSlicerInfo, + ) -> Result { let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple())); { let _ = std::fs::File::create(&filepath); diff --git a/src/slicer/orca.rs b/src/slicer/orca.rs index 291e520..6a3d629 100644 --- a/src/slicer/orca.rs +++ b/src/slicer/orca.rs @@ -5,7 +5,9 @@ use std::path::{Path, PathBuf}; use anyhow::{Context, Result}; use tokio::process::Command; -use crate::{DesignFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile}; +use crate::{ + traits::MachineSlicerInfo, DesignFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, +}; /// Handle to invoke the Orca Slicer with some specific machine-specific config. pub struct Slicer { @@ -27,6 +29,7 @@ impl Slicer { output_flag: &str, output_extension: &str, design_file: &DesignFile, + machine_info: &MachineSlicerInfo, ) -> Result { // Make sure the config path is a directory. if !self.config.is_dir() { @@ -40,23 +43,37 @@ impl Slicer { DesignFile::Stl(path) => (path, "stl"), }; + let (process_file, machine_file, filament_file) = match machine_info.nozzle_diameter { + bambulabs::message::NozzleDiameter::Diameter02 => ( + "process-0.10mm.json", + "machine-0.2-nozzle.json", + "filament-0.2-nozzle.json", + ), + bambulabs::message::NozzleDiameter::Diameter04 => { + ("process-0.20mm.json", "machine-0.2-nozzle.json", "filament.json") + } + // TODO: Add support for these nozzles and better template them. + bambulabs::message::NozzleDiameter::Diameter06 => anyhow::bail!("No configuration for 0.6mm nozzle"), + bambulabs::message::NozzleDiameter::Diameter08 => anyhow::bail!("No configuration for 0.8mm nozzle"), + }; + let uid = uuid::Uuid::new_v4(); let output_path = std::env::temp_dir().join(format!("{}.{}", uid, output_extension)); let process_config = self .config - .join("process.json") + .join(process_file) .to_str() .ok_or_else(|| anyhow::anyhow!("Invalid slicer config path: {}", self.config.display()))? .to_string(); let machine_config = self .config - .join("machine.json") + .join(machine_file) .to_str() .ok_or_else(|| anyhow::anyhow!("Invalid slicer config path: {}", self.config.display()))? .to_string(); let filament_config = self .config - .join("filament.json") + .join(filament_file) .to_str() .ok_or_else(|| anyhow::anyhow!("Invalid slicer config path: {}", self.config.display()))? .to_string(); @@ -115,9 +132,14 @@ impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; /// Generate gcode from some input file. - async fn generate(&self, design_file: &DesignFile) -> Result { + async fn generate( + &self, + design_file: &DesignFile, + machine_info: &MachineSlicerInfo, + ) -> Result { Ok(ThreeMfTemporaryFile( - self.generate_via_cli("--export-3mf", "3mf", design_file).await?, + self.generate_via_cli("--export-3mf", "3mf", design_file, machine_info) + .await?, )) } } diff --git a/src/slicer/prusa.rs b/src/slicer/prusa.rs index 95727d3..1b40e16 100644 --- a/src/slicer/prusa.rs +++ b/src/slicer/prusa.rs @@ -7,7 +7,7 @@ use anyhow::{Context, Result}; use tokio::process::Command; use crate::{ - DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, + traits::MachineSlicerInfo, DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, }; @@ -119,7 +119,11 @@ impl GcodeSlicerTrait for Slicer { impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, design_file: &DesignFile) -> Result { + async fn generate( + &self, + design_file: &DesignFile, + _machine_info: &MachineSlicerInfo, + ) -> Result { Ok(ThreeMfTemporaryFile( self.generate_from_cli("--export-3mf", "3mf", design_file).await?, )) diff --git a/src/sync.rs b/src/sync.rs index 871bab3..7a65d0a 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,7 +1,9 @@ -use crate::{Control, MachineState}; use std::sync::Arc; + use tokio::sync::Mutex; +use crate::{traits::MachineSlicerInfo, Control, MachineState}; + /// Wrapper around an `Arc>`, which helpfully will handle /// the locking to expose a [Control] without the caller having to care /// that this is a shared handle. @@ -43,4 +45,7 @@ where async fn state(&self) -> Result { self.0.lock().await.state().await } + async fn slicer_info(&self) -> Result { + self.0.lock().await.slicer_info().await + } } diff --git a/src/tests.rs b/src/tests.rs index 914c279..2aa879b 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,11 +1,12 @@ -use anyhow::{Context, Result}; -use expectorate::assert_contents; -use pretty_assertions::assert_eq; -use prometheus_client::registry::Registry; use std::{ collections::{BTreeMap, HashMap}, sync::Arc, }; + +use anyhow::{Context, Result}; +use expectorate::assert_contents; +use pretty_assertions::assert_eq; +use prometheus_client::registry::Registry; use test_context::{test_context, AsyncTestContext}; use testresult::TestResult; use tokio::sync::RwLock; diff --git a/src/traits.rs b/src/traits.rs index 29c3e0a..bf50615 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -124,6 +124,9 @@ pub trait Control { /// Return the state of the printer. fn state(&self) -> impl Future>; + + /// Return the information for the machine for the slicer. + fn slicer_info(&self) -> impl Future>; } /// [TemperatureSensor] indicates the specific part of the machine that the @@ -225,6 +228,13 @@ pub trait GcodeSlicer { /// GcodeTemporaryFile is a TemporaryFile full of .gcode. pub struct GcodeTemporaryFile(pub TemporaryFile); +/// Information about the machine that applies to the slicer. +#[derive(Debug, Clone, Copy)] +pub struct MachineSlicerInfo { + /// The diameter of the nozzle in millimeters. + pub nozzle_diameter: bambulabs::message::NozzleDiameter, +} + /// [Control]-specific slicer which takes a particular [DesignFile], and produces /// GCode. pub trait ThreeMfSlicer { @@ -236,6 +246,7 @@ pub trait ThreeMfSlicer { fn generate( &self, design_file: &DesignFile, + machine_info: &MachineSlicerInfo, ) -> impl Future::Error>>; } diff --git a/src/usb/control.rs b/src/usb/control.rs index f92013e..1265de2 100644 --- a/src/usb/control.rs +++ b/src/usb/control.rs @@ -8,8 +8,8 @@ use tokio::{ use tokio_serial::SerialStream; use crate::{ - gcode::Client, Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, - MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, Volume, + gcode::Client, traits::MachineSlicerInfo, Control as ControlTrait, GcodeControl as GcodeControlTrait, + GcodeTemporaryFile, MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, Volume, }; /// Handle to a USB based gcode 3D printer. @@ -140,6 +140,12 @@ impl ControlTrait for Usb { // TODO: fix this, do a gcode ping or something? true } + + async fn slicer_info(&self) -> Result { + Ok(MachineSlicerInfo { + nozzle_diameter: bambulabs::message::NozzleDiameter::Diameter04, + }) + } } impl GcodeControlTrait for Usb {