getSpeed function