diff --git a/red/justfile b/red/justfile index 98b0e54..8945968 100644 --- a/red/justfile +++ b/red/justfile @@ -6,7 +6,7 @@ build: rrun: #scp -r ./src {{url}}:red/ rsync -rvu --filter=':- .gitignore' ../red {{url}}: - ssh {{url}} "cd red; /home/olimex/.cargo/bin/cargo run;" + ssh {{url}} "cd red; RUST_BACKTRACE=1 /home/olimex/.cargo/bin/cargo run;" rdown: ssh {{url}} "sudo /usr/sbin/poweroff" diff --git a/red/src/jogger.rs b/red/src/jogger.rs index d9406f9..ae6306d 100644 --- a/red/src/jogger.rs +++ b/red/src/jogger.rs @@ -1,5 +1,6 @@ -use crate::printer::GcodeCommand; -use crate::{gamepad::Gamepad, printer::gcode::G0Command, printer::Printer}; +use crate::gamepad::Gamepad; +use crate::printer::gcode::{G0Command, G91Command}; +use crate::printer::{GcodeCommand, Printer}; use euclid::{vec3, Vector3D}; use futures::never::Never; use std::sync::Arc; @@ -23,14 +24,25 @@ pub type PrinterVec = Vector3D; /// Jogging the gantry by pumping loads of gcode into the printer board pub async fn jog(gamepad: Arc, mut printer: Printer) -> Never { + printer.send_gcode(Box::new(G91Command)).await.unwrap(); + println!("Sent G91Command"); loop { let (setpoint_x, setpoint_y, setpoint_z) = gamepad.speed_setpoint(); + // We're bound by lower speed on z and have no way to go at separate speeds per axis + let full_scale_speed = if setpoint_z == 0.0 { + FULL_SCALE_SPEED_XY + } else { + FULL_SCALE_SPEED_Z + }; let distance: PrinterVec = vec3( - (FULL_SCALE_SPEED_XY / 60.0) * TIME_PER_MOVEMENT.as_secs_f64() * (setpoint_x as f64), - (FULL_SCALE_SPEED_XY / 60.0) * TIME_PER_MOVEMENT.as_secs_f64() * (setpoint_y as f64), - (FULL_SCALE_SPEED_Z / 60.0) * TIME_PER_MOVEMENT.as_secs_f64() * (setpoint_z as f64), + full_scale_speed * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_x as f64), + full_scale_speed * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_y as f64), + full_scale_speed * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_z as f64), ); - let velocity = distance.length(); + if distance.length() == 0.0 { + continue; + } + let velocity = distance.length() / (TIME_PER_MOVEMENT.as_secs_f64() / 60.0); let command = G0Command { x: distance.x.into(), y: distance.y.into(), @@ -38,8 +50,7 @@ pub async fn jog(gamepad: Arc, mut printer: Printer) -> Never { e: None, velocity: velocity.into(), }; - // printer.send_gcode(Box::new(command)).await; - println!("{:?}", command.command()); + printer.send_gcode(Box::new(command)).await; std::thread::sleep(TIME_PER_MOVEMENT); } } diff --git a/red/src/main.rs b/red/src/main.rs index 265c547..86c3b97 100644 --- a/red/src/main.rs +++ b/red/src/main.rs @@ -34,9 +34,9 @@ const I2C_REGISTER_SPINDLE_SPEED: u8 = 0; #[tokio::main] async fn main() -> Never { - print!("Entering App"); + println!("Entering App"); let gamepad = gamepad::Gamepad::new().await.unwrap(); - let printer = Printer::connect(DEFAULT_TTY).await.unwrap(); + let printer = Printer::connect("/dev/ttyUSB2").await.unwrap(); // TODO: Make printer do relative movements jogger::jog(gamepad, printer).await } diff --git a/red/src/printer/gcode/g28.rs b/red/src/printer/gcode/g28.rs index f9c4371..469b6f9 100644 --- a/red/src/printer/gcode/g28.rs +++ b/red/src/printer/gcode/g28.rs @@ -27,7 +27,7 @@ impl GcodeCommand for G28Command { } fn parse_reply(&self, reply: &str) -> Result { - if reply.is_empty() { + if !reply.is_empty() { Err(GcodeReplyError { sent_command: self.command(), parsed_input: reply.to_string(), diff --git a/red/src/printer/gcode/g91.rs b/red/src/printer/gcode/g91.rs new file mode 100644 index 0000000..5887290 --- /dev/null +++ b/red/src/printer/gcode/g91.rs @@ -0,0 +1,23 @@ +use super::*; + +/// Auto Home +#[derive(Debug)] +pub struct G91Command; + +impl GcodeCommand for G91Command { + fn command(&self) -> String { + "G91".into() + } + + fn parse_reply(&self, reply: &str) -> Result { + if !reply.is_empty() { + Err(GcodeReplyError { + sent_command: self.command(), + parsed_input: reply.to_string(), + problem: "Expected no reply".to_string(), + }) + } else { + Ok(GcodeReply::NoReply) + } + } +} diff --git a/red/src/printer/gcode/mod.rs b/red/src/printer/gcode/mod.rs index 4f0649f..87356d4 100644 --- a/red/src/printer/gcode/mod.rs +++ b/red/src/printer/gcode/mod.rs @@ -11,9 +11,11 @@ /// ``` mod g0; mod g28; +mod g91; mod m114; pub use g0::G0Command; pub use g28::G28Command; +pub use g91::G91Command; pub use m114::M114Command; use std::fmt::Debug; diff --git a/red/src/printer/mod.rs b/red/src/printer/mod.rs index 4a81ba5..16ed268 100644 --- a/red/src/printer/mod.rs +++ b/red/src/printer/mod.rs @@ -71,6 +71,7 @@ impl Printer { while let Some(command) = printer_in_rx.recv().await { let command_text = format!("{}\n", command.command()); + println!("sending in: {:?}", command_text); serial_tx.send(command_text).await.unwrap(); let mut reply = "".to_string(); while let Some(line) = serial_rx.next().await {