Jog using absolute movements
This commit is contained in:
parent
3b5892e7e0
commit
b47a27cb86
|
@ -33,8 +33,8 @@ pub type PrinterVec = Vector3D<f64, PrinterUnits>;
|
|||
|
||||
/// Jog the gantry by pumping loads of gcode into the printer board
|
||||
pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
||||
printer.use_relative_movements().await.unwrap();
|
||||
println!("Using relative movements");
|
||||
printer.use_absolute_movements().await.unwrap();
|
||||
println!("Using absolute movements");
|
||||
loop {
|
||||
let (setpoint_x, setpoint_y, setpoint_z) = gamepad.speed_setpoint();
|
||||
|
||||
|
@ -48,11 +48,21 @@ pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
|||
continue;
|
||||
}
|
||||
let velocity = distance.length() / (TIME_PER_MOVEMENT.as_secs_f64() / 60.0);
|
||||
let old_postion = printer.state.position;
|
||||
printer
|
||||
.move_relative(distance.x, distance.y, distance.z, velocity.into())
|
||||
.move_absolute(
|
||||
old_postion.x + distance.x,
|
||||
old_postion.y + distance.y,
|
||||
old_postion.z + distance.z,
|
||||
velocity.into(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to send movement command!");
|
||||
|
||||
println!(
|
||||
"New position {pos:?}",
|
||||
pos = printer.printer_state().position
|
||||
);
|
||||
// Wait for one command time if buffer is overfull, wait for half that time if buffer is
|
||||
// filled *just* right.
|
||||
let fill_level = printer.maximum_capacity() - printer.remaining_capacity();
|
||||
|
|
|
@ -81,15 +81,3 @@ async fn write_to_printer() -> Never {
|
|||
printer.move_relative(25.0, 25.0, 5.0, None).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn jog() -> Never {
|
||||
let jogger = gamepad::Gamepad::new().await.unwrap();
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
let setpoint = jogger.speed_setpoint();
|
||||
println!(
|
||||
"speed setpoint: {} {} {}",
|
||||
setpoint.0, setpoint.1, setpoint.2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,9 @@ pub enum PrinterError {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PrinterPosition {
|
||||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub z: f64,
|
||||
}
|
||||
|
||||
pub enum MovementMode {
|
||||
|
@ -50,8 +50,8 @@ pub enum MovementMode {
|
|||
}
|
||||
|
||||
pub struct State {
|
||||
position: PrinterPosition,
|
||||
movement_mode: MovementMode,
|
||||
pub position: PrinterPosition,
|
||||
pub movement_mode: MovementMode,
|
||||
}
|
||||
|
||||
pub struct Printer {
|
||||
|
@ -163,6 +163,10 @@ impl Printer {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn printer_state(&self) -> &State {
|
||||
&self.state
|
||||
}
|
||||
|
||||
/// The maximum capacity of the machines GCODE buffer.
|
||||
pub fn maximum_capacity(&self) -> usize {
|
||||
self.maximum_buffer_capacity
|
||||
|
@ -289,14 +293,14 @@ impl Printer {
|
|||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
velocity: f64,
|
||||
velocity: Option<f64>,
|
||||
) -> Result<(), PrinterError> {
|
||||
let command = G0Command {
|
||||
x: Some(x),
|
||||
y: Some(y),
|
||||
z: Some(z),
|
||||
e: None, // Machine has no e
|
||||
velocity: Some(velocity),
|
||||
velocity: velocity,
|
||||
};
|
||||
if let MovementMode::RelativeMovements = self.state.movement_mode {
|
||||
self.use_absolute_movements().await?;
|
||||
|
|
Loading…
Reference in a new issue