Stroke measurement in hydraulic cylinders