Browse Source

added monolithic version of the scenario.

Cláudio Gomes 6 years ago
parent
commit
1df45a58c7

+ 18 - 0
ModelicaModels/ControlledScenario.mo

@@ -0,0 +1,18 @@
+model ControlledScenario
+  PowerSystem power();
+  Window window();
+  Obstacle obstacle();
+  Controller controller();
+equation
+  power.u = controller.u_motor;
+  power.d = controller.d_motor;
+  controller.i = power.i;
+  window.speed = power.omega;
+  window.displacement = power.theta;
+  window.reaction_force = obstacle.F;
+  power.tau = window.reaction_torque;
+  obstacle.disp = window.height;
+  annotation(
+    experiment(StartTime = 0, StopTime = 6, Tolerance = 1e-06, Interval = 0.0024),
+    __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS"));
+end ControlledScenario;

+ 22 - 0
ModelicaModels/Controller.mo

@@ -0,0 +1,22 @@
+model Controller
+  parameter Real i_max = 5;
+  output Real d_motor;
+  output Real u_motor;
+  input Real i;
+  Boolean detected;
+  Real timer;
+initial equation
+  detected = false;
+  timer = 0.0;
+equation
+  u_motor = if detected then 0.0 else 1.0;
+  d_motor = if detected then 1.0 else 0.0;
+  der(timer) = if detected then 1.0 else 0.0;
+  when abs(i) > i_max then
+    detected = true;
+    reinit(timer,0.0);
+  elsewhen timer > 1 then
+    detected = false;
+    reinit(timer,0.0);
+  end when;
+end Controller;

+ 7 - 0
ModelicaModels/ControllerTest.mo

@@ -0,0 +1,7 @@
+model ControllerTest
+  Controller ctrl;
+  Modelica.Blocks.Sources.Ramp ramp_i(duration = 2, height = 10);
+equation
+  ctrl.i = ramp_i.y;
+annotation(
+    experiment(StartTime = 0, StopTime = 6, Tolerance = 1e-06, Interval = 0.0024));end ControllerTest;

+ 41 - 41
ModelicaModels/StategraphSample.mo

@@ -1,41 +1,41 @@
-model StategraphSample
-  Modelica.Blocks.Interfaces.RealInput u annotation(
-    Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-58, 46}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
-  Modelica.StateGraph.InitialStepWithSignal s1 annotation(
-    Placement(visible = true, transformation(origin = {-22, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.StateGraph.Transition t1(condition = u > 0.5, waitTime = 0)  annotation(
-    Placement(visible = true, transformation(origin = {4, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.StateGraph.Transition t2(enableTimer = true, waitTime = 1)  annotation(
-    Placement(visible = true, transformation(origin = {0, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
-  inner Modelica.StateGraph.StateGraphRoot stateGraphRoot annotation(
-    Placement(visible = true, transformation(origin = {-66, 64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Blocks.Logical.Switch switch1 annotation(
-    Placement(visible = true, transformation(origin = {-22, -40}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
-  Modelica.Blocks.Sources.RealExpression realExpression1(y = 0.0)  annotation(
-    Placement(visible = true, transformation(origin = {14, -24}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
-  Modelica.Blocks.Sources.RealExpression realExpression2(y = 1) annotation(
-    Placement(visible = true, transformation(origin = {-54, -24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.Blocks.Interfaces.RealOutput y annotation(
-    Placement(visible = true, transformation(origin = {50, -48}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {56, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-  Modelica.StateGraph.Step step1 annotation(
-    Placement(visible = true, transformation(origin = {32, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
-equation
-  connect(step1.outPort[1], t2.inPort) annotation(
-    Line(points = {{42, 0}, {48, 0}, {48, 40}, {4, 40}, {4, 40}}));
-  connect(t1.outPort, step1.inPort[1]) annotation(
-    Line(points = {{6, 0}, {20, 0}, {20, 0}, {20, 0}}));
-  connect(switch1.y, y) annotation(
-    Line(points = {{-22, -52}, {-22, -52}, {-22, -48}, {50, -48}, {50, -48}}, color = {0, 0, 127}));
-  connect(s1.active, switch1.u2) annotation(
-    Line(points = {{-22, -12}, {-22, -12}, {-22, -28}, {-22, -28}}, color = {255, 0, 255}));
-  connect(realExpression1.y, switch1.u1) annotation(
-    Line(points = {{2, -24}, {-14, -24}, {-14, -28}, {-14, -28}}, color = {0, 0, 127}));
-  connect(realExpression2.y, switch1.u3) annotation(
-    Line(points = {{-42, -24}, {-30, -24}, {-30, -28}, {-30, -28}}, color = {0, 0, 127}));
-  connect(s1.outPort[1], t1.inPort) annotation(
-    Line(points = {{-12, 0}, {0, 0}, {0, 0}, {0, 0}}));
-  connect(t2.outPort, s1.inPort[1]) annotation(
-    Line(points = {{-2, 40}, {-60, 40}, {-60, 0}, {-34, 0}, {-34, 0}}));
-  annotation(
-    uses(Modelica(version = "3.2.2")));
-end StategraphSample;
+model StategraphSample
+  Modelica.Blocks.Interfaces.RealInput u annotation(
+    Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-58, 46}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+  Modelica.StateGraph.InitialStepWithSignal s1 annotation(
+    Placement(visible = true, transformation(origin = {-22, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.StateGraph.Transition t1(condition = u > 0.5, waitTime = 0)  annotation(
+    Placement(visible = true, transformation(origin = {4, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.StateGraph.Transition t2(enableTimer = true, waitTime = 2)  annotation(
+    Placement(visible = true, transformation(origin = {0, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
+  inner Modelica.StateGraph.StateGraphRoot stateGraphRoot annotation(
+    Placement(visible = true, transformation(origin = {-66, 64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Blocks.Logical.Switch switch1 annotation(
+    Placement(visible = true, transformation(origin = {-22, -40}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
+  Modelica.Blocks.Sources.RealExpression realExpression1(y = 0.0)  annotation(
+    Placement(visible = true, transformation(origin = {14, -24}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
+  Modelica.Blocks.Sources.RealExpression realExpression2(y = 1) annotation(
+    Placement(visible = true, transformation(origin = {-54, -24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.Blocks.Interfaces.RealOutput y annotation(
+    Placement(visible = true, transformation(origin = {50, -48}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {56, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+  Modelica.StateGraph.Step step1 annotation(
+    Placement(visible = true, transformation(origin = {32, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+equation
+  connect(step1.outPort[1], t2.inPort) annotation(
+    Line(points = {{42, 0}, {48, 0}, {48, 40}, {4, 40}, {4, 40}}));
+  connect(t1.outPort, step1.inPort[1]) annotation(
+    Line(points = {{6, 0}, {20, 0}, {20, 0}, {20, 0}}));
+  connect(switch1.y, y) annotation(
+    Line(points = {{-22, -52}, {-22, -52}, {-22, -48}, {50, -48}, {50, -48}}, color = {0, 0, 127}));
+  connect(s1.active, switch1.u2) annotation(
+    Line(points = {{-22, -12}, {-22, -12}, {-22, -28}, {-22, -28}}, color = {255, 0, 255}));
+  connect(realExpression1.y, switch1.u1) annotation(
+    Line(points = {{2, -24}, {-14, -24}, {-14, -28}, {-14, -28}}, color = {0, 0, 127}));
+  connect(realExpression2.y, switch1.u3) annotation(
+    Line(points = {{-42, -24}, {-30, -24}, {-30, -28}, {-30, -28}}, color = {0, 0, 127}));
+  connect(s1.outPort[1], t1.inPort) annotation(
+    Line(points = {{-12, 0}, {0, 0}, {0, 0}, {0, 0}}));
+  connect(t2.outPort, s1.inPort[1]) annotation(
+    Line(points = {{-2, 40}, {-60, 40}, {-60, 0}, {-34, 0}, {-34, 0}}));
+  annotation(
+    uses(Modelica(version = "3.2.2")));
+end StategraphSample;

+ 16 - 16
ModelicaModels/UncontrolledScenario.mo

@@ -1,16 +1,16 @@
-model UncontrolledScenario
-  PowerSystem power();
-  Window window();
-  Obstacle obstacle();
-equation
-  power.u = 1.0;
-  power.d = 0.0;
-  window.speed = power.omega;
-  window.displacement = power.theta;
-  window.reaction_force = obstacle.F;
-  power.tau = window.tau;
-  obstacle.disp = window.height;
-  annotation(
-    experiment(StartTime = 0, StopTime = 6, Tolerance = 1e-06, Interval = 0.0024),
-    __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS"));
-end UncontrolledScenario;
+model UncontrolledScenario
+  PowerSystem power();
+  Window window();
+  Obstacle obstacle();
+equation
+  power.u = 1.0;
+  power.d = 0.0;
+  window.speed = power.omega;
+  window.displacement = power.theta;
+  window.reaction_force = obstacle.F;
+  power.tau = window.reaction_torque;
+  obstacle.disp = window.height;
+  annotation(
+    experiment(StartTime = 0, StopTime = 6, Tolerance = 1e-06, Interval = 0.0024),
+    __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS"));
+end UncontrolledScenario;

File diff suppressed because it is too large
+ 2521 - 0
ModelicaModels/controller_scenario_export.csv


+ 78 - 0
ModelicaModels/plot_results.r

@@ -0,0 +1,78 @@
+library(ggplot2)
+library(cowplot)
+library(grid)
+library(dplyr)
+library(plyr)
+library(reshape)
+library(plotly)
+library(stringr)
+
+sizeAxisLabel <- 22
+
+# Gather all results
+data <- read.csv("controller_scenario_export.csv")
+
+data_molten <- melt(data, id=c("time"))
+
+
+
+# Plot Controller 
+  control <- subset(data_molten, variable == "controller.u_motor" | variable == "controller.d_motor")
+  
+  pallete <- c("#9699c3",
+               "#cca956")
+  pcontrol <- ggplot(data=control) +
+                geom_line(aes(x=time, y=value, color=variable), size=1) +
+                scale_x_continuous("Time (s)") +
+                scale_y_continuous("Value", limits=c(0, 1)) +
+                scale_color_manual("controller",
+                                   labels=c("controller.u_motor"="u","controller.d_motor"="d"),
+                                   values = pallete) +
+                theme(axis.title.y=element_blank(),
+                      axis.title=element_text(size=sizeAxisLabel,face="bold"),
+                      axis.text=element_text(size=sizeAxisLabel),
+                      legend.text=element_text(size=sizeAxisLabel),
+                      legend.title=element_text(size=sizeAxisLabel,face="bold"))
+    
+  pcontrol
+  
+# Plot power 
+  power <- subset(data_molten, variable == "controller.i")
+  
+  pallete <- c("#4f314e")
+  ppower <- ggplot(data=power) +
+            geom_line(aes(x=time, y=value, color=variable), size=1) +
+            scale_x_continuous("Time (s)") +
+            scale_y_continuous("Value", limits=c(-5, 10)) +
+            scale_color_manual("power",
+                               labels=c("controller.i"="armature_current"),
+                               values = pallete) +
+            theme(axis.title.y=element_blank(),
+                  axis.title=element_text(size=sizeAxisLabel,face="bold"),
+                  axis.text=element_text(size=sizeAxisLabel),
+                  legend.text=element_text(size=sizeAxisLabel),
+                  legend.title=element_text(size=sizeAxisLabel,face="bold"))
+  ppower
+  
+# Plot window
+  window <- subset(data_molten, variable == "window.displacement")
+  
+  pallete <- c("#be5440")
+  pwindow <- ggplot(data=window) +
+            geom_line(aes(x=time, y=value, color=variable), size=1) +
+            scale_x_continuous("Time (s)") +
+            scale_y_continuous("Value") +
+            scale_color_manual("window_sa",
+                               labels=c("height"="disp"),
+                               values = pallete) +
+            theme(axis.title.y=element_blank(),
+                  axis.title=element_text(size=sizeAxisLabel,face="bold"),
+                  axis.text=element_text(size=sizeAxisLabel),
+                  legend.text=element_text(size=sizeAxisLabel),
+                  legend.title=element_text(size=sizeAxisLabel,face="bold"))
+  pwindow
+  
+# Make multi-grid plot
+  row_plot <- plot_grid(pcontrol, ppower, pwindow, nrow = 3, ncol = 1, align = "v")
+  save_plot("vertical_plot_monolithic.pdf", row_plot, nrow = 3, ncol = 1, base_aspect_ratio = 3)
+  

BIN
ModelicaModels/vertical_plot_monolithic.pdf


+ 1 - 0
SemanticAdaptationForFMI/Experiments/power_window_case_study/monolithic_version/README.txt

@@ -0,0 +1 @@
+This is in the ModelicaModels folder.