package SpringMassDamperPackage // Plant model Plant parameter Modelica.SIunits.Mass m = 1; parameter Modelica.SIunits.TranslationalSpringConstant k = 1; parameter Modelica.SIunits.TranslationalDampingConstant b = 0.1; Modelica.SIunits.Position x(start = 1, fixed = true) "Position"; Modelica.SIunits.Velocity v(start = 0, fixed = true) "Velocity"; Modelica.SIunits.Force f "Force"; equation assert(m > 0, "Mass is outside of the domain of validity", AssertionLevel.error); der(x) = v; m * der(v) = f - k * x - b * v; end Plant; //Controller model Controller extends Plant; constant Real K = 1 "Gain of speed P controller"; constant Modelica.SIunits.Velocity vref = 2 "Speed ref."; discrete Real vd; discrete Real u; equation when sample(0, 1) then vd = v; u = K * (vref - vd); f = u; end when; end Controller; end SpringMassDamperPackage;