Move get_axis_position_mm to Planner (#10718)

This commit is contained in:
Scott Lahteine
2018-05-12 09:59:11 -05:00
committed by GitHub
parent a1062eec5b
commit 8f8c6a9bc4
12 changed files with 75 additions and 80 deletions

View File

@ -193,21 +193,21 @@ void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]
void get_cartesian_from_steppers() {
#if ENABLED(DELTA)
forward_kinematics_DELTA(
stepper.get_axis_position_mm(A_AXIS),
stepper.get_axis_position_mm(B_AXIS),
stepper.get_axis_position_mm(C_AXIS)
planner.get_axis_position_mm(A_AXIS),
planner.get_axis_position_mm(B_AXIS),
planner.get_axis_position_mm(C_AXIS)
);
#else
#if IS_SCARA
forward_kinematics_SCARA(
stepper.get_axis_position_degrees(A_AXIS),
stepper.get_axis_position_degrees(B_AXIS)
planner.get_axis_position_degrees(A_AXIS),
planner.get_axis_position_degrees(B_AXIS)
);
#else
cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
#endif
cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
#endif
}
@ -870,12 +870,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
}
#endif
// move duplicate extruder into correct duplication position.
planner.set_position_mm(
inactive_extruder_x_pos,
current_position[Y_AXIS],
current_position[Z_AXIS],
current_position[E_AXIS]
);
planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
planner.buffer_line(
current_position[X_AXIS] + duplicate_extruder_x_offset,
current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],

View File

@ -1299,6 +1299,37 @@ void Planner::check_axes_activity() {
#endif // PLANNER_LEVELING
/**
* Get an axis position according to stepper position(s)
* For CORE machines apply translation from ABC to XYZ.
*/
float Planner::get_axis_position_mm(const AxisEnum axis) {
float axis_steps;
#if IS_CORE
// Requesting one of the "core" axes?
if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
// Protect the access to the position.
const bool was_enabled = STEPPER_ISR_ENABLED();
DISABLE_STEPPER_DRIVER_INTERRUPT();
// ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
// ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
axis_steps = 0.5f * (
axis == CORE_AXIS_2 ? CORESIGN(stepper.position(CORE_AXIS_1) - stepper.position(CORE_AXIS_2))
: stepper.position(CORE_AXIS_1) + stepper.position(CORE_AXIS_2)
);
if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
}
else
axis_steps = stepper.position(axis);
#else
axis_steps = stepper.position(axis);
#endif
return axis_steps * steps_to_mm[axis];
}
/**
* Block until all buffered steps are executed / cleaned
*/

View File

@ -546,6 +546,17 @@ class Planner {
*/
static void sync_from_steppers();
/**
* Get an axis position according to stepper position(s)
* For CORE machines apply translation from ABC to XYZ.
*/
static float get_axis_position_mm(const AxisEnum axis);
// SCARA AB axes are in degrees, not mm
#if IS_SCARA
FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
#endif
/**
* Does the buffer have any blocks queued?
*/

View File

@ -30,7 +30,7 @@
#include "scara.h"
#include "motion.h"
#include "stepper.h"
#include "planner.h"
float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
@ -147,8 +147,8 @@ void inverse_kinematics(const float raw[XYZ]) {
}
void scara_report_positions() {
SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_degrees(A_AXIS));
SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", stepper.get_axis_position_degrees(B_AXIS));
SERIAL_PROTOCOLPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS));
SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", planner.get_axis_position_degrees(B_AXIS));
SERIAL_EOL();
}

View File

@ -2037,32 +2037,6 @@ int32_t Stepper::position(const AxisEnum axis) {
return count_pos;
}
/**
* Get an axis position according to stepper position(s)
* For CORE machines apply translation from ABC to XYZ.
*/
float Stepper::get_axis_position_mm(const AxisEnum axis) {
float axis_steps;
#if IS_CORE
// Requesting one of the "core" axes?
if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
CRITICAL_SECTION_START;
// ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
// ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
axis_steps = 0.5f * (
axis == CORE_AXIS_2 ? CORESIGN(count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2])
: count_position[CORE_AXIS_1] + count_position[CORE_AXIS_2]
);
CRITICAL_SECTION_END;
}
else
axis_steps = position(axis);
#else
axis_steps = position(axis);
#endif
return axis_steps * planner.steps_to_mm[axis];
}
void Stepper::finish_and_disable() {
planner.synchronize();
disable_all_steppers();

View File

@ -228,18 +228,6 @@ class Stepper {
//
static void report_positions();
//
// Get the position (mm) of an axis based on stepper position(s)
//
static float get_axis_position_mm(const AxisEnum axis);
//
// SCARA AB axes are in degrees, not mm
//
#if IS_SCARA
FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
#endif
//
// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
// to notify the subsystem that it is time to go to work.

View File

@ -36,7 +36,7 @@
#include "../libs/private_spi.h"
#endif
#if ENABLED(BABYSTEPPING)
#if ENABLED(BABYSTEPPING) || ENABLED(PID_EXTRUSION_SCALING)
#include "stepper.h"
#endif

View File

@ -38,10 +38,6 @@
#include "../feature/power.h"
#endif
#if ENABLED(PID_EXTRUSION_SCALING)
#include "stepper.h"
#endif
#ifndef SOFT_PWM_SCALE
#define SOFT_PWM_SCALE 0
#endif