Technology Sharing

Simscape Physical Modeling Steps

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:

  • Create a new Simscape model with the necessary and commonly used blocks already on the model canvas
  • Select the recommended solver and tolerance settings
  • Enable data logging for the entire model

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.

  1. Open the Simscape > Foundation Library > Mechanical > Translational Elements library.
  2. Drag Mass, Translational Spring, Translational Damper, and Mechanical Translational Reference blocks into the model window.
  3. Connect the Translational Spring, Translational Damper, and Mass blocks to the Mechanical Translational Reference block as shown in the following figure. To rotate a block, select it and pressCtrl+R

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.

  1. Double-click the Spring module. ClearAutomatic Applicationcheck box.Spring rateSet as400 N/m,then clickapplication

  1. Double-click the Damper module.Damping coefficientSet as100 N/(m/s)

  1. Double-click the Mass block.MassSet as3.6 kg

  1. To specify the desired initial value for the mass velocity, enterInitial TargetsExpand in sectionVelocityThe variablePriorityDesignated as "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.

  1. Open the Simscape > Foundation Library > Mechanical > Mechanical Sources library.
  2. Add an Ideal Force Source block to the schematic. Simplify the block names as shown.
  3. To reflect the correct direction of the force as shown in the original schematic, flip the block orientation.® ToolbarFormattab, inarrangementNext, clickFlip upside down
  4. Duplicate the Mechanical Translational Reference block by right-clicking it and dragging it to a new location. Then flip the orientation of the new block using the same method as the Force Source block.
  5. Connect port C of the Force Source block to this second Mechanical Translational Reference block and port R to the Mass block, as shown in the following figure.

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.

  1. Open the Simscape > Foundation Library > Mechanical > Mechanical Sensors library.
  2. Add an Ideal Translational Motion Sensor block to the schematic.
  3. To rotate the module, select it and pressCtrl+R
  4. Connect the module as shown in the following figure. Simplify the module names as shown in the figure.

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:

  1. Delete the Scope block.

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.

  1. Connect the physical signal output port of the Simulink-PS Converter block to port S of the Force Source block.
  2. Connect the output port P of the Motion Sensor block to the physical signal input port of the PS-Simulink Converter block.
  3. Connect the Solver Configuration block to the circuit and hide the transformer block names. The schematic now looks like the following.

Then, build and connect the controller:

  1. Open the Simulink > Sources library and drag a Pulse Generator block into the model. Change the block name to Position Command. Set the block parameters as shown.

  1. Open the Simulink > Math Operations library and drag a Sum block into the model.Bulleted List, replace the second plus sign with a minus sign, as shown.

  1. Open Simulink > Continuous library and drag a PID Controller block into the model.Proportion (P)Integration (I)andDifferentiation (D)Parameter values ​​are shown in the figure.

  1. Connect the modules as shown in the diagram below.

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:

  1. Right-click the Simulink signal that passes from the Pulse Generator block to the Sum block. From the context menu, selectCreate & Connect Viewer > Simulink > Scope
  2. Then, right-click the Simulink signal passed from the PS-Simulink Converter block to the Sum block. From the context menu, selectConnect To Viewer > Scope

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.

  1. Right-click the Spring module.
  2. From the context menu, selectSimscape > View simulation data > simlog

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.

  1. existSpring Under Node, select NodexThe right pane shows the spring deformation data plotted against time.

  1. Double-click the Mass block.qualitySet as7.2 kg
  2. Run the simulation.
  3. To reload logged data, click theImport Databutton. In the pop-up window that displays the recorded variable name, clickSure