Enable z jogging
This commit is contained in:
parent
db33f6a53c
commit
396d24b451
|
@ -1,5 +1,7 @@
|
|||
/// Functionality for retrieving and interpreting gamepad input
|
||||
use gilrs::Axis::*;
|
||||
use gilrs::Button::LeftTrigger2;
|
||||
use gilrs::Button::RightTrigger2;
|
||||
use gilrs::EventType::*;
|
||||
use gilrs::Gilrs;
|
||||
use std::sync::Arc;
|
||||
|
@ -79,6 +81,7 @@ impl Gamepad {
|
|||
|
||||
/// Update the setpoints in accordance to incoming `GamepadEvent`s
|
||||
async fn handle_events(self_arc: Arc<Self>, mut events_rx: mpsc::Receiver<GamepadEvent>) {
|
||||
// There is two z-axes that counter each other.
|
||||
let mut z_positive = 0.0;
|
||||
let mut z_negative = 0.0;
|
||||
while let Some(event) = events_rx.recv().await {
|
||||
|
@ -109,14 +112,12 @@ impl Gamepad {
|
|||
match event.event {
|
||||
AxisChanged(LeftStickX, value, _) => Some(GamepadEvent::AxisPosition(Axis::X, value)),
|
||||
AxisChanged(LeftStickY, value, _) => Some(GamepadEvent::AxisPosition(Axis::Y, value)),
|
||||
AxisChanged(RightZ, value, _) => Some(GamepadEvent::AxisPosition(
|
||||
Axis::ZNegative,
|
||||
(1.0 + value) / 2.0,
|
||||
)),
|
||||
AxisChanged(LeftZ, value, _) => Some(GamepadEvent::AxisPosition(
|
||||
Axis::ZPositive,
|
||||
(1.0 + value) / 2.0,
|
||||
)),
|
||||
ButtonChanged(LeftTrigger2, value, _) => {
|
||||
Some(GamepadEvent::AxisPosition(Axis::ZNegative, value))
|
||||
}
|
||||
ButtonChanged(RightTrigger2, value, _) => {
|
||||
Some(GamepadEvent::AxisPosition(Axis::ZPositive, value))
|
||||
}
|
||||
ButtonPressed(gilrs::Button::Start, _) => Some(GamepadEvent::TerminatePressed),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ const TIME_PER_MOVEMENT: Duration = Duration::from_millis(30);
|
|||
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 = 10.0;
|
||||
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
|
||||
/// for the motion planner on the printer to plan ahead.
|
||||
|
@ -39,16 +39,10 @@ pub async fn jog(gamepad: Arc<Gamepad>, mut printer: Printer) -> Never {
|
|||
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 * (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),
|
||||
FULL_SCALE_SPEED_XY * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_x as f64),
|
||||
FULL_SCALE_SPEED_XY * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_y as f64),
|
||||
FULL_SCALE_SPEED_Z * (TIME_PER_MOVEMENT.as_secs_f64() / 60.0) * (setpoint_z as f64),
|
||||
);
|
||||
if distance.length() == 0.0 {
|
||||
sleep(TIME_PER_MOVEMENT).await;
|
||||
|
|
Loading…
Reference in a new issue