MCPcopy Create free account
hub / github.com/MarlinFirmware/Marlin / apply_motion_limits

Function apply_motion_limits

Marlin/src/module/motion.cpp:1287–1416  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

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

Callers 8

cubic_b_splineFunction · 0.85
motion.cppFile · 0.85
tool_changeFunction · 0.85
M115Method · 0.85
M360Method · 0.85
plan_arcFunction · 0.85
M240Method · 0.85
inject_jog_movesMethod · 0.85

Calls 5

all_axes_homedFunction · 0.85
LIMITFunction · 0.85
axis_was_homedFunction · 0.85
NOLESSFunction · 0.85
NOMOREFunction · 0.85

Tested by

no test coverage detected