Skip to content

Commit

Permalink
start of templating for bambu based on the nozzle type
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Oct 17, 2024
1 parent 75ae3d8 commit 15cc583
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 47 deletions.
21 changes: 19 additions & 2 deletions bambulabs/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub struct PushStatus {
/// The upload.
pub upload: Option<PrintUpload>,
/// The nozzle diameter.
pub nozzle_diameter: Option<String>,
pub nozzle_diameter: NozzleDiameter,
/// The nozzle temperature.
pub nozzle_temper: Option<f64>,
/// The nozzle type.
Expand Down Expand Up @@ -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::*;
Expand All @@ -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
);

Expand Down
26 changes: 26 additions & 0 deletions config/bambu/filament-0.2-nozzle.json
Original file line number Diff line number Diff line change
@@ -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}"
]
}
35 changes: 35 additions & 0 deletions config/bambu/machine-0.2-nozzle.json

Large diffs are not rendered by default.

File renamed without changes.
22 changes: 22 additions & 0 deletions config/bambu/process-0.10mm.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
File renamed without changes.
9 changes: 8 additions & 1 deletion src/any_machine.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -132,4 +135,8 @@ impl ControlTrait for AnyMachine {
async fn state(&self) -> Result<MachineState> {
for_all!(|self, machine| { machine.state().await })
}

async fn slicer_info(&self) -> Result<MachineSlicerInfo> {
for_all!(|self, machine| { machine.slicer_info().await })
}
}
16 changes: 14 additions & 2 deletions src/bambu/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<MachineSlicerInfo> {
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 {
Expand Down
14 changes: 8 additions & 6 deletions src/bin/machine-api/cmd_serve.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
7 changes: 5 additions & 2 deletions src/machine.rs
Original file line number Diff line number Diff line change
@@ -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].
Expand Down Expand Up @@ -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) => {
Expand Down
11 changes: 9 additions & 2 deletions src/moonraker/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -80,6 +81,12 @@ impl ControlTrait for Client {
_ => MachineState::Unknown,
})
}

async fn slicer_info(&self) -> Result<MachineSlicerInfo> {
Ok(MachineSlicerInfo {
nozzle_diameter: bambulabs::message::NozzleDiameter::Diameter04,
})
}
}

impl SuspendControlTrait for Client {
Expand Down
6 changes: 4 additions & 2 deletions src/moonraker/temperature.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -74,6 +74,12 @@ impl ControlTrait for Noop {
async fn state(&self) -> Result<MachineState> {
Ok(MachineState::Unknown)
}

async fn slicer_info(&self) -> Result<MachineSlicerInfo> {
Ok(MachineSlicerInfo {
nozzle_diameter: bambulabs::message::NozzleDiameter::Diameter04,
})
}
}

impl SuspendControlTrait for Noop {
Expand Down
3 changes: 2 additions & 1 deletion src/server/context.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions src/slicer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
}
}
}
Expand All @@ -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<ThreeMfTemporaryFile> {
async fn generate(
&self,
design_file: &DesignFile,

machine_info: &crate::traits::MachineSlicerInfo,
) -> Result<ThreeMfTemporaryFile> {
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,
}
}
}
8 changes: 6 additions & 2 deletions src/slicer/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -40,7 +40,11 @@ impl GcodeSlicerTrait for Slicer {
impl ThreeMfSlicerTrait for Slicer {
type Error = anyhow::Error;

async fn generate(&self, _design_file: &DesignFile) -> Result<ThreeMfTemporaryFile> {
async fn generate(
&self,
_design_file: &DesignFile,
_machine_info: &MachineSlicerInfo,
) -> Result<ThreeMfTemporaryFile> {
let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple()));
{
let _ = std::fs::File::create(&filepath);
Expand Down
Loading

0 comments on commit 15cc583

Please sign in to comment.