From 1fffa6f0cf881349d0651b0962d2d91f3c59209e Mon Sep 17 00:00:00 2001 From: "Claudio (xjobb Martina)" <claudio@neumann.control.lth.se> Date: Wed, 29 Aug 2018 17:16:45 +0200 Subject: [PATCH] modelicaExamples1 --- GPS_pw_modeling.mo | 109 ++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 76 deletions(-) diff --git a/GPS_pw_modeling.mo b/GPS_pw_modeling.mo index 26f9c08..844a090 100644 --- a/GPS_pw_modeling.mo +++ b/GPS_pw_modeling.mo @@ -29,8 +29,7 @@ package GPS_pw_modeling Placement(visible = true, transformation(origin = {-167, 101}, extent = {{-11, -11}, {11, 11}}, rotation = 0), iconTransformation(origin = {-94, 2}, extent = {{-26, -26}, {26, 26}}, rotation = 0))); Modelica.Blocks.Interfaces.BooleanInput on_signal annotation( Placement(visible = true, transformation(origin = {-133, 93}, extent = {{-11, -11}, {11, 11}}, rotation = 0), iconTransformation(origin = {-40, 100}, extent = {{-20, -20}, {20, 20}}, rotation = -90))); - Modelica.Blocks.Interfaces.BooleanOutput position_out annotation( - Placement(visible = true, transformation(origin = {176, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0), iconTransformation(origin = {95, -15}, extent = {{25, -25}, {-25, 25}}, rotation = 0))); + Modelica.Blocks.Interfaces.BooleanOutput position_out annotation( Placement(visible = true, transformation(origin = {176, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0), iconTransformation(origin = {95, -15}, extent = {{25, -25}, {-25, 25}}, rotation = 0))); Modelica.Blocks.Interfaces.RealOutput power_consumption annotation( Placement(visible = true, transformation(origin = {-160, 84}, extent = {{-8, -8}, {8, 8}}, rotation = 0), iconTransformation(origin = {95, 41}, extent = {{-25, -25}, {25, 25}}, rotation = 180))); //States @@ -50,16 +49,16 @@ package GPS_pw_modeling Placement(visible = true, transformation(origin = {100, 58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Modelica.StateGraph.Step freq_and_phase(nIn = 3, nOut = 2) annotation( Placement(visible = true, transformation(origin = {-4, 58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Modelica.StateGraph.Step cold_start(nOut = 2) annotation( + Modelica.StateGraph.Step cold_start(nOut = 2) annotation( Placement(visible = true, transformation(origin = {-82, 58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); //Transitions Modelica.StateGraph.Transition lock_freq_and_phase(enableTimer = true, waitTime = freq_and_phase_acquisition_time) annotation( Placement(visible = true, transformation(origin = {-40, 58}, extent = {{-10, 10}, {10, -10}}, rotation = 0))); Modelica.StateGraph.Transition lock_freq_and_phase_1(condition = sv_ephemeris >= required_satellites, enableTimer = true, waitTime = freq_and_phase_acquisition_time) annotation( Placement(visible = true, transformation(origin = {34, 24}, extent = {{-10, 10}, {10, -10}}, rotation = 90))); - Modelica.StateGraph.Transition lock_freq_and_Phase_3(condition = sv_ephemeris < required_satellites, enableTimer= true, waitTime = freq_and_phase_acquisition_time) annotation( + Modelica.StateGraph.Transition lock_freq_and_Phase_3(condition = sv_ephemeris < required_satellites, enableTimer = true, waitTime = freq_and_phase_acquisition_time) annotation( Placement(visible = true, transformation(origin = {-32, 18}, extent = {{-10, 10}, {10, -10}}, rotation = 90))); - Modelica.StateGraph.Transition lock_freq_and_phase_2(condition = sv_ephemeris >= required_satellites, enableTimer= true, waitTime = freq_and_phase_acquisition_time_fast) annotation( + Modelica.StateGraph.Transition lock_freq_and_phase_2(condition = sv_ephemeris >= required_satellites, enableTimer = true, waitTime = freq_and_phase_acquisition_time_fast) annotation( Placement(visible = true, transformation(origin = {70, 24}, extent = {{-10, 10}, {10, -10}}, rotation = 90))); Modelica.StateGraph.Transition lock_freq_and_Phase_4(condition = sv_ephemeris < required_satellites, enableTimer = true, waitTime = freq_and_phase_acquisition_time_fast) annotation( Placement(visible = true, transformation(origin = {-2, 18}, extent = {{-10, 10}, {10, -10}}, rotation = 90))); @@ -85,13 +84,13 @@ package GPS_pw_modeling Placement(visible = true, transformation(origin = {130, 18}, extent = {{-10, 10}, {10, -10}}, rotation = -90))); Modelica.Blocks.MathBoolean.Not not1 annotation( Placement(visible = true, transformation(origin = {22, 94}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Modelica.StateGraph.TransitionWithSignal turn_off_antenna2 annotation( + Modelica.StateGraph.TransitionWithSignal turn_off_antenna2 annotation( Placement(visible = true, transformation(origin = {-126, 14}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); - Modelica.StateGraph.TransitionWithSignal turn_off_antenna3 annotation( + Modelica.StateGraph.TransitionWithSignal turn_off_antenna3 annotation( Placement(visible = true, transformation(origin = {-126, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0))); - Modelica.StateGraph.TransitionWithSignal turn_off_antenna4 annotation( + Modelica.StateGraph.TransitionWithSignal turn_off_antenna4 annotation( Placement(visible = true, transformation(origin = {104, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Modelica.StateGraph.TransitionWithSignal turn_off_antenna5 annotation( + Modelica.StateGraph.TransitionWithSignal turn_off_antenna5 annotation( Placement(visible = true, transformation(origin = {66, -60}, extent = {{-10, 10}, {10, -10}}, rotation = -90))); equation connect(turn_off_antenna5.condition, not1.y) annotation( @@ -100,7 +99,7 @@ package GPS_pw_modeling Line(points = {{66, -62}, {66, -62}, {66, -70}, {102, -70}, {102, -90}, {92, -90}, {92, -90}})); connect(turn_off_antenna5.inPort, warm_start.outPort[3]) annotation( Line(points = {{66, -56}, {52, -56}, {52, 4}, {34, 4}, {34, -2}, {34, -2}})); - connect(turn_on_warm_start.condition, on_signal) annotation( + connect(turn_on_warm_start.condition, on_signal) annotation( Line(points = {{44, -60}, {50.75, -60}, {50.75, -50}, {-106, -50}, {-106, 93}, {-133, 93}}, color = {255, 0, 255})); connect(not1.y, turn_off_antenna4.condition) annotation( Line(points = {{34, 94}, {200, 94}, {200, -16}, {104, -16}, {104, -10}, {104, -10}}, color = {255, 0, 255})); @@ -108,13 +107,13 @@ package GPS_pw_modeling Line(points = {{106, 2}, {130, 2}, {130, -8}, {130, -8}})); connect(turn_off_antenna4.inPort, hot_start.outPort[3]) annotation( Line(points = {{100, 2}, {72, 2}, {72, -10}, {72, -10}})); - connect(hot_start_available.outPort[2], ephemeris_data_expire_2.inPort) annotation( + connect(hot_start_available.outPort[2], ephemeris_data_expire_2.inPort) annotation( Line(points = {{130, -30.5}, {130, -44}, {172, -44}, {172, -110}, {-134, -110}}, thickness = 0.5)); - connect(turn_on_hot_start.inPort, hot_start_available.outPort[3]) annotation( + connect(turn_on_hot_start.inPort, hot_start_available.outPort[3]) annotation( Line(points = {{104, -44}, {130, -44}, {130, -30.5}})); - connect(lose_hot_start.inPort, hot_start_available.outPort[1]) annotation( + connect(lose_hot_start.inPort, hot_start_available.outPort[1]) annotation( Line(points = {{128, -74}, {128, -52.25}, {130, -52.25}, {130, -30.5}})); - connect(hot_start_available.inPort[1], turn_off_antenna.outPort) annotation( + connect(hot_start_available.inPort[1], turn_off_antenna.outPort) annotation( Line(points = {{130, -9}, {130, 18}}, thickness = 0.5)); connect(turn_on_hot_start.outPort, hot_start.inPort[1]) annotation( Line(points = {{98.5, -44}, {72, -44}, {72, -31}})); @@ -122,19 +121,19 @@ package GPS_pw_modeling Line(points = {{72, -9.5}, {72, 8}, {-2, 8}, {-2, 14}}, thickness = 0.5)); connect(hot_start.outPort[1], lock_freq_and_phase_2.inPort) annotation( Line(points = {{72, -9.5}, {70, -9.5}, {70, 20}}, thickness = 0.5)); - connect(turn_on_hot_start.condition, on_signal) annotation( + connect(turn_on_hot_start.condition, on_signal) annotation( Line(points = {{100, -34}, {100, 22}, {-106, 22}, {-106, 93}, {-133, 93}}, color = {255, 0, 255})); - connect(warm_start_available.inPort[1], lose_hot_start.outPort) annotation( + connect(warm_start_available.inPort[1], lose_hot_start.outPort) annotation( Line(points = {{91, -90}, {91, -90.125}, {105, -90.125}, {105, -90.25}, {128, -90.25}, {128, -79.5}}, thickness = 0.5)); - connect(turn_on_warm_start.inPort, warm_start_available.outPort[2]) annotation( + connect(turn_on_warm_start.inPort, warm_start_available.outPort[2]) annotation( Line(points = {{32, -64}, {32, -87.25}, {69.5, -87.25}, {69.5, -90}})); - connect(warm_start_available.outPort[1], ephemeris_data_expire_1.inPort) annotation( + connect(warm_start_available.outPort[1], ephemeris_data_expire_1.inPort) annotation( Line(points = {{69.5, -92}, {4.75, -92}, {4.75, -104}, {-122, -104}}, thickness = 0.5)); connect(ephemeris_data_expire_2.outPort, GPS_off.inPort[2]) annotation( Line(points = {{-137.5, -110}, {-172, -110}, {-172, 58}, {-161, 58}})); connect(ephemeris_data_expire_1.outPort, GPS_off.inPort[1]) annotation( Line(points = {{-125.5, -104}, {-172, -104}, {-172, 58}, {-161, 58}})); - connect(warm_start.inPort[1], turn_on_warm_start.outPort) annotation( + connect(warm_start.inPort[1], turn_on_warm_start.outPort) annotation( Line(points = {{34, -23}, {34, -40.75}, {30, -40.75}, {30, -58.5}}, thickness = 0.5)); connect(turn_off_antenna3.condition, not1.y) annotation( Line(points = {{-126, -42}, {-126, -42}, {-126, -48}, {-190, -48}, {-190, 130}, {56, 130}, {56, 94}, {34, 94}, {34, 94}}, color = {255, 0, 255})); @@ -186,7 +185,7 @@ package GPS_pw_modeling Line(points = {{-44, 58}, {-73.5, 58}})); //power consumption OUTPUT power_consumption = if on_signal then power_consumption_over_time else 0; - //is position available OUTPUT +//is position available OUTPUT position_out = min(sv_tracked_freq_phase, sv_ephemeris) > required_satellites; algorithm when {pre(lock_freq_and_phase.fire), pre(lock_freq_and_phase_1.fire), pre(lock_freq_and_phase_2.fire)} then @@ -216,66 +215,24 @@ package GPS_pw_modeling end GPS_pw_simulator; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - model test_GPS - GPS_pw_simulator gps annotation( - Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + GPS_pw_modeling.GPS_pw_simulator gps annotation( + Placement(visible = true, transformation(origin = {32, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Modelica.Blocks.Sources.IntegerTable visible_satellites(table = [0, 8; 100, 7; 500, 12]) annotation( - Placement(visible = true, transformation(origin = {-72, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Modelica.Blocks.Sources.BooleanExpression turn_on(y = if time > 10 then if time < 500 then true else false else false) annotation( - Placement(visible = true, transformation(origin = {-76, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Modelica.Blocks.Sources.BooleanTable turn_on_table(table = {0, 30, 100, 120, 125, 140, 145, 170, 175, 200, 205, 2000, 2010, 2050, 2500, 3000}) annotation( - Placement(visible = true, transformation(origin = {-46, 64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Placement(visible = true, transformation(origin = {-90, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanTable general_example(table = {0, 30, 100, 120, 125, 140, 145, 170, 175, 200, 205, 2000, 2010, 2050, 2500, 3000}) annotation( + Placement(visible = true, transformation(origin = {-90, 88}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanTable slow_and_fast(table = {20, 85, 90, 91, 100, 101, 110, 111, 120, 121, 1875, 2100}) annotation( + Placement(visible = true, transformation(origin = {-68, -12}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerTable constant_number(table = [0, 8]) annotation( + Placement(visible = true, transformation(origin = {-36, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation - connect(turn_on_table.y, gps.on_signal) annotation( - Line(points = {{-34, 64}, {-2, 64}, {-2, 10}, {-2, 10}}, color = {255, 0, 255})); - connect(visible_satellites.y, gps.visible_satellites) annotation( - Line(points = {{-60, 0}, {-8, 0}, {-8, 0}, {-8, 0}}, color = {255, 127, 0})); + connect(constant_number.y, gps.visible_satellites) annotation( + Line(points = {{-24, -60}, {22, -60}, {22, -60}, {22, -60}}, color = {255, 127, 0})); + connect(slow_and_fast.y, gps.on_signal) annotation( + Line(points = {{-56, -12}, {28, -12}, {28, -50}, {28, -50}}, color = {255, 0, 255})); annotation( - experiment(StartTime = 0, StopTime = 1000, Tolerance = 1e-06, Interval = 0.002), + experiment(StartTime = 0, StopTime = 2100, Tolerance = 1e-6, Interval = 0.0042), __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl")); end test_GPS; -- GitLab