Implement xy movements
This commit is contained in:
parent
af069c8e5e
commit
cecc355be4
|
@ -6,7 +6,7 @@ build:
|
||||||
rrun:
|
rrun:
|
||||||
#scp -r ./src {{url}}:red/
|
#scp -r ./src {{url}}:red/
|
||||||
rsync -rvu --filter=':- .gitignore' ../red {{url}}:
|
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:
|
rdown:
|
||||||
ssh {{url}} "sudo /usr/sbin/poweroff"
|
ssh {{url}} "sudo /usr/sbin/poweroff"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::printer::GcodeCommand;
|
use crate::gamepad::Gamepad;
|
||||||
use crate::{gamepad::Gamepad, printer::gcode::G0Command, printer::Printer};
|
use crate::printer::gcode::{G0Command, G91Command};
|
||||||
|
use crate::printer::{GcodeCommand, Printer};
|
||||||
use euclid::{vec3, Vector3D};
|
use euclid::{vec3, Vector3D};
|
||||||
use futures::never::Never;
|
use futures::never::Never;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -23,14 +24,25 @@ pub type PrinterVec = Vector3D<f64, PrinterUnits>;
|
||||||
|
|
||||||
/// Jogging the gantry by pumping loads of gcode into the printer board
|
/// Jogging the gantry by pumping loads of gcode into the printer board
|
||||||
pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
||||||
|
printer.send_gcode(Box::new(G91Command)).await.unwrap();
|
||||||
|
println!("Sent G91Command");
|
||||||
loop {
|
loop {
|
||||||
let (setpoint_x, setpoint_y, setpoint_z) = gamepad.speed_setpoint();
|
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(
|
let distance: PrinterVec = vec3(
|
||||||
(FULL_SCALE_SPEED_XY / 60.0) * TIME_PER_MOVEMENT.as_secs_f64() * (setpoint_x as f64),
|
full_scale_speed * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_x as f64),
|
||||||
(FULL_SCALE_SPEED_XY / 60.0) * TIME_PER_MOVEMENT.as_secs_f64() * (setpoint_y as f64),
|
full_scale_speed * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (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_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 {
|
let command = G0Command {
|
||||||
x: distance.x.into(),
|
x: distance.x.into(),
|
||||||
y: distance.y.into(),
|
y: distance.y.into(),
|
||||||
|
@ -38,8 +50,7 @@ pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
||||||
e: None,
|
e: None,
|
||||||
velocity: velocity.into(),
|
velocity: velocity.into(),
|
||||||
};
|
};
|
||||||
// printer.send_gcode(Box::new(command)).await;
|
printer.send_gcode(Box::new(command)).await;
|
||||||
println!("{:?}", command.command());
|
|
||||||
std::thread::sleep(TIME_PER_MOVEMENT);
|
std::thread::sleep(TIME_PER_MOVEMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ const I2C_REGISTER_SPINDLE_SPEED: u8 = 0;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Never {
|
async fn main() -> Never {
|
||||||
print!("Entering App");
|
println!("Entering App");
|
||||||
let gamepad = gamepad::Gamepad::new().await.unwrap();
|
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
|
// TODO: Make printer do relative movements
|
||||||
jogger::jog(gamepad, printer).await
|
jogger::jog(gamepad, printer).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl GcodeCommand for G28Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_reply(&self, reply: &str) -> Result<GcodeReply> {
|
fn parse_reply(&self, reply: &str) -> Result<GcodeReply> {
|
||||||
if reply.is_empty() {
|
if !reply.is_empty() {
|
||||||
Err(GcodeReplyError {
|
Err(GcodeReplyError {
|
||||||
sent_command: self.command(),
|
sent_command: self.command(),
|
||||||
parsed_input: reply.to_string(),
|
parsed_input: reply.to_string(),
|
||||||
|
|
23
red/src/printer/gcode/g91.rs
Normal file
23
red/src/printer/gcode/g91.rs
Normal file
|
@ -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<GcodeReply> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,9 +11,11 @@
|
||||||
/// ```
|
/// ```
|
||||||
mod g0;
|
mod g0;
|
||||||
mod g28;
|
mod g28;
|
||||||
|
mod g91;
|
||||||
mod m114;
|
mod m114;
|
||||||
pub use g0::G0Command;
|
pub use g0::G0Command;
|
||||||
pub use g28::G28Command;
|
pub use g28::G28Command;
|
||||||
|
pub use g91::G91Command;
|
||||||
pub use m114::M114Command;
|
pub use m114::M114Command;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ impl Printer {
|
||||||
|
|
||||||
while let Some(command) = printer_in_rx.recv().await {
|
while let Some(command) = printer_in_rx.recv().await {
|
||||||
let command_text = format!("{}\n", command.command());
|
let command_text = format!("{}\n", command.command());
|
||||||
|
println!("sending in: {:?}", command_text);
|
||||||
serial_tx.send(command_text).await.unwrap();
|
serial_tx.send(command_text).await.unwrap();
|
||||||
let mut reply = "".to_string();
|
let mut reply = "".to_string();
|
||||||
while let Some(line) = serial_rx.next().await {
|
while let Some(line) = serial_rx.next().await {
|
||||||
|
|
Loading…
Reference in a new issue