Some cleanup of st_get_pos functions

master
Scott Lahteine 9 years ago
parent fdee2be49c
commit e087a99a10

@ -1090,6 +1090,12 @@ float junction_deviation = 0.1;
} // plan_buffer_line() } // plan_buffer_line()
#if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA) #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
/**
* Get the XYZ position of the steppers as a vector_3.
*
* On CORE machines XYZ is derived from ABC.
*/
vector_3 plan_get_position() { vector_3 plan_get_position() {
vector_3 position = vector_3(st_get_axis_position_mm(X_AXIS), st_get_axis_position_mm(Y_AXIS), st_get_axis_position_mm(Z_AXIS)); vector_3 position = vector_3(st_get_axis_position_mm(X_AXIS), st_get_axis_position_mm(Y_AXIS), st_get_axis_position_mm(Z_AXIS));
@ -1102,8 +1108,14 @@ float junction_deviation = 0.1;
return position; return position;
} }
#endif // AUTO_BED_LEVELING_FEATURE && !DELTA #endif // AUTO_BED_LEVELING_FEATURE && !DELTA
/**
* Directly set the planner XYZ position (hence the stepper positions).
*
* On CORE machines stepper ABC will be translated from the given XYZ.
*/
#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING) #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
void plan_set_position(float x, float y, float z, const float& e) void plan_set_position(float x, float y, float z, const float& e)
#else #else

@ -1099,15 +1099,22 @@ void st_set_e_position(const long& e) {
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
} }
long st_get_position(uint8_t axis) { /**
* Get a stepper's position in steps.
*/
long st_get_position(AxisEnum axis) {
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
long count_pos = count_position[axis]; long count_pos = count_position[axis];
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
return count_pos; return count_pos;
} }
/**
* Get an axis position according to stepper position(s)
* For CORE machines apply translation from ABC to XYZ.
*/
float st_get_axis_position_mm(AxisEnum axis) { float st_get_axis_position_mm(AxisEnum axis) {
float axis_pos; float axis_steps;
#if ENABLED(COREXY) | ENABLED(COREXZ) #if ENABLED(COREXY) | ENABLED(COREXZ)
if (axis == X_AXIS || axis == CORE_AXIS_2) { if (axis == X_AXIS || axis == CORE_AXIS_2) {
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
@ -1116,14 +1123,14 @@ float st_get_axis_position_mm(AxisEnum axis) {
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
// ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1 // ((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 // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
axis_pos = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f; axis_steps = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f;
} }
else else
axis_pos = st_get_position(axis); axis_steps = st_get_position(axis);
#else #else
axis_pos = st_get_position(axis); axis_steps = st_get_position(axis);
#endif #endif
return axis_pos / axis_steps_per_unit[axis]; return axis_steps / axis_steps_per_unit[axis];
} }
void finishAndDisableSteppers() { void finishAndDisableSteppers() {

@ -61,7 +61,7 @@ void st_set_position(const long& x, const long& y, const long& z, const long& e)
void st_set_e_position(const long& e); void st_set_e_position(const long& e);
// Get current position in steps // Get current position in steps
long st_get_position(uint8_t axis); long st_get_position(AxisEnum axis);
// Get current axis position in mm // Get current axis position in mm
float st_get_axis_position_mm(AxisEnum axis); float st_get_axis_position_mm(AxisEnum axis);

Loading…
Cancel
Save