Some challenges in the development of autonomous vehicles, such as generating a model representing the dynamics of the speed, designing a longitudinal controller, and the optimization method, are still explored until now. In this paper, a longitudinal controller based on the proportional-integral-derivative controller with an additional feedforward term is proposed, where the Flower Pollination Algorithm is employed for optimizing the controller. The feed-forward term and the model used in the optimization are generated using the data-driven approach. For the optimization, a cost function considering mean absolute error and mean absolute jerk will be minimized. The simulation study was performed using the CARLA simulator, and the results show that the proposed scheme represents the dynamics of the speed very well inside the range of the training data and does not overfit the training data. It is also demonstrated that the proposed longitudinal controller can track the desired speed satisfactorily in a non-straight path.