* Constrain the given coordinates to the software endstops. * * For DELTA/SCARA the XY constraint is based on the smallest * radius within the set software endstops. */
| 1285 | * radius within the set software endstops. |
| 1286 | */ |
| 1287 | void apply_motion_limits(xyz_pos_t &target) { |
| 1288 | |
| 1289 | if (!soft_endstop._enabled) return; |
| 1290 | |
| 1291 | #if IS_KINEMATIC |
| 1292 | |
| 1293 | if (TERN0(DELTA, !all_axes_homed())) return; |
| 1294 | |
| 1295 | #if ALL(HAS_HOTEND_OFFSET, DELTA) |
| 1296 | // The effector center position will be the target minus the hotend offset. |
| 1297 | const xy_pos_t offs = hotend_offset[active_extruder]; |
| 1298 | #elif ENABLED(POLARGRAPH) |
| 1299 | // POLARGRAPH uses draw_area_* below... |
| 1300 | #elif ENABLED(POLAR) |
| 1301 | // For now, we don't limit POLAR |
| 1302 | #else |
| 1303 | // SCARA needs to consider the angle of the arm through the entire move, so for now use no tool offset. |
| 1304 | constexpr xy_pos_t offs{0}; |
| 1305 | #endif |
| 1306 | |
| 1307 | #if ENABLED(POLARGRAPH) |
| 1308 | LIMIT(target.x, draw_area_min.x, draw_area_max.x); |
| 1309 | LIMIT(target.y, draw_area_min.y, draw_area_max.y); |
| 1310 | #elif ENABLED(POLAR) |
| 1311 | // Motion limits are as same as cartesian limits. |
| 1312 | #else |
| 1313 | if (TERN1(IS_SCARA, axis_was_homed(X_AXIS) && axis_was_homed(Y_AXIS))) { |
| 1314 | const float dist_2 = HYPOT2(target.x - offs.x, target.y - offs.y); |
| 1315 | if (dist_2 > delta_max_radius_2) |
| 1316 | target *= float(delta_max_radius / SQRT(dist_2)); // 200 / 300 = 0.66 |
| 1317 | } |
| 1318 | #endif |
| 1319 | |
| 1320 | #else |
| 1321 | |
| 1322 | #if HAS_X_AXIS |
| 1323 | if (axis_was_homed(X_AXIS)) { |
| 1324 | #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_X) |
| 1325 | NOLESS(target.x, soft_endstop.min.x); |
| 1326 | #endif |
| 1327 | #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_X) |
| 1328 | NOMORE(target.x, soft_endstop.max.x); |
| 1329 | #endif |
| 1330 | } |
| 1331 | #endif |
| 1332 | |
| 1333 | #if HAS_Y_AXIS |
| 1334 | if (axis_was_homed(Y_AXIS)) { |
| 1335 | #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Y) |
| 1336 | NOLESS(target.y, soft_endstop.min.y); |
| 1337 | #endif |
| 1338 | #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Y) |
| 1339 | NOMORE(target.y, soft_endstop.max.y); |
| 1340 | #endif |
| 1341 | } |
| 1342 | #endif |
| 1343 | |
| 1344 | #endif |
no test coverage detected