Model Inversion Control

Introduction

Model a hoist crane control system using model inversion control.

Explore the available scenarios by evaluating each cell in order. Evaluation is done by selecting a cell and pressing Shift+Enter.

In order to get the full experience of this example, you need the following:

Wolfram SystemModeler; a free trial download is available at www.wolfram.com/system-modeler

The model that came in the same bundle as this notebook

For more information about Wolfram SystemModeler, visit www.wolfram.com/system-modeler.

Initialize

Define the model name:

mmodel="ModelInversionControl.InversionControlledCrane";
cranemodel="ModelInversionControl.Components.CraneCrabDamped";
partialModel="ModelInversionControl.Components.PartialControlledCrane";

Load the model:

Import[FileNameJoin[{NotebookDirectory[],"ModelInversionControl.mo"}]];

The Model

The hoist crane is modeled using the PlanarMechanics Modelica library. Force is applied to a prismatic joint that pushes a crab along a one-dimensional beam. Attached to the crab is a dampened revolute joint that connects to the load through a stiff rod. In the controller, a filtered pulse is used as a reference signal to control the position of the load.

Using a constrained inversion block, the force that should be applied to the crab can be calculated from the reference signal.

To get a visualization of what the model looks like, you can use the “Diagram” property from the SystemModel object:

SystemModel[mmodel,{"Diagram",ImageSize-> 570,Frame-> False}]

You can also investigate the components in the model:

SystemModel[cranemodel,{"Diagram",ImageSize-> 570,Frame-> False}]

Simulation

Compare two different parameter settings that describe the inertia of the crane load.

Simulate with two different parameters:

sim=Quiet[SystemModelSimulate[mmodel,{0,40},<|"ParameterValues"->{"crane_I"->{50,200}}|>]];

Analysis

Show the load positions for the two different scenarios and compare them to the reference position that was supplied to the controller:

Show[
SystemModelPlot[sim[[1]],{"filterOutput"},
PlotLegends->Placed[{"Reference"},Below],
PlotStyle-> Directive[Dashed,Black],
PlotLabel-> Style["Actual and Reference Crane Position","Caption"]],
SystemModelPlot[sim,{"loadPosition"},
PlotLegends->Placed[{"I: 50","I: 500"},Below]],
ImageSize-> 570
]

Generate a Controller

Linearize the Model

Using Mathematica together with SystemModeler, you could also generate a controller and use it to control the process.

Automatically generate a linearized state-space model using SystemModelLinearize:

ssm =SystemModelLinearize[cranemodel]

Retrieve a list of all output names:

outputs=Part[ssm,-1,2,2]

Create a feedback controller based on the crab position. Start by extracting only this output from the state-space model:

feedbackssm=SystemsModelExtract[ssm,All,First[FirstPosition[outputs,"loadPosition"]],All]

Transform the state-space model into a transfer function model:

tf=TransferFunctionModel[feedbackssm,s]

Tune the Controller

Using the PIDTune function, a PID controller can be generated that controls the loadPosition variable given a feedback signal:

pid=PIDTune[tf,"PID","PIDData"];

({k,Ti,Td}=pid["FeedbackIdealParameters"]) //Column

pidParams = {"feedbackController.k"-> k,"feedbackController.Ti"->Ti,"feedbackController.Td"->Td};

Connect the Components

Next you need to generate a model that uses the generated controller. This is easily done using the ConnectSystemModelComponents function. You can use the same components, connections, partial model and parameters that were used in the example model:

components={"feedback"∈"Modelica.Blocks.Math.Feedback","feedbackController"∈"Modelica.Blocks.Continuous.PID"};
connections ={"feedbackController.y"\[UndirectedEdge]"crane.inputForce","feedback.u2"\[UndirectedEdge]"crane.crabPosition","feedback.y"\[UndirectedEdge]"feedbackController.u","filter.y"\[UndirectedEdge]"feedback.u1"};
parameters={"crane_I"->10};
pidmodel=ConnectSystemModelComponents["ControlledCrane",components,connections,<|"ExtendsModels"-> partialModel|>];

Simulate

When the components are connected, all you need to do is to supply the previously calculated and specified parameter values and simulate the model. When the simulation is completed, the two test scenarios are plotted together so that the performance of the different controllers can be compared:

controlledModel = SetSystemModel[pidmodel,<|"ParameterValues"->Join[parameters,pidParams]|>];
pidSim=SystemModelSimulate[controlledModel,80];
SystemModelPlot[{sim[[2]],pidSim},PlotLabel->Style["Actual and Reference Crane Position","Caption"],PlotStyle->{Directive[Dashed,Black],ColorData[97][1],None,ColorData[97][2]},
PlotLegends->Placed[{"Reference","Model Inversion Control",None,"PID Controller"},Below],
ImageSize->570]

If you have SystemModeler installed, you can open up SimulationCenter to see an animation of the PID model.

SystemModeler[pidSim,"Animation"]

Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

License

All content in this bundle is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. By accessing the content or using it in any way, you accept and agree to be bound by the terms of this license. If you do not agree to these Terms of Use, you may not use this content. Wolfram Research reserves the right to change, modify, add to, or remove portions of these Terms of Use at any time without notice. Please refer back to www.wolfram.com for the latest Terms of Use.

A summary of the licensing terms can be found at:
http://creativecommons.org/licenses/by-nc-sa/3.0

The full legal code can be found at: 
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode