Add custom types for position (#15204)

This commit is contained in:
Scott Lahteine
2019-09-29 04:25:39 -05:00
committed by GitHub
parent 43d6e9fa43
commit 50e4545255
227 changed files with 3147 additions and 3264 deletions

View File

@ -30,7 +30,6 @@ Nozzle nozzle;
#include "../Marlin.h"
#include "../module/motion.h"
#include "point_t.h"
#if ENABLED(NOZZLE_CLEAN_FEATURE)
@ -38,30 +37,30 @@ Nozzle nozzle;
* @brief Stroke clean pattern
* @details Wipes the nozzle back and forth in a linear movement
*
* @param start point_t defining the starting point
* @param end point_t defining the ending point
* @param start xyz_pos_t defining the starting point
* @param end xyz_pos_t defining the ending point
* @param strokes number of strokes to execute
*/
void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) {
#if ENABLED(NOZZLE_CLEAN_GOBACK)
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
const xyz_pos_t oldpos = current_position;
#endif
// Move to the starting point
#if ENABLED(NOZZLE_CLEAN_NO_Z)
do_blocking_move_to_xy(start.x, start.y);
do_blocking_move_to_xy(start);
#else
do_blocking_move_to(start.x, start.y, start.z);
do_blocking_move_to(start);
#endif
// Start the stroke pattern
for (uint8_t i = 0; i < (strokes >> 1); i++) {
do_blocking_move_to_xy(end.x, end.y);
do_blocking_move_to_xy(start.x, start.y);
do_blocking_move_to_xy(end);
do_blocking_move_to_xy(start);
}
#if ENABLED(NOZZLE_CLEAN_GOBACK)
do_blocking_move_to(ix, iy, iz);
do_blocking_move_to(oldpos);
#endif
}
@ -69,29 +68,29 @@ Nozzle nozzle;
* @brief Zig-zag clean pattern
* @details Apply a zig-zag cleaning pattern
*
* @param start point_t defining the starting point
* @param end point_t defining the ending point
* @param start xyz_pos_t defining the starting point
* @param end xyz_pos_t defining the ending point
* @param strokes number of strokes to execute
* @param objects number of triangles to do
*/
void Nozzle::zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
const float diffx = end.x - start.x, diffy = end.y - start.y;
if (!diffx || !diffy) return;
void Nozzle::zigzag(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes, const uint8_t &objects) {
const xy_pos_t diff = end - start;
if (!diff.x || !diff.y) return;
#if ENABLED(NOZZLE_CLEAN_GOBACK)
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
const xyz_pos_t back = current_position;
#endif
#if ENABLED(NOZZLE_CLEAN_NO_Z)
do_blocking_move_to_xy(start.x, start.y);
do_blocking_move_to_xy(start);
#else
do_blocking_move_to(start.x, start.y, start.z);
do_blocking_move_to(start);
#endif
const uint8_t zigs = objects << 1;
const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe?
const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
const point_t *side;
const bool horiz = ABS(diff.x) >= ABS(diff.y); // Do a horizontal wipe?
const float P = (horiz ? diff.x : diff.y) / zigs; // Period of each zig / zag
const xyz_pos_t *side;
for (uint8_t j = 0; j < strokes; j++) {
for (int8_t i = 0; i < zigs; i++) {
side = (i & 1) ? &end : &start;
@ -110,7 +109,7 @@ Nozzle nozzle;
}
#if ENABLED(NOZZLE_CLEAN_GOBACK)
do_blocking_move_to(ix, iy, iz);
do_blocking_move_to(back);
#endif
}
@ -118,21 +117,21 @@ Nozzle nozzle;
* @brief Circular clean pattern
* @details Apply a circular cleaning pattern
*
* @param start point_t defining the middle of circle
* @param start xyz_pos_t defining the middle of circle
* @param strokes number of strokes to execute
* @param radius radius of circle
*/
void Nozzle::circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
void Nozzle::circle(const xyz_pos_t &start, const xyz_pos_t &middle, const uint8_t &strokes, const float &radius) {
if (strokes == 0) return;
#if ENABLED(NOZZLE_CLEAN_GOBACK)
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
const xyz_pos_t back = current_position;
#endif
#if ENABLED(NOZZLE_CLEAN_NO_Z)
do_blocking_move_to_xy(start.x, start.y);
do_blocking_move_to_xy(start);
#else
do_blocking_move_to(start.x, start.y, start.z);
do_blocking_move_to(start);
#endif
for (uint8_t s = 0; s < strokes; s++)
@ -143,10 +142,10 @@ Nozzle nozzle;
);
// Let's be safe
do_blocking_move_to_xy(start.x, start.y);
do_blocking_move_to_xy(start);
#if ENABLED(NOZZLE_CLEAN_GOBACK)
do_blocking_move_to(ix, iy, iz);
do_blocking_move_to(back);
#endif
}
@ -158,21 +157,21 @@ Nozzle nozzle;
* @param argument depends on the cleaning pattern
*/
void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) {
point_t start = NOZZLE_CLEAN_START_POINT;
point_t end = NOZZLE_CLEAN_END_POINT;
xyz_pos_t start = NOZZLE_CLEAN_START_POINT, end = NOZZLE_CLEAN_END_POINT;
if (pattern == 2) {
if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
SERIAL_ECHOLNPGM("Warning : Clean Circle requires XY");
return;
}
end = NOZZLE_CLEAN_CIRCLE_MIDDLE;
constexpr xyz_pos_t middle NOZZLE_CLEAN_CIRCLE_MIDDLE;
end = middle;
}
else {
if (!TEST(cleans, X_AXIS)) start.x = end.x = current_position[X_AXIS];
if (!TEST(cleans, Y_AXIS)) start.y = end.y = current_position[Y_AXIS];
if (!TEST(cleans, X_AXIS)) start.x = end.x = current_position.x;
if (!TEST(cleans, Y_AXIS)) start.y = end.y = current_position.y;
}
if (!TEST(cleans, Z_AXIS)) start.z = end.z = current_position[Z_AXIS];
if (!TEST(cleans, Z_AXIS)) start.z = end.z = current_position.z;
switch (pattern) {
case 1: zigzag(start, end, strokes, objects); break;
@ -185,7 +184,7 @@ Nozzle nozzle;
#if ENABLED(NOZZLE_PARK_FEATURE)
void Nozzle::park(const uint8_t z_action, const point_t &park/*=NOZZLE_PARK_POINT*/) {
void Nozzle::park(const uint8_t z_action, const xyz_pos_t &park/*=NOZZLE_PARK_POINT*/) {
constexpr feedRate_t fr_xy = NOZZLE_PARK_XY_FEEDRATE, fr_z = NOZZLE_PARK_Z_FEEDRATE;
switch (z_action) {
@ -194,14 +193,14 @@ Nozzle nozzle;
break;
case 2: // Raise by Z-park height
do_blocking_move_to_z(_MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
do_blocking_move_to_z(_MIN(current_position.z + park.z, Z_MAX_POS), fr_z);
break;
default: // Raise to at least the Z-park height
do_blocking_move_to_z(_MAX(park.z, current_position[Z_AXIS]), fr_z);
do_blocking_move_to_z(_MAX(park.z, current_position.z), fr_z);
}
do_blocking_move_to_xy(park.x, park.y, fr_xy);
do_blocking_move_to_xy(park, fr_xy);
report_current_position();
}