Commit 2d474c18 authored by Pierre Haessig's avatar Pierre Haessig

first version. Structure ok, but doesn't simulate

parents
within CarProject;
model Air
parameter Velocity v(displayUnit="km/h") "reverse wind speed";
parameter Velocity v_pert(displayUnit="km/h") "wind speed periodic perturbation";
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(
Placement(visible = true, transformation(origin = {-30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Constant const(k = -v) annotation(
Placement(visible = true, transformation(origin = {-90, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Mechanics.Translational.Sources.Speed windSpeed(useSupport = true) annotation(
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(
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
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(
Line(points = {{-78, -30}, {-60, -30}, {-60, -6}, {-42, -6}}, color = {0, 0, 127}));
connect(windSpeed.flange, flange_b) annotation(
Line(points = {{20, 0}, {96, 0}, {96, 0}, {98, 0}}, color = {0, 127, 0}));
connect(windSpeed.support, flange_a) annotation(
Line(points = {{10, -10}, {0, -10}, {0, -98}}, color = {0, 127, 0}));
connect(add1.y, windSpeed.v_ref) annotation(
Line(points = {{-19, 0}, {-2, 0}}, color = {0, 0, 127}));
annotation(
Icon(graphics = {Rectangle(origin = {0, -10}, fillColor = {210, 228, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 110}, {100, -90}}), Text(origin = {-2, 1}, extent = {{-54, 39}, {54, -39}}, textString = "Air")}),
Diagram(coordinateSystem(initialScale = 0.1)));end Air;
\ No newline at end of file
within CarProject;
model Car
Position s "car position";
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 = {-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)));
Modelica.Mechanics.Translational.Sensors.SpeedSensor speedSensor1 annotation(
Placement(visible = true, transformation(origin = {50, -22}, 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)));
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)));
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}));
connect(mass1.flange_b, damper1.flange_a) annotation(
Line(points = {{60, 0}, {62, 0}, {62, 44}, {68, 44}, {68, 44}}, 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}));
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}));
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}));
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)));
end Car;
\ No newline at end of file
within CarProject;
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(
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)));
equation
connect(air1.flange_b, car1.flange_air) annotation(
Line(points = {{60, 10}, {18, 10}, {18, 14}, {18, 14}}, color = {0, 127, 0}));
connect(air1.flange_a, road1.flange) annotation(
Line(points = {{70, 0}, {70, -49}, {10, -49}}, color = {0, 127, 0}));
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
within CarProject.Components;
model Controller
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(
Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput v "speed measurement" annotation(
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(
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(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"
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)));
equation
connect(f, force1.f) annotation(
Line(points = {{-80, 0}, {-14, 0}, {-14, 0}, {-12, 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(
Line(points = {{74, 0}, {10, 0}}, color = {0, 127, 0}));
end Engine;
\ No newline at end of file
within CarProject;
package Components "Components for the car"
extends Modelica.Icons.UtilitiesPackage;
end Components;
\ No newline at end of file
within CarProject;
model Road "the road is a fixed mechanical reference"
Modelica.Mechanics.Translational.Components.Fixed fixed1 annotation(
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)));
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
within CarProject;
type Velocity = Modelica.SIunits.Velocity(displayUnit = "km/h");
\ 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};
annotation(
uses(Modelica(version = "3.2.2")),
Icon(graphics = {Polygon(origin = {4, 1}, fillColor = {255, 0, 0}, fillPattern = FillPattern.Solid, points = {{-84, -1}, {-64, 51}, {38, 51}, {84, -1}, {84, -51}, {-84, -51}, {-84, -1}}), Ellipse(origin = {-46, -71}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-18, 19}, {18, -19}}, endAngle = 360), Ellipse(origin = {50, -71}, fillColor = {136, 138, 133}, fillPattern = FillPattern.Solid, extent = {{-18, 19}, {18, -19}}, endAngle = 360)}));
end CarProject;
\ No newline at end of file
CarTest
Car
Road
Air
Components
# Example Modelica Project
This project is a minimal simulation of car on a road.
It is intended as a generic example for all Modelica Modeling projects
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