This example models control of a system that consists of two masses attached on either side of a spring. A control loop damps the oscillation of the spring that results when an external force acts on the system. The model uses Callback Button blocks to provide an interface for you to adjust the frequency of the external force before and during simulation.
The model for this example adds two Callback Button blocks, labeled
Frequency + and
Frequency - to the Double Mass-Spring System model. When you simulate the model, an animation visualizes the system.
Click the button labeled
Frequency + to increase the oscillation frequency. When you adjust the frequency of the external force, the Callback Button block displays a message in the command window indicating the new frequency value. You can adjust the parameter during a simulation and while the model is idle.
Both Callback Button blocks in this model are configured with a
ClickFcn that responds to your clicks and a
PressFcn that executes when you press the Callback Button block. Double-click the
Frequency + Callback Button block to view its parameters.
When you click the
Frequency + Callback Button block, the
ClickFcn increases the frequency of the external force by
0.1. If you press the Callback Button block for more than the
500 ms Press Delay, the
PressFcn increases the frequency of the external force by
0.1 every second.