Your code is in inches as indicated by the G20 command at the top. G21 is for mm. Its a modal command which means that you'll stay in inches until its changed by a G21. Not sure how the Duet handles homing, but if it doesnt specify G21, then your homing command is running in inches and that's probably why you are slamming into things. i.e. instead of moving to 10 mm its trying to move to 10 inches.