2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
In order to introduce the steps of building and simulating physical models, here is the example model provided by Simulink.Mass-Spring-Damper with ControllerFor example, the following figure shows the established model.
The detailed physical modeling and simulation analysis steps are as follows:
Step 1: Usessc_new Create a new model
usessc_new is the best way to start building a Simscape™ model. Using this function helps ensure that you use the recommended default settings for your model.ssc_new It will automatically:
In MATLAB® In the command line window, type:
ssc_new
The default solver setting for newly created unnamed models isVariableStepAuto, the model contains a Solver Configuration block, a Simulink-PS Converter block, and a PS-Simulink Converter block connected to a Scope block.
The Resources section at the bottom of the model window provides links to related module libraries and documentation topics.
Step 2: Assemble the physical network
To model your system, you add blocks from the Simscape library to your model and then connect those blocks to physical networks. In the schematic diagram you create, the lines connecting the blocks represent the physical connections that exist between components in the real system you are modeling. In other words, a Simscape diagram simulates the physical system layout.
When constructing a network, it is important to add domain-specific reference blocks, such as Electrical Reference, Mechanical Translational Reference, and so on.
To adjust the visual presentation of the model, simplify the names of the Spring and Damper blocks, as shown. To make the name of the Mass block appear along with the Spring and Damper blocks, right-click the Mass block and selectFormat > Display module name > Open。
Step 3: Adjust module parameters and variable targets
Simscape Blocks represent generic components with default initial values for block parameters and variables. You can adjust these values to suit your application or match them to the manufacturer datasheet.
To view and modify block parameter values and initial targets for block variables, double-click a block to open its dialog box.SettingsTab.
For most Simscape blocks, the block dialog box contains the same information and layout as the block Property Inspector. By default, changing a value in the Property Inspector applies the new value immediately. For greater control, it is recommended that you clear theAutomatic ApplicationCheck box to enableResetandapplicationbutton. This is particularly useful when working with complex modules, as you can change multiple parameters at once. Change the parameter value to match the manufacturer datasheet, review the entire set, and then clickapplication. ClearAutomatic ApplicationAfter you clear a check box, the check box remains cleared during your MATLAB session.
To view a description of a module, clickDescriptiontab. This tab also containsSource codeClick this link to open the Simscape source file for this block in the MATLAB Editor.
If a module has no parameters or variable targets that can be set, the module dialog box has noSettingstab, onlyDescriptionTab.
To view the documentation for a module, click the question mark in the upper right corner of the module dialog box.button.
In this model, you will adjust the parameters that control the mass, spring stiffness, and damping coefficient. You will also specify the initial velocity of the mass by adjusting the corresponding variable objective.
400 N/m
,then clickapplication。100 N/(m/s)
。3.6 kg
。High
”, which means that the solver will try to exactly satisfy this initial value when calculating the initial conditions to determine the starting point of the simulation.Velocitycheck box.Valuefield, type10
,then clickapplication。Step 4: Add source
You can drive a Simscape model using input signals. Using this approach, you can represent physical effects such as force, voltage, or pressure acting on the system. You can also specify other quantities that flow through the system, such as current, mass flow, and heat flux. You can add signal input connections to a physics network by using a Simscape source block.
To add a representation of the forces acting on the mass, use the Ideal Force Source block.
After connecting the physics network to the Simulink source, the input signal representing the force curve is provided through port S (seeStep 6: Connect to Simulink using interface blocks). A positive signal at port S will specify a force acting from port C to port R.
Step 5: Adding Sensors
You can measure quantities in a physical network and use them elsewhere in the model. Some common uses of these quantities include feedback for control algorithms, modeling physical components whose behavior depends on other physical quantities (such as temperature-dependent resistors), or simply viewing results during simulation.
You can use sensor blocks to measure these quantities, connecting sensors in series or in parallel, depending on the value you want to measure. To measure quantities defined by the Through variable (such as current, flow, force), connect sensors in series. To measure quantities defined by the Across variable (such as voltage, pressure, velocity), connect sensors in parallel.
To measure spring deflection, connect the Ideal Translational Motion Sensor module in parallel with the spring.
Step 6: Connect to Simulink using the interface block
Simscape The equations in the network are solved simultaneously, while Simulink blocks are evaluated sequentially. Interface blocks, such as the Simulink-PS Converter and PS-Simulink Converter, are used to handle the boundary between these two modeling conventions. You need to use an interface block when Simulink signals specify quantities in a Simscape network, or when you pass Simscape quantities to Simulink for control design or other purposes. Each time you connect Simulink blocks to a Simscape physical network, you must use the appropriate converter block.
Next you will connect the physical network to the controller built from regular Simulink blocks. First, prepare the physical network to connect to the Simulink signals:
Although you can use oscilloscopes to view simulation results, these oscilloscopes can make the block diagram more cluttered. A more efficient way to view and analyze simulation results is to use the Simscape Results Explorer, such asStep 8: View the simulation resultsAs described in.
Then, build and connect the controller:
The control Simulink signal enters the input port of the Simulink-PS Converter block, where it is converted into a physical signal that drives the force distribution of the Ideal Force Source block.
The output port P of the Ideal Translational Motion Sensor block, which is used to measure the spring deformation, is connected to the PS-Simulink Converter block. This block is used to convert the physical signal into a feedback Simulink signal for the controller.
To compare the input and feedback signals, connect them to the Signal Viewer:
Step 7: Simulate the Model
You can run the model by clicking the Run button in the Simulink toolbar (at the top of the model window) or in the waveform viewer toolbar. to run the simulation. The Simscape solver evaluates the model, computes the initial conditions, and then runs the simulation.
To run the simulation, click。
The waveform viewer displays an overlay of the input and feedback signals.
Step 8: View the simulation results
The Simscape Results Explorer allows you to view and analyze simulation data using data logging capabilities. For example, you can compare two simulation runs to analyze how changes in mass affect spring deflection.
Notice:simlog
is the default name of the record variable.Workspace variable nameIf a model configuration parameter changes a variable name, the context menu lists that name as a recorded variable associated with the block.
The Simscape Results Explorer window opens with the node corresponding to the Spring module highlighted in the left pane. The right pane displays a plot of the simulation data for the three variables associated with the module.
Spring
Under Node, select Nodex
The right pane shows the spring deformation data plotted against time.7.2 kg
。