diff options
author | Siddharth11235 | 2019-09-03 18:09:16 +0530 |
---|---|---|
committer | Siddharth11235 | 2019-09-03 18:09:16 +0530 |
commit | b4b6aa36e3486a3544acc52419149b5671f841e9 (patch) | |
tree | 66c1783158f23e6d21c77324156fc57e18d4ac67 /InterProcessExamples | |
parent | f5266f634f4fb4fd39933a83551a01cf446256b8 (diff) | |
download | OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.tar.gz OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.tar.bz2 OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.zip |
Diffstat (limited to 'InterProcessExamples')
-rwxr-xr-x | InterProcessExamples/DCMotor.mo | 65 | ||||
-rwxr-xr-x | InterProcessExamples/DiscretePID.mo | 56 | ||||
-rwxr-xr-x | InterProcessExamples/package.mo | 16 | ||||
-rwxr-xr-x | InterProcessExamples/package.order | 2 |
4 files changed, 139 insertions, 0 deletions
diff --git a/InterProcessExamples/DCMotor.mo b/InterProcessExamples/DCMotor.mo new file mode 100755 index 0000000..d902201 --- /dev/null +++ b/InterProcessExamples/DCMotor.mo @@ -0,0 +1,65 @@ +within InterProcessCommunication.Examples.InterProcessExamples; + +model DCMotor + extends Modelica.Icons.Example; + //extends Modelica.Mechanics.Rotational.Components; + Modelica.Mechanics.Rotational.Components.Inertia load(J = 10, phi(fixed = true, start = 0), w(fixed = true, start = 0)) annotation( + Placement(transformation(extent = {{67, 0}, {87, 20}}))); + Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed annotation( + Placement(transformation(extent = {{-10, -10}, {6, 6}}, rotation = -90, origin = {94, -7}))); + Modelica.Mechanics.Rotational.Sources.Torque torque annotation( + Placement(transformation(extent = {{40, 0}, {60, 20}}))); + Modelica.Blocks.Interfaces.RealOutput y annotation( + Placement(visible = true, transformation(origin = {50, -44}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + + // Declaration of variables and constants + + Real motorInputValue "Value of input to the Discrete PID Controller" ; + Real motorOutputValue "Value of output of Discrete PID Controller" ; + Integer motorInputIndex = 1;//Address from where to read, can be any number between 0 to 10, it must match the address given to output value in second model i.e. DiscretePID_SM_Example in this case + Integer motorOutputIndex = 1;//Address where to write, can be any number between 0 to 10 + Real motorOutputDummy "Dummy value to be returned by the SharedMemoryWrite function"; + +equation + + connect(speed.w, y) annotation( + Line(points = {{92, -14}, {90, -14}, {90, -44}, {50, -44}, {50, -44}}, color = {0, 0, 127})); + connect(speed.flange, load.flange_b) annotation( + Line(points = {{92, 3}, {92, 10}, {87, 10}}, color = {0, 0, 0}, smooth = Smooth.None)); + connect(torque.flange, load.flange_a) annotation( + Line(points = {{60, 10}, {67, 10}}, color = {0, 0, 0}, smooth = Smooth.None)); + + torque.tau = motorInputValue "The value of control signal (pidOutputValue) is acquired by the SharedMemoryRead function and it is assigned to the input of the DC motor"; + motorOutputValue = speed.w "The measured speed of the DC motor is assigned to pidInputValue, which is written into the shared memory using SharedMemoryWrite Function"; + + when sample(0, 0.05) then + motorInputValue = InterProcessCommunication.SharedMemory.SharedMemoryRead(motorInputIndex) "SharedMemoryRead Function reads the value from the shared memory, pointed by pidOutputIndex tag and assigns it to the input of the DC motor"; + motorOutputDummy = InterProcessCommunication.SharedMemory.SharedMemoryWrite(motorOutputIndex, motorOutputValue) "SharedMemoryWrite Function writes the value of measured speed into the shared memory, pointed by pidInputIndex tag" ; + end when; + + annotation( + Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-140, -100}, {140, 100}}, initialScale = 0.1), graphics = {Text(lineColor = {255, 0, 0}, extent = {{40, 37}, {90, 31}}, textString = "plant"), Rectangle(lineColor = {255, 0, 0}, extent = {{32, 40}, {104, -40}})}), + Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}, grid = {2, 2})), + Documentation(info = "<html> + +<p> +<b>Inter Process Communication Library V1.0</b><br /><br /> +The <b>DCMotor</b> model contains the DC motor, which reads the control signal from shared memory (given by discrete PID controller) and the speed sensor measures the resulting rotation. The measured speed from speed sensor is written into the shared memory. + + </p> + + <p> +The values of control signal and speed of the DC motor are read from and written into the shared memory at sampling interval of 0.05 seconds. <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryRead\"> SharedMemoryRead </a> and <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryWrite\"> SharedMemoryWrite </a> functions are used to read the control signal from the shared memory and write the measured speed into the shared memory respectively. The motorOutputIndex and motorInputIndex variables serve as index of the tag i.e. motorInputIndex points to the value of control signal and motorOutputIndex points to the value of speed of the DC motor. The value of the control signal, returned by the <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryRead\"> SharedMemoryRead </a> function is stored in the motorInputValue variable. The value of the motorInputValue is in turn assigned to the torque.tau variable, which serves as an input to the DC motor. Similarly, the value of the measured speed is assigned to motorOutputvalue variable. Therefore, the value of the motorOutputvalue is written into shared memory using <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryWrite\"> SharedMemoryWrite </a> function. +</p> + +<p> +<b>License:</b> GNU GPLV3 2017<br /> +This is a free program, and you are welcome to modify and redistribute it. This program comes with ABSOLUTELY NO WARRANTY.<br /><br /> +<b>Credits:</b> ModeliCon Infotech Team <br />Ankur Gajjar <br />Shubham Patne <br />Jal Panchal <br />Ritesh Sharma <br />Pavan P <br /> +</p> + +</html>"), + experiment(StopTime = 30, StartTime = 0, Tolerance = 1e-06, Interval = 0.01), + __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS", nls = "homotopy", clock = "RT")); + +end DCMotor;
\ No newline at end of file diff --git a/InterProcessExamples/DiscretePID.mo b/InterProcessExamples/DiscretePID.mo new file mode 100755 index 0000000..a387057 --- /dev/null +++ b/InterProcessExamples/DiscretePID.mo @@ -0,0 +1,56 @@ +within InterProcessCommunication.Examples.InterProcessExamples; + +model DiscretePID + extends Modelica.Icons.Example; + parameter Real sampleTime = 0.05; + parameter Integer pidInputIndex = 1;//Address from where to read, can be any number between 0 to 10, it must match the address given to output value in second model i.e. DCMotor_SM_Example in this case + parameter Integer pidOutputIndex = 1;//Address where to write, can be any number between 0 to 10 + Real MotorSpeed;//motor speed sensed by speed sensor and received as feedback + Real pidOutputDummy;//dummy return value from shared memory + Real pidInputValue;//value read from shared memory + Real pidOutputValue;//value written to shared memory + Modelica.Blocks.Continuous.PID PID(Td = 0.05, Ti = 5, k = 9) annotation( + Placement(visible = true, transformation(origin = {50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.Feedback feedback1 annotation( + Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Continuous.Filter filter1(f_cut = 0.8, order = 3) annotation( + Placement(visible = true, transformation(origin = {24, -32}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.Step step1(height = 20, startTime = 5) annotation( + Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); +algorithm + when sample(0, sampleTime) then + pidInputValue := InterProcessCommunication.SharedMemory.SharedMemoryRead(pidInputIndex) "SharedMemoryRead Function reads the value from the shared memory, pointed by pidOutputIndex tag and assigns it to the input of the DC motor"; + filter1.u := pidInputValue; + feedback1.u2 := filter1.y; + MotorSpeed := feedback1.u2; + pidOutputValue := PID.y; + pidOutputDummy := InterProcessCommunication.SharedMemory.SharedMemoryWrite(pidOutputIndex, pidOutputValue) "SharedMemoryWrite Function writes the value of measured speed into the shared memory, pointed by pidInputIndex tag"; + end when; +equation + connect(step1.y, feedback1.u1) annotation( + Line(points = {{-38, 0}, {-10, 0}, {-10, 0}, {-8, 0}}, color = {0, 0, 127})); + connect(feedback1.y, PID.u) annotation( + Line(points = {{10, 0}, {38, 0}, {38, 0}, {38, 0}}, color = {0, 0, 127})); + annotation( + experiment(StartTime = 0, StopTime = 30, Tolerance = 1e-06, Interval = 0.01), + __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS", nls = "homotopy", clock = "RT"), Documentation(info="<html> + +<p> +<b>Inter Process Communication Library V1.0</b><br /><br /> +The <b>DiscretePID</b> model contains the discretized PID controller with the step signal with 20 amplitude and 5s start time as a reference signal. The measured speed of the DC motor is read from the shared memory and given to the feedback of the discrete PID controller. Based on the difference between setpoint and measured speed, the discrete PID controller provides a control signal, which is written into the shared memory. +</p> + +<p> +The values of control signal and speed of the DC motor are written into and read from the shared memory at sampling interval of 0.05 seconds respectively. <a href=\"modelica://InterProcessCommunication.SharedMemory_Functions.SharedMemoryRead\"> SharedMemoryRead </a> and <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryWrite\"> SharedMemoryWrite </a> functions are used to read the speed of the DC motor from the shared memory and write the control signal into the shared memory respectively. The pidOutputIndex and pidInputIndex variables serve as index of the tag i.e. pidOutputIndex points to the value of control signal and pidInputIndex points to the value of speed of the DC motor. The value of the speed of the DC motor, returned by the <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryRead\"> SharedMemoryRead </a> function is stored in the pidIutputValue variable. The value of the pidIutputValue is in turn assigned to the filter1.u variable, which serves as an input to the feedback of the discrete PID controller. Similarly, the value of control signal is assigned to pidOutputvalue variable. Therefore, the value of the pidOutputvalue is written into shared memory using <a href=\"modelica://InterProcessCommunication.SharedMemory.SharedMemoryWrite\"> SharedMemoryWrite </a> function. +</p> + +<p> +<b>License:</b> GNU GPLV3 2017<br /> +This is a free program, and you are welcome to modify and redistribute it. This program comes with ABSOLUTELY NO WARRANTY.<br /><br /> +<b>Credits:</b> ModeliCon Infotech Team <br />Ankur Gajjar <br />Shubham Patne <br />Jal Panchal <br />Ritesh Sharma <br />Pavan P <br /> +</p> + +</html>"), + Diagram(graphics = {Rectangle(origin = {0, -10}, extent = {{-68, 50}, {68, -50}}), Text(origin = {0, 36}, lineColor = {255, 0, 0}, fillColor = {255, 0, 0}, extent = {{-26, -6}, {26, 6}}, textString = "Controller Package")})); + +end DiscretePID;
\ No newline at end of file diff --git a/InterProcessExamples/package.mo b/InterProcessExamples/package.mo new file mode 100755 index 0000000..77de993 --- /dev/null +++ b/InterProcessExamples/package.mo @@ -0,0 +1,16 @@ +within InterProcessCommunication.Examples; + +package InterProcessExamples +extends Modelica.Icons.ExamplesPackage; + annotation (Documentation(info= "<html> +<p> +<b>Inter Process Communication Library V1.0</b><br /><br /> +This package contains example models for inter process and intersystem communication. For User's guide to those models and necessary setups refer to <a href=\"modelica://InterProcessCommunication.info.Tutorial\"> Tutorial</a> +</p> +<p> +<b>License:</b> GNU GPL 2017<br /> +This is a free program, and you are welcome to modify and redistribute it. This program comes with ABSOLUTELY NO WARRANTY.<br /><br /> +<b>Credits:</b> ModeliCon Infotech Team <br />Ankur Gajjar <br />Shubham Patne <br />Jal Panchal <br />Ritesh Sharma <br />Pavan P <br /> +</p> +</html>")); +end InterProcessExamples;
\ No newline at end of file diff --git a/InterProcessExamples/package.order b/InterProcessExamples/package.order new file mode 100755 index 0000000..99c50a3 --- /dev/null +++ b/InterProcessExamples/package.order @@ -0,0 +1,2 @@ +DiscretePID +DCMotor |