Optimize spindle speed as function of calculated motion error