working principle of grainging machine