MATLAB Examples

Steady-State Simulation with Projection-Based Trim Optimizer

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.

Contents

Open Model

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.

set_param(mdl,'LoadExternalInput','off')
set_param(mdl,'LoadInitialState','off')

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 'iter'.

opt = findopOptions('OptimizerType','graddescent-proj',...
                    'DisplayReport','iter');
opt.OptimizationOptions.MaxFunEvals = 20000;

Trim Model

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.

load('scdbackhoe_op.mat')

Simulate Model

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.

bdclose(mdl)