* 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. */
| 1204 | * at the same positions relative to the machine. |
| 1205 | */ |
| 1206 | void update_software_endstops(const AxisEnum axis |
| 1207 | OPTARG(HAS_HOTEND_OFFSET, const uint8_t old_tool_index/*=0*/, const uint8_t new_tool_index/*=0*/) |
| 1208 | ) { |
| 1209 | |
| 1210 | #if ENABLED(DUAL_X_CARRIAGE) |
| 1211 | |
| 1212 | if (axis == X_AXIS) { |
| 1213 | |
| 1214 | // In Dual X mode hotend_offset[X] is T1's home position |
| 1215 | const float dual_max_x = _MAX(hotend_offset[1].x, X2_MAX_POS); |
| 1216 | |
| 1217 | if (new_tool_index != 0) { |
| 1218 | // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger) |
| 1219 | soft_endstop.min.x = X2_MIN_POS; |
| 1220 | soft_endstop.max.x = dual_max_x; |
| 1221 | } |
| 1222 | else if (idex_is_duplicating()) { |
| 1223 | // In Duplication Mode, T0 can move as far left as X1_MIN_POS |
| 1224 | // but not so far to the right that T1 would move past the end |
| 1225 | soft_endstop.min.x = X1_MIN_POS; |
| 1226 | soft_endstop.max.x = _MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset); |
| 1227 | } |
| 1228 | else { |
| 1229 | // In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS |
| 1230 | soft_endstop.min.x = X1_MIN_POS; |
| 1231 | soft_endstop.max.x = X1_MAX_POS; |
| 1232 | } |
| 1233 | |
| 1234 | } |
| 1235 | |
| 1236 | #elif ENABLED(DELTA) |
| 1237 | |
| 1238 | soft_endstop.min[axis] = base_min_pos(axis); |
| 1239 | soft_endstop.max[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_max_pos(axis); |
| 1240 | |
| 1241 | switch (axis) { |
| 1242 | case X_AXIS: |
| 1243 | case Y_AXIS: |
| 1244 | // Get a minimum radius for clamping |
| 1245 | delta_max_radius = _MIN(ABS(_MAX(soft_endstop.min.x, soft_endstop.min.y)), soft_endstop.max.x, soft_endstop.max.y); |
| 1246 | delta_max_radius_2 = sq(delta_max_radius); |
| 1247 | break; |
| 1248 | case Z_AXIS: |
| 1249 | refresh_delta_clip_start_height(); |
| 1250 | default: break; |
| 1251 | } |
| 1252 | |
| 1253 | #elif HAS_HOTEND_OFFSET |
| 1254 | |
| 1255 | // Software endstops are relative to the tool 0 workspace, so |
| 1256 | // the movement limits must be shifted by the tool offset to |
| 1257 | // retain the same physical limit when other tools are selected. |
| 1258 | |
| 1259 | if (new_tool_index == old_tool_index || axis == Z_AXIS) { // The Z axis is "special" and shouldn't be modified |
| 1260 | const float offs = (axis == Z_AXIS) ? 0 : hotend_offset[active_extruder][axis]; |
| 1261 | soft_endstop.min[axis] = base_min_pos(axis) + offs; |
| 1262 | soft_endstop.max[axis] = base_max_pos(axis) + offs; |
| 1263 | } |
no test coverage detected