Recent advances in understanding fish locomotion with robotic devices have included the use of flapping foil robots that swim at a constant swimming speed. However, the speed of even steadily swimming live fishes is not constant because the fish center of mass oscillates axially throughout a tail beat cycle. In this paper, we couple a linear motor that produces controlled oscillations in the axial direction to a robotic flapping foil apparatus to model both axial and side to side oscillatory motions used by freely-swimming fishes. This experimental arrangement allows us to compensate for the substantial inertia of the carriage and motors that drive the oscillating foils. We identify a 'critically-oscillated' amplitude of axial motion at which the cyclic oscillations in axial locomotor force are greatly reduced throughout the flapping cycle. We studied the midline kinematics, power consumption and wake flow patterns of non-rigid foils with different lengths and flexural stiffnesses at a variety of axial oscillation amplitudes. We found that 'critically-oscillated' peak-to-peak axial amplitudes on the order of 1.0 mm and at the correct phase are sufficient to mimic center of mass motion, and that such amplitudes are similar to center of mass oscillations recorded for freely-swimming live fishes. Flow visualization revealed differences in wake flows of flexible foils between the 'non-oscillated' and 'critically-oscillated' states. Inertia-compensating methods provide a novel experimental approach for studying aquatic animal swimming, and allow instrumented robotic swimmers to display center of mass oscillations similar to those exhibited by freely-swimming fishes.