You home to max, that sets max position from their it calculates min position
I would guess #define X_MAX_POS 317 should be #define X_MAX_POS 327
I would guess #define X_MAX_POS 317 should be #define X_MAX_POS 327