Skip to content

Commit

Permalink
merge followup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 11, 2022
1 parent 5b853a2 commit 55928d8
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/G26.cpp
Expand Up @@ -306,7 +306,7 @@ typedef struct {
LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1);
#endif

if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y))
if (position_is_reachable(s) && position_is_reachable(e))
print_line_from_here_to_there(s, e);
}
}
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/gcode/calibrate/M665.cpp
Expand Up @@ -174,12 +174,12 @@
void GcodeSuite::M665_report(const bool forReplay/*=true*/) {
report_heading_etc(forReplay, F(STR_POLARGRAPH_SETTINGS));
SERIAL_ECHOLNPGM_P(
PSTR(" M665 S"), LINEAR_UNIT(segments_per_second),
PSTR(" L"), LINEAR_UNIT(draw_area_min.x),
PSTR(" R"), LINEAR_UNIT(draw_area_max.x),
SP_T_STR, LINEAR_UNIT(draw_area_max.y),
SP_B_STR, LINEAR_UNIT(draw_area_min.y),
PSTR(" H"), LINEAR_UNIT(polargraph_max_belt_len)
PSTR(" M665 S"), LINEAR_UNIT(segments_per_second),
PSTR(" L"), LINEAR_UNIT(draw_area_min.x),
PSTR(" R"), LINEAR_UNIT(draw_area_max.x),
SP_T_STR, LINEAR_UNIT(draw_area_max.y),
SP_B_STR, LINEAR_UNIT(draw_area_min.y),
PSTR(" H"), LINEAR_UNIT(polargraph_max_belt_len)
);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Expand Up @@ -933,7 +933,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
#endif

#if IS_KINEMATIC
case 665: M665(); break; // M665: Set Delta/SCARA/Polargraph parameters
case 665: M665(); break; // M665: Set Kinematics parameters
#endif

#if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
Expand Down
75 changes: 66 additions & 9 deletions Marlin/src/module/motion.cpp
Expand Up @@ -300,15 +300,72 @@ void report_current_position_projected() {

#endif

#if ENABLED(POLARGRAPH)
bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset/*=0*/) {
const float x1 = rx - (draw_area_min.x), x2 = (draw_area_max.x) - rx, y = ry - (draw_area_max.y),
a = HYPOT(x1, y), b = HYPOT(x2, y);
return a < (polargraph_max_belt_len) + 1
&& b < (polargraph_max_belt_len) + 1
&& (a + b) > _MIN(draw_area_size.x, draw_area_size.y);
}
#endif
#if IS_KINEMATIC

bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset/*=0*/) {

bool can_reach;

#if ENABLED(DELTA)

can_reach = HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);

#elif ENABLED(AXEL_TPARA)

const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y);
can_reach = (
R2 <= sq(L1 + L2) - inset
#if MIDDLE_DEAD_ZONE_R > 0
&& R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
#endif
);

#elif IS_SCARA

const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
can_reach = (
R2 <= sq(L1 + L2) - inset
#if MIDDLE_DEAD_ZONE_R > 0
&& R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
#endif
);

#elif ENABLED(POLARGRAPH)

const float d1 = rx - (draw_area_min.x),
d2 = (draw_area_max.x) - rx,
y = ry - (draw_area_max.y),
a = HYPOT(d1, y),
b = HYPOT(d2, y);

can_reach = (
a < polargraph_max_belt_len + 1
&& b < polargraph_max_belt_len + 1
&& (a + b) > _MIN(draw_area_size.x, draw_area_size.y)
);

#endif

return can_reach;
}

#else // CARTESIAN

// Return true if the given position is within the machine bounds.
bool position_is_reachable(const_float_t rx, const_float_t ry) {
if (!COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
#if ENABLED(DUAL_X_CARRIAGE)
if (active_extruder)
return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
else
return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
#else
return COORDINATE_OKAY(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
#endif
}

#endif // CARTESIAN


void home_if_needed(const bool keeplev/*=false*/) {
if (!all_axes_trusted()) gcode.home_all_axes(keeplev);
Expand Down
51 changes: 6 additions & 45 deletions Marlin/src/module/motion.h
Expand Up @@ -548,61 +548,22 @@ void home_if_needed(const bool keeplev=false);
extern abc_pos_t scara_home_offset; // A and B angular offsets, Z mm offset
#endif

#if ENABLED(POLARGRAPH)
bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset=0);
#else

// Return true if the given point is within the printable area
inline bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset=0) {
#if ENABLED(DELTA)

return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);

#elif ENABLED(AXEL_TPARA)

const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y);
return (
R2 <= sq(L1 + L2) - inset
#if MIDDLE_DEAD_ZONE_R > 0
&& R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
#endif
);

#elif IS_SCARA

const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
return (
R2 <= sq(L1 + L2) - inset
#if MIDDLE_DEAD_ZONE_R > 0
&& R2 >= sq(float(MIDDLE_DEAD_ZONE_R))
#endif
);
bool position_is_reachable(const_float_t rx, const_float_t ry, const float inset=0);

#endif
}
#endif

inline bool position_is_reachable(const xy_pos_t &pos, const float inset=0) {
return position_is_reachable(pos.x, pos.y, inset);
}

#else // CARTESIAN
#else

// Return true if the given position is within the machine bounds.
inline bool position_is_reachable(const_float_t rx, const_float_t ry) {
if (!COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
#if ENABLED(DUAL_X_CARRIAGE)
if (active_extruder)
return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
else
return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
#else
return COORDINATE_OKAY(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
#endif
bool position_is_reachable(const_float_t rx, const_float_t ry);
inline bool position_is_reachable(const xy_pos_t &pos) {
return position_is_reachable(pos.x, pos.y);
}
inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }

#endif // CARTESIAN
#endif

/**
* Duplication mode
Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/module/polargraph.cpp
Expand Up @@ -38,9 +38,12 @@
#include "../MarlinCore.h"

float segments_per_second; // Initialized by settings.load()
xy_pos_t draw_area_min = { X_MIN_POS, Y_MIN_POS };
xy_pos_t draw_area_max = { X_MAX_POS, Y_MAX_POS };

xy_pos_t draw_area_min = { X_MIN_POS, Y_MIN_POS },
draw_area_max = { X_MAX_POS, Y_MAX_POS };

xy_float_t draw_area_size = { X_MAX_POS - X_MIN_POS, Y_MAX_POS - Y_MIN_POS };

float polargraph_max_belt_len = HYPOT(draw_area_size.x, draw_area_size.y);

void inverse_kinematics(const xyz_pos_t &raw) {
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/module/polargraph.h
Expand Up @@ -29,8 +29,7 @@
#include "../core/macros.h"

extern float segments_per_second;
extern xy_pos_t draw_area_min;
extern xy_pos_t draw_area_max;
extern xy_pos_t draw_area_min, draw_area_max;
extern xy_float_t draw_area_size;
extern float polargraph_max_belt_len;

Expand Down

0 comments on commit 55928d8

Please sign in to comment.