Car.mo 4.03 KB
Newer Older
1 2
within CarProject;

Pierre Haessig's avatar
Pierre Haessig committed
3
model Car "Car with a speed control"
4
  Position s "car position";
5
  Velocity v(displayUnit = "km/h") "car velocity";
6 7 8
  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(
9 10 11 12
    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(
13
    Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Pierre Haessig's avatar
Pierre Haessig committed
14
  CarProject.Components.Engine engine annotation(
15
    Placement(visible = true, transformation(origin = {-10, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
16
  Modelica.Mechanics.Translational.Sensors.SpeedSensor speedSensor1 annotation(
17
    Placement(visible = true, transformation(origin = {30, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
18
  Modelica.Blocks.Sources.Constant speed_sp(k = v_sp) annotation(
19
    Placement(visible = true, transformation(origin = {-90, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
20
  Modelica.Mechanics.Translational.Interfaces.Flange_b flange_air annotation(
21 22 23
    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)));
24 25
equation
  connect(damper1.flange_b, flange_air) annotation(
26
    Line(points = {{70, 30}, {90, 30}}, color = {0, 127, 0}));
27
  connect(mass1.flange_b, damper1.flange_a) annotation(
28 29 30 31 32
    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}));
33
  connect(speedSensor1.v, controller1.v) annotation(
34
    Line(points = {{41, -30}, {74, -30}, {74, -50}, {-72, -50}, {-72, -4}, {-62, -4}}, color = {0, 0, 127}));
Pierre Haessig's avatar
Pierre Haessig committed
35
  connect(engine.flange_b, mass1.flange_a) annotation(
36
    Line(points = {{0, 0}, {20, 0}}, color = {0, 127, 0}));
Pierre Haessig's avatar
Pierre Haessig committed
37
  connect(engine.flange_a, flange_road) annotation(
38
    Line(points = {{-10, -10}, {-10, -30}}, color = {0, 127, 0}));
Pierre Haessig's avatar
Pierre Haessig committed
39
  connect(controller1.f, engine.f) annotation(
40 41 42 43
    Line(points = {{-38, 0}, {-22, 0}}, color = {0, 0, 127}));
  /*define car position*/
  s = mass1.s;
  v = mass1.v;
44
  annotation(
Pierre Haessig's avatar
Pierre Haessig committed
45
    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, 80}, lineColor = {0, 67, 168}, fillColor = {0, 67, 168}, extent = {{-100, 20}, {40, -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)),
46
    Diagram(graphics = {Text(origin = {51, 53}, extent = {{-33, 5}, {33, -5}}, textString = "frottement de l'air")}));
47
end Car;