A look-ahead controller is developed for a heavy diesel truck that utilizes information about the road topography ahead of the vehicle when the route is known. A dedicated prediction model is formulated where special attention is given to properly include gear shifting. The nature of the problem is analyzed for the purpose of optimization, and a well performing dynamic programming algorithm is tailored. A key step for satisfactory solutions with a sufficiently low computational effort is to avoid numerical problems. The focus here is the choice of discretization method, and it turns out that a basic analysis give decisive insight into the interplay between the criterion and the discretization errors. The resulting algorithm is demonstrated to perform well in real on-line tests on a highway.