Revive SCARA's home offset (unimplemented)

This commit is contained in:
Scott Lahteine
2018-11-03 03:56:33 -05:00
parent 2c9586be0c
commit d1ff22b983
13 changed files with 193 additions and 140 deletions

View File

@ -124,7 +124,7 @@ typedef struct SettingsDataStruct {
float planner_max_jerk[XYZE], // M205 XYZE planner.max_jerk[XYZE]
planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
float home_offset[XYZ]; // M206 XYZ
float home_offset[XYZ]; // M206 XYZ / M665 TPZ
#if HAS_HOTEND_OFFSET
float hotend_offset[XYZ][HOTENDS - 1]; // M218 XYZ
@ -309,10 +309,11 @@ void MarlinSettings::postprocess() {
planner.refresh_e_factor(i);
#endif
#if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
// Software endstops depend on home_offset
LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
#endif
// Software endstops depend on home_offset
LOOP_XYZ(i) {
update_workspace_offset((AxisEnum)i);
update_software_endstops((AxisEnum)i);
}
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
set_z_fade_height(new_z_fade_height, false); // false = no report
@ -453,10 +454,14 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(home_offset);
#if !HAS_HOME_OFFSET
const float home_offset[XYZ] = { 0 };
#if HAS_SCARA_OFFSET
EEPROM_WRITE(scara_home_offset);
#else
#if !HAS_HOME_OFFSET
const float home_offset[XYZ] = { 0 };
#endif
EEPROM_WRITE(home_offset);
#endif
EEPROM_WRITE(home_offset);
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
@ -1062,15 +1067,19 @@ void MarlinSettings::postprocess() {
}
//
// Home Offset (M206)
// Home Offset (M206 / M665)
//
{
_FIELD_TEST(home_offset);
#if !HAS_HOME_OFFSET
float home_offset[XYZ];
#if HAS_SCARA_OFFSET
EEPROM_READ(scara_home_offset);
#else
#if !HAS_HOME_OFFSET
float home_offset[XYZ];
#endif
EEPROM_READ(home_offset);
#endif
EEPROM_READ(home_offset);
}
//
@ -1826,7 +1835,9 @@ void MarlinSettings::reset(PORTARG_SOLO) {
planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
#endif
#if HAS_HOME_OFFSET
#if HAS_SCARA_OFFSET
ZERO(scara_home_offset);
#elif HAS_HOME_OFFSET
ZERO(home_offset);
#endif
@ -2430,7 +2441,20 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#if ENABLED(DELTA)
#if HAS_SCARA_OFFSET
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM_P(port, "SCARA settings: S<seg-per-sec> P<theta-psi-offset> T<theta-offset>");
}
CONFIG_ECHO_START;
SERIAL_ECHOPAIR_P(port, " M665 S", delta_segments_per_second);
SERIAL_ECHOPAIR_P(port, " P", scara_home_offset[A_AXIS]);
SERIAL_ECHOPAIR_P(port, " T", scara_home_offset[B_AXIS]);
SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(scara_home_offset[Z_AXIS]));
SERIAL_EOL_P(port);
#elif ENABLED(DELTA)
if (!forReplay) {
CONFIG_ECHO_START;

View File

@ -129,11 +129,14 @@ const float homing_feedrate_mm_s[4] PROGMEM = {
// Cartesian conversion result goes here:
float cartes[XYZ];
// Until kinematics.cpp is created, create this here
#if IS_KINEMATIC
float delta[ABC];
#endif
#if HAS_SCARA_OFFSET
float scara_home_offset[ABC];
#endif
/**
* The workspace can be offset by some commands, or
* these offsets may be omitted to save on computation.
@ -452,15 +455,14 @@ void bracket_probe_move(const bool before) {
void setup_for_endstop_or_probe_move() { bracket_probe_move(true); }
void clean_up_after_endstop_or_probe_move() { bracket_probe_move(false); }
// Software Endstops are based on the configured limits.
float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
#if HAS_SOFTWARE_ENDSTOPS
// Software Endstops are based on the configured limits.
bool soft_endstops_enabled = true;
// Software Endstops are based on the configured limits.
float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
#if IS_KINEMATIC
float soft_endstop_radius, soft_endstop_radius_2;
#endif
@ -502,6 +504,79 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
#endif
}
/**
* Software endstops can be used to monitor the open end of
* an axis that has a hardware endstop on the other end. Or
* they can prevent axes from moving past endstops and grinding.
*
* To keep doing their job as the coordinate system changes,
* the software endstop positions must be refreshed to remain
* at the same positions relative to the machine.
*/
void update_software_endstops(const AxisEnum axis) {
#if ENABLED(DUAL_X_CARRIAGE)
if (axis == X_AXIS) {
// In Dual X mode hotend_offset[X] is T1's home position
const float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS);
if (active_extruder != 0) {
// T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
soft_endstop_min[X_AXIS] = X2_MIN_POS;
soft_endstop_max[X_AXIS] = dual_max_x;
}
else if (dxc_is_duplicating()) {
// In Duplication Mode, T0 can move as far left as X1_MIN_POS
// but not so far to the right that T1 would move past the end
soft_endstop_min[X_AXIS] = X1_MIN_POS;
soft_endstop_max[X_AXIS] = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
}
else {
// In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
soft_endstop_min[X_AXIS] = X1_MIN_POS;
soft_endstop_max[X_AXIS] = X1_MAX_POS;
}
}
#elif ENABLED(DELTA)
soft_endstop_min[axis] = base_min_pos(axis);
soft_endstop_max[axis] = (axis == Z_AXIS ? delta_height
#if HAS_BED_PROBE
- zprobe_zoffset + Z_PROBE_OFFSET_FROM_EXTRUDER
#endif
: base_max_pos(axis));
switch (axis) {
case X_AXIS:
case Y_AXIS:
// Get a minimum radius for clamping
soft_endstop_radius = MIN(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
soft_endstop_radius_2 = sq(soft_endstop_radius);
break;
case Z_AXIS:
delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
default: break;
}
#else
soft_endstop_min[axis] = base_min_pos(axis);
soft_endstop_max[axis] = base_max_pos(axis);
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("For ", axis_codes[axis]);
SERIAL_ECHOPAIR(" axis:\n soft_endstop_min = ", soft_endstop_min[axis]);
SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
}
#endif
}
#endif
#if !UBL_SEGMENTED
@ -1154,7 +1229,7 @@ void set_axis_is_at_home(const AxisEnum axis) {
#if HAS_POSITION_SHIFT
position_shift[axis] = 0;
update_software_endstops(axis);
update_workspace_offset(axis);
#endif
#if ENABLED(DUAL_X_CARRIAGE)
@ -1504,89 +1579,18 @@ void homeaxis(const AxisEnum axis) {
#endif
} // homeaxis()
#if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
/**
* Software endstops can be used to monitor the open end of
* an axis that has a hardware endstop on the other end. Or
* they can prevent axes from moving past endstops and grinding.
*
* To keep doing their job as the coordinate system changes,
* the software endstop positions must be refreshed to remain
* at the same positions relative to the machine.
*/
void update_software_endstops(const AxisEnum axis) {
#if HAS_HOME_OFFSET
workspace_offset[axis] = home_offset[axis] + position_shift[axis];
#endif
#if ENABLED(DUAL_X_CARRIAGE)
if (axis == X_AXIS) {
// In Dual X mode hotend_offset[X] is T1's home position
const float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS);
if (active_extruder != 0) {
// T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
soft_endstop_min[X_AXIS] = X2_MIN_POS;
soft_endstop_max[X_AXIS] = dual_max_x;
}
else if (dxc_is_duplicating()) {
// In Duplication Mode, T0 can move as far left as X1_MIN_POS
// but not so far to the right that T1 would move past the end
soft_endstop_min[X_AXIS] = X1_MIN_POS;
soft_endstop_max[X_AXIS] = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
}
else {
// In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
soft_endstop_min[X_AXIS] = X1_MIN_POS;
soft_endstop_max[X_AXIS] = X1_MAX_POS;
}
}
#elif ENABLED(DELTA)
soft_endstop_min[axis] = base_min_pos(axis);
soft_endstop_max[axis] = (axis == Z_AXIS ? delta_height
#if HAS_BED_PROBE
- zprobe_zoffset + Z_PROBE_OFFSET_FROM_EXTRUDER
#endif
: base_max_pos(axis));
#else
soft_endstop_min[axis] = base_min_pos(axis);
soft_endstop_max[axis] = base_max_pos(axis);
#endif
#if HAS_WORKSPACE_OFFSET
void update_workspace_offset(const AxisEnum axis) {
workspace_offset[axis] = home_offset[axis] + position_shift[axis];
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("For ", axis_codes[axis]);
#if HAS_HOME_OFFSET
SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
#endif
#if HAS_POSITION_SHIFT
SERIAL_ECHOPAIR("\n position_shift = ", position_shift[axis]);
#endif
SERIAL_ECHOPAIR("\n soft_endstop_min = ", soft_endstop_min[axis]);
SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
}
#endif
#if ENABLED(DELTA)
switch (axis) {
#if HAS_SOFTWARE_ENDSTOPS
case X_AXIS:
case Y_AXIS:
// Get a minimum radius for clamping
soft_endstop_radius = MIN(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
soft_endstop_radius_2 = sq(soft_endstop_radius);
break;
#endif
case Z_AXIS:
delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
default: break;
SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
SERIAL_ECHOLNPAIR("\n position_shift = ", position_shift[axis]);
}
#endif
}
#endif // HAS_WORKSPACE_OFFSET || DUAL_X_CARRIAGE || DELTA
#endif
#if HAS_M206_COMMAND
/**
@ -1595,6 +1599,6 @@ void homeaxis(const AxisEnum axis) {
*/
void set_home_offset(const AxisEnum axis, const float v) {
home_offset[axis] = v;
update_software_endstops(axis);
update_workspace_offset(axis);
}
#endif // HAS_M206_COMMAND

View File

@ -93,8 +93,6 @@ extern int16_t feedrate_percentage;
extern float hotend_offset[XYZ][HOTENDS];
#endif
extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float(p); }
FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte(p); }
@ -110,12 +108,23 @@ XYZ_DEFS(float, max_length, MAX_LENGTH);
XYZ_DEFS(float, home_bump_mm, HOME_BUMP_MM);
XYZ_DEFS(signed char, home_dir, HOME_DIR);
#if HAS_WORKSPACE_OFFSET
void update_workspace_offset(const AxisEnum axis);
#else
#define update_workspace_offset(x) NOOP
#endif
#if HAS_SOFTWARE_ENDSTOPS
extern bool soft_endstops_enabled;
extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
void clamp_to_software_endstops(float target[XYZ]);
void update_software_endstops(const AxisEnum axis);
#else
constexpr bool soft_endstops_enabled = false;
constexpr float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
#define clamp_to_software_endstops(x) NOOP
#define update_software_endstops(x) NOOP
#endif
void report_current_position();
@ -252,6 +261,10 @@ void homeaxis(const AxisEnum axis);
extern const float L1, L2;
#endif
#if HAS_SCARA_OFFSET
extern float scara_home_offset[ABC]; // A and B angular offsets, Z mm offset
#endif
// Return true if the given point is within the printable area
inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
#if ENABLED(DELTA)
@ -354,10 +367,6 @@ void homeaxis(const AxisEnum axis);
#endif
#if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
void update_software_endstops(const AxisEnum axis);
#endif
#if HAS_M206_COMMAND
void set_home_offset(const AxisEnum axis, const float v);
#endif

View File

@ -60,12 +60,7 @@ void scara_set_axis_is_at_home(const AxisEnum axis) {
current_position[axis] = cartes[axis];
/**
* SCARA home positions are based on configuration since the actual
* limits are determined by the inverse kinematic transform.
*/
soft_endstop_min[axis] = base_min_pos(axis); // + (cartes[axis] - base_home_pos(axis));
soft_endstop_max[axis] = base_max_pos(axis); // + (cartes[axis] - base_home_pos(axis));
update_software_endstops(axis);
}
}

View File

@ -623,7 +623,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
feedrate_mm_s = old_feedrate_mm_s;
#if HAS_SOFTWARE_ENDSTOPS && ENABLED(DUAL_X_CARRIAGE)
#if ENABLED(DUAL_X_CARRIAGE)
update_software_endstops(X_AXIS);
#endif