Commit 891fcdf3 authored by Pierre Haessig's avatar Pierre Haessig

Working version of car simulation

parent 2d474c18
......@@ -3,6 +3,7 @@ within CarProject;
model Air
parameter Velocity v(displayUnit="km/h") "reverse wind speed";
parameter Velocity v_pert(displayUnit="km/h") "wind speed periodic perturbation";
Force f "total aerdynamic drag force";
Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b "connection to moving object" annotation(
Placement(visible = true, transformation(origin = {98, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.Add add1 annotation(
......@@ -13,9 +14,10 @@ model Air
Placement(visible = true, transformation(origin = {10, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sinePerturb(amplitude = v_pert, freqHz = 0.1) annotation(
Placement(visible = true, transformation(origin = {-90, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a annotation(
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a "connection to ground" annotation(
Placement(visible = true, transformation(origin = {0, -98}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {0, -98}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
f = flange_b.f;
connect(sinePerturb.y, add1.u1) annotation(
Line(points = {{-79, 30}, {-60, 30}, {-60, 6}, {-42, 6}}, color = {0, 0, 127}));
connect(const.y, add1.u2) annotation(
......
......@@ -2,43 +2,46 @@ within CarProject;
model Car
Position s "car position";
Velocity v(displayUnit = "km/h") "car velocity";
parameter Modelica.SIunits.Mass m_car=1e3 "car mass";
parameter Modelica.SIunits.Velocity v_sp(displayUnit = "km/h")=10 "speed set point";
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_road "road connection" annotation(
Placement(visible = true, transformation(origin = {0, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, -100}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Components.Mass mass1(L = 0, m = m_car, s(fixed = true, start = 0)) annotation(
Placement(visible = true, transformation(origin = {50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
CarProject.Components.Controller controller1 annotation(
Placement(visible = true, transformation(origin = {-10, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, -100}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Components.Mass mass1(L = 0, m = m_car, s(fixed = true, start = 0), v(fixed = true, start = 0)) "masse du chassis" annotation(
Placement(visible = true, transformation(origin = {30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
CarProject.Components.Controller controller1 "contrôleur de vitesse" annotation(
Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
CarProject.Components.Engine engine1 annotation(
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Placement(visible = true, transformation(origin = {-10, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Sensors.SpeedSensor speedSensor1 annotation(
Placement(visible = true, transformation(origin = {50, -22}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Placement(visible = true, transformation(origin = {30, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Constant speed_sp(k = v_sp) annotation(
Placement(visible = true, transformation(origin = {-90, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Placement(visible = true, transformation(origin = {-90, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Interfaces.Flange_b flange_air annotation(
Placement(visible = true, transformation(origin = {128, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {90, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Components.Damper damper1(d = 1) annotation(
Placement(visible = true, transformation(origin = {78, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Placement(visible = true, transformation(origin = {90, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {90, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Components.Damper damper1(d = 10) annotation(
Placement(visible = true, transformation(origin = {60, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(speed_sp.y, controller1.v_sp) annotation(
Line(points = {{-79, 40}, {-68, 40}, {-68, 4}, {-62, 4}}, color = {0, 0, 127}));
/*define car position*/
s = mass1.flange_a.s;
connect(damper1.flange_b, flange_air) annotation(
Line(points = {{88, 44}, {126, 44}, {126, 42}, {128, 42}}, color = {0, 127, 0}));
Line(points = {{70, 30}, {90, 30}}, color = {0, 127, 0}));
connect(mass1.flange_b, damper1.flange_a) annotation(
Line(points = {{60, 0}, {62, 0}, {62, 44}, {68, 44}, {68, 44}}, color = {0, 127, 0}));
Line(points = {{40, 0}, {50, 0}, {50, 30}}, color = {0, 127, 0}));
connect(speed_sp.y, controller1.v_sp) annotation(
Line(points = {{-79, 30}, {-68, 30}, {-68, 4}, {-62, 4}}, color = {0, 0, 127}));
connect(mass1.flange_a, speedSensor1.flange) annotation(
Line(points = {{20, 0}, {20, -30}}, color = {0, 127, 0}));
connect(speedSensor1.v, controller1.v) annotation(
Line(points = {{62, -22}, {74, -22}, {74, -50}, {-72, -50}, {-72, -4}, {-62, -4}, {-62, -4}}, color = {0, 0, 127}));
Line(points = {{41, -30}, {74, -30}, {74, -50}, {-72, -50}, {-72, -4}, {-62, -4}}, color = {0, 0, 127}));
connect(engine1.flange_b, mass1.flange_a) annotation(
Line(points = {{0, 0}, {20, 0}}, color = {0, 127, 0}));
connect(engine1.flange_a, flange_road) annotation(
Line(points = {{0, -10}, {0, -10}, {0, -30}, {0, -30}}, color = {0, 127, 0}));
connect(mass1.flange_a, speedSensor1.flange) annotation(
Line(points = {{40, 0}, {40, 0}, {40, -22}, {40, -22}}, color = {0, 127, 0}));
Line(points = {{-10, -10}, {-10, -30}}, color = {0, 127, 0}));
connect(controller1.f, engine1.f) annotation(
Line(points = {{-38, 0}, {-12, 0}, {-12, 0}, {-12, 0}}, color = {0, 0, 127}));
connect(engine1.flange_b, mass1.flange_a) annotation(
Line(points = {{10, 0}, {40, 0}, {40, 0}, {40, 0}}, color = {0, 127, 0}));
Line(points = {{-38, 0}, {-22, 0}}, color = {0, 0, 127}));
/*define car position*/
s = mass1.s;
v = mass1.v;
annotation(
Icon(graphics = {Polygon(fillColor = {239, 41, 41}, fillPattern = FillPattern.Solid, points = {{-100, -60}, {100, -60}, {100, 0}, {40, 60}, {-80, 60}, {-100, 0}, {-100, -60}}), Ellipse(origin = {-50, -70}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-30, -30}, {30, 30}}, endAngle = 360), Ellipse(origin = {50, -70}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-30, -30}, {30, 30}}, endAngle = 360), Text(origin = {0, 120}, extent = {{-100, 20}, {100, -20}}, textString = "%name"), Text(origin = {-3, -9}, extent = {{-97, 29}, {103, -31}}, textString = "m=%m_car"), Line(origin = {60, 70}, points = {{20, 0}, {-20, 0}}, color = {79, 138, 226}, thickness = 1, arrow = {Arrow.None, Arrow.Open})}, coordinateSystem(initialScale = 0.1)));
Icon(graphics = {Polygon(fillColor = {239, 41, 41}, fillPattern = FillPattern.Solid, points = {{-100, -60}, {100, -60}, {100, 0}, {40, 60}, {-80, 60}, {-100, 0}, {-100, -60}}), Ellipse(origin = {-50, -70}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-30, -30}, {30, 30}}, endAngle = 360), Ellipse(origin = {50, -70}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-30, -30}, {30, 30}}, endAngle = 360), Text(origin = {0, 120}, extent = {{-100, 20}, {100, -20}}, textString = "%name"), Text(origin = {-3, -9}, extent = {{-97, 29}, {103, -31}}, textString = "m=%m_car"), Line(origin = {60, 70}, points = {{20, 0}, {-20, 0}}, color = {79, 138, 226}, thickness = 1, arrow = {Arrow.None, Arrow.Open})}, coordinateSystem(initialScale = 0.1)),
Diagram(graphics = {Text(origin = {51, 53}, extent = {{-33, 5}, {33, -5}}, textString = "frottement de l'air")}));
end Car;
\ No newline at end of file
......@@ -4,7 +4,7 @@ model CarTest
extends Modelica.Icons.Example;
CarProject.Car car1(m_car = 1e3, v_sp = 27.7778) annotation(
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
CarProject.Air air1(v = 5.55556, v_pert = 2.77778) annotation(
CarProject.Air air1(v = 11.1111, v_pert = 5.55556) annotation(
Placement(visible = true, transformation(origin = {70, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
CarProject.Road road1 annotation(
Placement(visible = true, transformation(origin = {10, -50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
......@@ -16,4 +16,6 @@ equation
connect(car1.flange_road, road1.flange) annotation(
Line(points = {{10, -20}, {10, -49}}, color = {0, 127, 0}));
annotation(
Diagram(graphics = {Text(origin = {0, 80}, extent = {{-100, 20}, {100, -20}}, textString = "Car test on the road")}));end CarTest;
\ No newline at end of file
experiment(StopTime=180),
Diagram(graphics = {Text(origin = {0, 80}, extent = {{-100, 20}, {100, -20}}, textString = "Car test on the road")}));
end CarTest;
\ No newline at end of file
within CarProject.Components;
model Controller
parameter Modelica.SIunits.Time tc = 5 "expected closed loop time constant (cf. Skogestad 2003)";
Modelica.Blocks.Interfaces.RealOutput f "force control" annotation(
Placement(visible = true, transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput v_sp "speed set point" annotation(
......@@ -9,16 +10,16 @@ model Controller
Placement(visible = true, transformation(origin = {-100, -50}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Math.Feedback feedback1 annotation(
Placement(visible = true, transformation(origin = {-30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.Gain gain1(k = 100) annotation(
Modelica.Blocks.Continuous.PI PI(T = 4 * tc, k = 1000 / tc) annotation(
Placement(visible = true, transformation(origin = {30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(feedback1.y, gain1.u) annotation(
Line(points = {{-21, 0}, {18, 0}}, color = {0, 0, 127}));
connect(PI.y, f) annotation(
Line(points = {{41, 0}, {106, 0}}, color = {0, 0, 127}));
connect(feedback1.y, PI.u) annotation(
Line(points = {{-20, 0}, {18, 0}}, color = {0, 0, 127}));
connect(v_sp, feedback1.u1) annotation(
Line(points = {{-100, 0}, {-38, 0}}, color = {0, 0, 127}));
connect(v, feedback1.u2) annotation(
Line(points = {{-100, -50}, {-30, -50}, {-30, -8}}, color = {0, 0, 127}));
connect(gain1.y, f) annotation(
Line(points = {{41, 0}, {106, 0}}, color = {0, 0, 127}));
annotation(
Icon(graphics = {Rectangle(fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {3, -2}, extent = {{-81, 80}, {81, -80}}, textString = "Speed\nControl"), Text(origin = {-120, 6}, extent = {{-20, 14}, {20, -12}}, textString = "v*"), Text(origin = {-124, -70}, extent = {{-16, 10}, {24, -18}}, textString = "v")}));end Controller;
\ No newline at end of file
within CarProject.Components;
model Engine "model of the engine and the wheels"
model Engine "model of the engine and the wheels (force road -> car)"
parameter Force f_max=2000 "maximul force of the engine";
Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b annotation(
Placement(visible = true, transformation(origin = {74, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {102, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a annotation(
Placement(visible = true, transformation(origin = {-50, -80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {0, -98}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Sources.Force force1(useSupport = true) annotation(
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput f "engine force" annotation(
Placement(visible = true, transformation(origin = {-80, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput f "engine force set point" annotation(
Placement(visible = true, transformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Nonlinear.Limiter limiter1(limitsAtInit = true, uMax = f_max) annotation(
Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(f, force1.f) annotation(
Line(points = {{-80, 0}, {-14, 0}, {-14, 0}, {-12, 0}}, color = {0, 0, 127}));
connect(limiter1.y, force1.f) annotation(
Line(points = {{-38, 0}, {-12, 0}, {-12, 0}, {-12, 0}}, color = {0, 0, 127}));
connect(f, limiter1.u) annotation(
Line(points = {{-120, 0}, {-62, 0}, {-62, 0}, {-62, 0}}, color = {0, 0, 127}));
connect(flange_a, force1.support) annotation(
Line(points = {{-50, -80}, {0, -80}, {0, -10}}, color = {0, 127, 0}));
connect(flange_b, force1.flange) annotation(
......
within CarProject;
package Interfaces "subpackage for custom ports or partial classes. This example has none"
extends Modelica.Icons.InterfacesPackage;
end Interfaces;
\ No newline at end of file
......@@ -5,6 +5,9 @@ model Road "the road is a fixed mechanical reference"
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Interfaces.Flange_b flange annotation(
Placement(visible = true, transformation(origin = {0, 100}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {0, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(flange, fixed1.flange) annotation(
Line(points = {{0, 100}, {0, 100}, {0, 0}, {0, 0}}, color = {0, 127, 0}));
annotation(
Icon(graphics = {Rectangle(origin = {0, -20}, fillColor = {85, 87, 83}, fillPattern = FillPattern.Solid, extent = {{-100, 20}, {100, -20}}), Text(origin = {0, -71}, extent = {{-100, 29}, {100, -29}}, textString = "Road")}));
end Road;
\ No newline at end of file
package CarProject "Root package of the car modeling project"
extends Modelica.Icons.Package;
/*Import of useful physical types*/
import Modelica.SIunits.{Position,Velocity};
import Modelica.SIunits.{Position,Velocity,Force};
annotation(
uses(Modelica(version = "3.2.2")),
......
......@@ -3,3 +3,4 @@ Car
Road
Air
Components
Interfaces
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment