Main Content

Extract Initial Values from Block or Subsystem

This example shows how to create an operating point from a block or subsystem and initialize that block or subsystem with the operating point. When you create operating point data for a block or subsystem, you cannot immediately use this operating point to initialize that block or subsystem because of the mismatch in the data structure hierarchy. Use the relativePath function to determine the correct location, and then add the necessary layers for inserting this data in the operating point for the current model.

Open the Permanent Magnet DC Motor example model.

openExample("simscape/PermanentMagnetDCMotorExample")
mdl = "PermanentMagnetDCMotor";

Open the DC Motor subsystem and select the Rotor Inductance block. Create an operating point for the Rotor Inductance block named opRI using the values from the Start simulation phase.

opRI = simscape.op.create(mdl + "/DC Motor/Rotor Inductance","Start")
opRI = 

  OperatingPoint with children:

  Targets:

   ChildId       Value  Unit  Priority
   _______  __________  ____  ________

   'i'      1.5000e-09  'A'     'None'
   'i_L'             0  'A'     'High'
   'v'          1.5000  'V'     'None'

  OperatingPoints:

   ChildId  Size
   _______  ____

   'n'       1x1
   'p'       1x1

To change the initial value for the inductor current variable, i_L, enter:

t = simscape.op.Target(1.5, "A", "High");
opRI = set(opRI, "i_L", t)
opRI = 
  OperatingPoint with children:

  Targets:

   ChildId       Value  Unit  Priority
   _______  __________  ____  ________

   'i'      1.5000e-09  'A'     'None'
   'i_L'        1.5000  'A'     'High'
   'v'          1.5000  'V'     'None'

  OperatingPoints:

   ChildId  Size
   _______  ____

   'n'       1x1
   'p'       1x1

To use the new operating point to initialize the block, you must create an operating point for the whole model and insert the block operating point.

Create an empty OperatingPoint object named opModel.

opModel = simscape.op.OperatingPoint
opModel = 

  OperatingPoint with no children.

Set the Identifier property of the operating point to the name of the model and find the relative path for the Rotor Inductance block.

opModel.Identifier = bdroot(mdl + "/DC Motor/Rotor Inductance");
relPath = relativePath(opModel, mdl + "/DC Motor/Rotor Inductance")
relPath =

    'DC Motor/Rotor Inductance'

Add the OperatingPoint object opRI to the OperatingPoint object opModel.

opModel = set(opModel,relPath,opRI)
opModel = 

  OperatingPoint with children:

  OperatingPoints:

   ChildId     Size
   __________  ____

   'DC Motor'   1x1

The function inserts the data at the location defined by relPath and adds the nodes to the data tree, as necessary.

You can now use the opModel operating point to initialize the model and apply the new target to the Rotor Inductance block.

See Also

| |