This paper presents a stable control method for free-piston linear generator (FPLG) based on online trajectory planning. The single cycle movement of the piston is divided into two stages. The former adopts a constant electromagnetic force to adjust the engine load, and the latter adopts the method of online trajectory tracking control to realize the accurate control of top dead center (TDC) and bottom dead center (BDC) positions. In particular, misfire, incomplete combustion, deflagration and other conditions are observed by the mid-point velocity during the expansion stroke after the completion of combustion process. Besides, the online trajectory planning based on the midpoint velocity of the piston expansion stroke, the location of the target dead point and the dynamics model of piston. Furthermore, the reference trajectory is optimized online by the errors of dead point position iteratively. Finally, based on the established model, the stable operation of the system is realized under the fuel mass fluctuation of 15%. The result shows the validation of the proposed control method.