46 lines
1.8 KiB
Rust
46 lines
1.8 KiB
Rust
|
use crate::printer::GcodeCommand;
|
||
|
use crate::{gamepad::Gamepad, printer::gcode::G0Command, printer::Printer};
|
||
|
use euclid::{vec3, Vector3D};
|
||
|
use futures::never::Never;
|
||
|
use std::sync::Arc;
|
||
|
use std::time::Duration;
|
||
|
|
||
|
/// Time that a single movement command should take
|
||
|
///
|
||
|
/// 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(20);
|
||
|
/// Movement speed of gantry when going full throttle in x/y-direction
|
||
|
/// in units/min (mm/min)
|
||
|
const FULL_SCALE_SPEED_XY: f64 = 1000.0;
|
||
|
/// Movement speed of gantry when going full throttle in z-direction
|
||
|
/// in units/min (mm/min)
|
||
|
const FULL_SCALE_SPEED_Z: f64 = 10.0;
|
||
|
|
||
|
/// Should be mm on most machine including the Leapfrog
|
||
|
pub struct PrinterUnits;
|
||
|
pub type PrinterVec = Vector3D<f64, PrinterUnits>;
|
||
|
|
||
|
/// Jogging the gantry by pumping loads of gcode into the printer board
|
||
|
pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
||
|
loop {
|
||
|
let (setpoint_x, setpoint_y, setpoint_z) = gamepad.speed_setpoint();
|
||
|
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),
|
||
|
);
|
||
|
let velocity = distance.length();
|
||
|
let command = G0Command {
|
||
|
x: distance.x.into(),
|
||
|
y: distance.y.into(),
|
||
|
z: distance.z.into(),
|
||
|
e: None,
|
||
|
velocity: velocity.into(),
|
||
|
};
|
||
|
// printer.send_gcode(Box::new(command)).await;
|
||
|
println!("{:?}", command.command());
|
||
|
std::thread::sleep(TIME_PER_MOVEMENT);
|
||
|
}
|
||
|
}
|