|  |  |  |  | // CP: 65001 | 
					
						
							|  |  |  |  | // SimulationX Version: 3.8.2.45319 x64 | 
					
						
							|  |  |  |  | //Licensed by 2000-2019 Modelica Association & al. under the Modelica License 2 | 
					
						
							|  |  |  |  | //Copyright © 2000-2019, Modelica Association & al. | 
					
						
							|  |  |  |  | within AIDAModelica; | 
					
						
							|  |  |  |  | model PID_2 "PID_2" | 
					
						
							|  |  |  |  | 	import Modelica.Blocks.Types.InitPID; | 
					
						
							|  |  |  |  | 	import Modelica.Blocks.Types.Init; | 
					
						
							|  |  |  |  | 	import Modelica.Blocks; | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Interfaces.RealInput u "'input Real' as connector" annotation(Placement( | 
					
						
							|  |  |  |  | 		transformation( | 
					
						
							|  |  |  |  | 			origin={-126,86}, | 
					
						
							|  |  |  |  | 			extent={{-14,-14},{14,14}}), | 
					
						
							|  |  |  |  | 		iconTransformation( | 
					
						
							|  |  |  |  | 			origin={-50,-100}, | 
					
						
							|  |  |  |  | 			extent={{-20,-20},{20,20}}, | 
					
						
							|  |  |  |  | 			rotation=90))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Interfaces.RealInput du "'input Real' as connector" annotation(Placement( | 
					
						
							|  |  |  |  | 		transformation( | 
					
						
							|  |  |  |  | 			origin={-116,-82}, | 
					
						
							|  |  |  |  | 			extent={{-14,-14},{14,14}}), | 
					
						
							|  |  |  |  | 		iconTransformation( | 
					
						
							|  |  |  |  | 			origin={50,-100}, | 
					
						
							|  |  |  |  | 			extent={{-20,-20},{20,20}}, | 
					
						
							|  |  |  |  | 			rotation=90))); | 
					
						
							|  |  |  |  | 	Blocks.Interfaces.RealOutput y annotation(Placement( | 
					
						
							|  |  |  |  | 		transformation( | 
					
						
							|  |  |  |  | 			origin={110,0}, | 
					
						
							|  |  |  |  | 			extent={{-10,-10},{10,10}}), | 
					
						
							|  |  |  |  | 		iconTransformation( | 
					
						
							|  |  |  |  | 			origin={110,0}, | 
					
						
							|  |  |  |  | 			extent={{-10,-10},{10,10}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Interfaces.RealInput Consign "'input Real' as connector" annotation(Placement( | 
					
						
							|  |  |  |  | 		transformation( | 
					
						
							|  |  |  |  | 			origin={-126,30}, | 
					
						
							|  |  |  |  | 			extent={{-12,-12},{12,12}}), | 
					
						
							|  |  |  |  | 		iconTransformation( | 
					
						
							|  |  |  |  | 			origin={-100,0}, | 
					
						
							|  |  |  |  | 			extent={{-20,-20},{20,20}}))); | 
					
						
							|  |  |  |  | 	parameter Real k(unit="1")=1 "Gain"; | 
					
						
							|  |  |  |  | 	parameter Real Ti( | 
					
						
							|  |  |  |  | 		min=Modelica.Constants.small, | 
					
						
							|  |  |  |  | 		start=0.5) "Time Constant of Integrator"; | 
					
						
							|  |  |  |  | 	parameter Real Td( | 
					
						
							|  |  |  |  | 		min=0, | 
					
						
							|  |  |  |  | 		start=0.1) "Time Constant of Derivative block"; | 
					
						
							|  |  |  |  | 	parameter Blocks.Types.InitPID initType=Blocks.Types.InitPID.DoNotUse_InitialIntegratorState "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)" annotation( | 
					
						
							|  |  |  |  | 		Evaluate=true, | 
					
						
							|  |  |  |  | 		Dialog(group="Initialization")); | 
					
						
							|  |  |  |  | 	parameter Real xi_start=0 "Initial or guess value value for integrator output (= integrator state)" annotation(Dialog(group="Initialization")); | 
					
						
							|  |  |  |  | 	parameter Real xd_start=0 "Initial or guess value for state of derivative block" annotation(Dialog(group="Initialization")); | 
					
						
							|  |  |  |  | 	parameter Real y_start=0 "Initial value of output" annotation(Dialog( | 
					
						
							|  |  |  |  | 		group="Initialization", | 
					
						
							|  |  |  |  | 		enable=initType==InitPID.InitialOutput)); | 
					
						
							|  |  |  |  | 	constant Real unitTime=1 annotation(HideResult=true); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Math.Gain P(k=1) "Proportional part of PID controller" annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-28,68}, | 
					
						
							|  |  |  |  | 		extent={{-10,-10},{10,10}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Math.Gain D(k=Td) "Derivative part of PID controller, with derivate received at input du" annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-27,-41}, | 
					
						
							|  |  |  |  | 		extent={{-9,-9},{9,9}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Continuous.Integrator I( | 
					
						
							|  |  |  |  | 		k=unitTime / Ti, | 
					
						
							|  |  |  |  | 		initType=if initType == InitPID.SteadyState then Init.SteadyState else if initType == InitPID.InitialState or initType == InitPID.DoNotUse_InitialIntegratorState then Init.InitialState else Init.NoInit, | 
					
						
							|  |  |  |  | 		y_start=xi_start) "Integral part of PID controller" annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-28,30}, | 
					
						
							|  |  |  |  | 		extent={{-10,-10},{10,10}}))); | 
					
						
							|  |  |  |  | 	Blocks.Math.Gain Gain(k=k) "Gain of PID controller" annotation(Placement(transformation(extent={{60,-10},{80,10}}))); | 
					
						
							|  |  |  |  | 	Blocks.Math.Add3 Add annotation(Placement(transformation(extent={{20,-10},{40,10}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Math.Feedback feedback1 annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-68,30}, | 
					
						
							|  |  |  |  | 		extent={{-14,14},{14,-14}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Math.Feedback feedback2 annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-64,-42}, | 
					
						
							|  |  |  |  | 		extent={{-10,-10},{10,10}}))); | 
					
						
							|  |  |  |  | 	Modelica.Blocks.Continuous.Derivative derivative1 annotation(Placement(transformation( | 
					
						
							|  |  |  |  | 		origin={-90,-42}, | 
					
						
							|  |  |  |  | 		extent={{-10,-10},{10,10}}))); | 
					
						
							|  |  |  |  | 	initial equation | 
					
						
							|  |  |  |  | 		if initType == InitPID.InitialOutput then | 
					
						
							|  |  |  |  | 		  y = y_start; | 
					
						
							|  |  |  |  | 		end if; | 
					
						
							|  |  |  |  | 	equation | 
					
						
							|  |  |  |  | 		connect(derivative1.y, feedback2.u1) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-79, -42}, {-79, -44}, {-72, -44}, {-72, -42}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(Consign, derivative1.u) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-126, 30}, {-102, 30}, {-102, -42}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(du, feedback2.u2) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-116, -82}, {-64, -82}, {-64, -50}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(feedback2.y,D.u) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{-55,-42},{-50,-42},{-42.7,-42},{-42.7,-41},{-37.7,-41}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(D.y, Add.u3) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-17, -41}, {0, -41}, {0, -8}, {18, -8}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(Consign,feedback1.u1) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{-126,30},{-121,30},{-84.3,30},{-79.3,30}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(u,feedback1.u2) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{-126,86},{-121,86},{-68,86},{-68,46.3},{-68,41.3}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(feedback1.y,P.u) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{-55.3,30},{-50.3,30},{-45,30},{-45,68},{-40,68}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(I.u,feedback1.y) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{-40,30},{-45,30},{-50.3,30},{-55.3,30}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(I.y, Add.u2) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-17, 30}, {-0.5, 30}, {-0.5, 0}, {18, 0}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(P.y, Add.u1) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{-17, 68}, {0, 68}, {0, 8}, {18, 8}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 		connect(y,Gain.y) annotation(Line( | 
					
						
							|  |  |  |  | 			points={{110,0},{105,0},{86,0},{81,0}}, | 
					
						
							|  |  |  |  | 			color={0,0,127})); | 
					
						
							|  |  |  |  | 		connect(Add.y, Gain.u) annotation( | 
					
						
							|  |  |  |  | 		  Line(points = {{41, 0}, {58, 0}}, color = {0, 0, 127})); | 
					
						
							|  |  |  |  | 	annotation(experiment( | 
					
						
							|  |  |  |  | 		StopTime=1, | 
					
						
							|  |  |  |  | 		StartTime=0, | 
					
						
							|  |  |  |  | 		Interval=0.001)); | 
					
						
							|  |  |  |  | end PID_2; |