From 2981b6b975ea5f212fa685f1d029beeb1ba775e7 Mon Sep 17 00:00:00 2001 From: zaubentrucker Date: Mon, 3 Mar 2025 15:26:56 +0100 Subject: [PATCH] Cleanup code --- red/src/jogger.rs | 10 +++++++--- red/src/main.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/red/src/jogger.rs b/red/src/jogger.rs index db9cfed..0779e1a 100644 --- a/red/src/jogger.rs +++ b/red/src/jogger.rs @@ -9,19 +9,23 @@ use std::time::Duration; /// For a given GCode buffer size on the machine, we can assume /// a maximum delay of `TIME_PER_MOVEMENT * BUFFER_COUNT` const TIME_PER_MOVEMENT: Duration = Duration::from_millis(30); + /// Movement speed of gantry when going full throttle in x/y-direction /// in units/min (mm/min) const FULL_SCALE_SPEED_XY: f64 = 2000.0; + /// Movement speed of gantry when going full throttle in z-direction /// in units/min (mm/min) const FULL_SCALE_SPEED_Z: f64 = 100.0; + /// Amount of GCODE buffers that should be filled for optimal jogging performance. -/// More buffers increase the controller delay. Less buffers make it more difficult +/// More buffers increase the controller delay. Fewer buffers make it more difficult /// for the motion planner on the printer to plan ahead. -const TARGET_BUFER_FILL_LEVEL: usize = 4; +const TARGET_BUFFER_FILL_LEVEL: usize = 4; /// Time to wait before sending new commands if the GCODE buffer is overfull const LONG_COMMAND_DELAY: Duration = TIME_PER_MOVEMENT; + /// Divider for `LONG_COMMAND_DELAY` for waiting if we've reached `TARGET_BUFER_FILL_LEVEL` const SHORT_COMMAND_DELAY_DIVIDER: u32 = 2; @@ -76,7 +80,7 @@ pub fn jog(gamepad: &mut Gamepad, mut printer: Printer) -> Result<()> { let fill_level = printer.maximum_capacity() - printer.remaining_capacity(); println!("remaining capacity: {}", printer.remaining_capacity()); println!("fill level: {}", fill_level); - match fill_level.cmp(&TARGET_BUFER_FILL_LEVEL) { + match fill_level.cmp(&TARGET_BUFFER_FILL_LEVEL) { std::cmp::Ordering::Equal => { std::thread::sleep(LONG_COMMAND_DELAY / SHORT_COMMAND_DELAY_DIVIDER) } diff --git a/red/src/main.rs b/red/src/main.rs index cbabc20..3d19d6d 100644 --- a/red/src/main.rs +++ b/red/src/main.rs @@ -7,7 +7,7 @@ use red::printer::{AutoReportSetting, Printer}; use std::path::Path; fn main() -> Result<()> { - jog() + jog() } fn find_printer_port() -> Result { @@ -36,7 +36,7 @@ fn jog() -> Result<()> { let printer_tty_path = find_printer_port()?; let mut printer = Printer::connect_to_path(&printer_tty_path) .with_context(|| anyhow!("Initializing printer connection"))?; - + printer.set_position_auto_report(AutoReportSetting::EverySeconds(1))?; printer.set_temperature_auto_report(AutoReportSetting::EverySeconds(1))?;