For a magnetocardiography (MCG) system inside a magnetically shielded room (MSR), the residual field should be further suppressed to obtain high-quality MCG signals. In this paper, a compensation system has been developed based on the bi-planar coil and the PID controller. The bi-planar coil, derived from the target-field theory and the Tikhonov regularization method, is utilized to generate magnetic field with high uniformity in the pre-defined target region. And the PID controller is introduced to provide dynamic compensation current for the coil, according to the residual field change monitored by a reference SQUID magnetometer. The measurement results show that the noise suppression ratio (NSR) can reach above 20 dB in the low-frequency range from 0.1 to 50 Hz. The DC component and the fluctuation of the residual field in time-domain can be respectively suppressed to 0 pT and 4 pT, indicating that this proposed compensation method is useful for MCG measurement.