Swash plate axial piston pumps play an important role in hydraulic systems due to their superior performance and compact design. As the controlled object of the valve-controlled hydraulic cylinder, the swash plate is affected by the complex fluid dynamics effect and the mechanical structure, which is prone to vibration, during the working process, thereby adversely affecting the dynamic performance of the system. In this paper, an electronically controlled ball screw type variable displacement mechanism with stiffness compensation is proposed. By introducing piezoelectric ceramic materials into the nut assembly, dynamic stiffness compensation of the system is achieved, which effectively changes the vibration characteristics of the swash plate and thus significantly improves the working stability of the system. Based on this, the stiffness model of a double nut ball screw is established to obtain the relationship between piezoelectric ceramics and the double nut. An asymmetric Bouc–Wen piezoelectric actuator model with nonlinear hysteresis characteristics is also established, and a particle swarm algorithm with improved inertia weights is utilized to identify the parameters of the asymmetric Bouc–Wen model. Finally, a piezoelectric actuator model based on the feedforward inverse model and a PID composite control algorithm is applied to the variable displacement mechanism system for stiffness compensation.