You can find operating points for models with Simscape™ components using Simulink® Control Design™software. In particular, you can find steady-state operating points using one of the following methods:
Optimization-based trimming — Specify constraints on model inputs, outputs, or states, and compute a steady-state operating point that satisfies these constraints. For more information, see Compute Steady-State Operating Point from State Specifications and Compute Steady-State Operating Point from Output Specifications.
By default, you can define operating point specifications for any Simulink and Simscape states in your model, and any root-level input and output ports of your model. You can also define additional output specifications on Simulink signals. To apply output specifications to a Simscape physical signal, first convert the signal using a PS-Simulink Converter block.
Simulation snapshot — Specify model initial conditions near an expected equilibrium point, and simulate the model until it reaches steady state. You can then create an operating point based on the steady-state signals and states in the model. For more information, see Compute Operating Points at Simulation Snapshots.
To produce better trimming results for Simscape models, you can use projection-based trim optimizers. These optimizers enforce the consistency of the model initial condition at each evaluation of the objective function or nonlinear constraint function. Using projection-based trim optimizers requires Optimization Toolbox™ software.
You can use these projection-based optimizers when trimming models from the command line and in the Linear Analysis Tool.
To specify the optimizer type at the command line, create a
findopOptions option set,
and specify the
Optimizer option as one of the
'lsqnonlin-proj' — Nonlinear least squares
'graddescent-proj' — Gradient descent with
When using gradient descent with projection at the command line, you can
specify whether the algorithm enforces the model initial conditions using
hard or soft constraints by specifying the
To specify the optimizer type in the Linear Analysis Tool, first open the
Trim the model dialog box. In the Linear Analysis Tool, in the
Operating Point drop-down list, select
Then, in the Trim the model dialog box, on the Options tab, in the Optimization Method drop-down list, select an optimizer.
When you use gradient descent with projection in the Linear Analysis Tool, the algorithm enforces the model initial conditions using hard constraints.
This example shows how to find a steady-state operating point for a Simscape™ Multibody™ model using
findop with a projection-based optimizer. Results are verified using simulation.
Open the Simulink model.
mdl = 'scdbackhoeTRIM'; open_system(mdl)
Define Operating Point Specifications
Before creating an operating point specification, configure the model to use the model initial condition.
Create a default operating point specification object.
ops = operspec(mdl);
Impose constraints on the outputs.
ops.Outputs(1).Known = true(10,1); ops.Outputs(1).y(1) = 0; % Bucket angle ops.Outputs(1).y(3) = 50; % Upper angle ops.Outputs(1).y(5) = -50; % Lower angle ops.Outputs(1).y(7) = 0; % Base angle ops.Outputs(1).y(9) = -45; % Support angle
Configure Trim Options
Configure trim optimizer options. Set the
'OptimizerType' option to
'graddescent-proj', which is a projection-based trim optimizer that enforces consistency of the model physical states. To display trim progress, set the
'DisplayReport' option to
opt = findopOptions('OptimizerType','graddescent-proj',... 'DisplayReport','iter'); opt.OptimizationOptions.MaxFunEvals = 20000;
Find the steady-state operating point that meets these specifications. The following command takes a few minutes.
[op,rpt] = findop(mdl,ops,opt);
To save time, load precomputed results.
Simulate the model from the computed steady state.
set_param(mdl, 'LoadExternalInput','on') set_param(mdl, 'ExternalInput','getinputstruct(op)') set_param(mdl, 'LoadInitialState','on') set_param(mdl, 'InitialState','getstatestruct(op)') sim(mdl)
Open scope to inspect results.
open_system([mdl, '/Joint Angle Trajectories'])
The simulation results show that the five angles are trimmed to their expected values, however the trajectory deviates slightly over time due to numerical noise and instability. You can stabilize the angles using feedback controllers.