Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gps-modeling
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martina Maggio
gps-modeling
Commits
e7b0d0d8
Commit
e7b0d0d8
authored
6 years ago
by
Claudio Mandrioli
Browse files
Options
Downloads
Patches
Plain Diff
commented modelica code is GPS simulator class and moved to modelica folder
parent
db28a6ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modelica/GPS_pw_modeling.mo
+453
-0
453 additions, 0 deletions
modelica/GPS_pw_modeling.mo
with
453 additions
and
0 deletions
modelica/GPS_pw_modeling.mo
0 → 100755
+
453
−
0
View file @
e7b0d0d8
package GPS_pw_modeling
model GPS_pw_simulator_old
//prima versione - obsoleta
//
//parameters
parameter Integer required_satellites = 4;
//number of satellites required for sufficient accuracy
//parameter Integer number_of_channels = 16;
//number of channels available in the device
parameter Real power_consumption_over_time = 387.2;
//power consumed when antenna is on (assumed constant) [mW]
parameter Real time_to_get_ephemeris = 59;
//time to get ephemeris data after freq&phase are locked (wrost case default)
parameter Real freq_and_phase_acquisition_time = 0.01;
//frequency and phase acquisition time when exaustive search is required (random)
parameter Real freq_and_phase_acquisition_time_fast = 0.005;
//frequency and phase acquisition time for hot start (random)
parameter Real ephemeris_duration = 1800;
//how long the eohemeris data will be reliable
parameter Real time_lose_hot_start = 10;
//how long it takes to lose possibility of hot start
//states
Integer sv_tracked_freq_phase(start = 0);
//number of satellites of which frequency and phase are available
Integer sv_ephemeris(start = 0);
//number of satellites of which ephemeris data are available;
Real expiration_time(start = -1.0);
//time at which ephemeris data will expire
//Inputs and outputs
Modelica.Blocks.Interfaces.IntegerInput visible_satellites annotation(
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 = {-132, 118}, extent = {{-12, -12}, {12, 12}}, 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.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
inner Modelica.StateGraph.StateGraphRoot stateGraphRoot annotation(
Placement(visible = false, transformation(origin = {-90, -90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.InitialStep GPS_off(nIn = 4) annotation(
Placement(visible = true, transformation(origin = {-150, 58}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.Step warm_start(nOut = 3) annotation(
Placement(visible = true, transformation(origin = {34, -12}, extent = {{10, -10}, {-10, 10}}, rotation = -90)));
Modelica.StateGraph.Step hot_start(nIn = 2, nOut = 3) annotation(
Placement(visible = true, transformation(origin = {72, -20}, extent = {{10, -10}, {-10, 10}}, rotation = -90)));
Modelica.StateGraph.Step warm_start_available(nIn = 2, nOut = 2) annotation(
Placement(visible = true, transformation(origin = {80, -90}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.StateGraph.Step hot_start_available(nIn = 2, nOut = 3) annotation(
Placement(visible = true, transformation(origin = {130, -20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
Modelica.StateGraph.Step position_available(nIn = 4, nOut = 3) annotation(
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(nIn = 2, 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(
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(
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)));
Modelica.StateGraph.Transition get_ephemeris_data(enableTimer = true, waitTime = time_to_get_ephemeris) annotation(
Placement(visible = true, transformation(origin = {40, 58}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
Modelica.StateGraph.Transition update_ephemeris_data(enableTimer = true, waitTime = time_to_get_ephemeris) annotation(
Placement(visible = true, transformation(origin = {154, 58}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
Modelica.StateGraph.Transition lose_hot_start(enableTimer = true, waitTime = time_lose_hot_start) annotation(
Placement(visible = true, transformation(origin = {128, -78}, extent = {{-10, 10}, {10, -10}}, rotation = -90)));
Modelica.StateGraph.Transition ephemeris_data_expire_1(condition = time > expiration_time) annotation(
Placement(visible = true, transformation(origin = {-126, -104}, extent = {{10, 10}, {-10, -10}}, rotation = 0)));
Modelica.StateGraph.Transition ephemeris_data_expire_2(condition = time > expiration_time) annotation(
Placement(visible = true, transformation(origin = {-138, -110}, extent = {{10, 10}, {-10, -10}}, rotation = 0)));
//turn on transitions
Modelica.StateGraph.TransitionWithSignal turn_on annotation(
Placement(visible = true, transformation(origin = {-116, 58}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_on_hot_start annotation(
Placement(visible = true, transformation(origin = {100, -44}, extent = {{10, 10}, {-10, -10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_on_warm_start annotation(
Placement(visible = true, transformation(origin = {32, -60}, extent = {{10, 10}, {-10, -10}}, rotation = -90)));
//turn off transition
Modelica.StateGraph.TransitionWithSignal turn_off_antenna annotation(
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, 118}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
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(
Placement(visible = true, transformation(origin = {-126, -30}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
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(
Placement(visible = true, transformation(origin = {66, -60}, extent = {{-10, 10}, {10, -10}}, rotation = -90)));
Modelica.StateGraph.Transition satellite_outage annotation(
Placement(visible = true, transformation(origin = {158, 100}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(satellite_outage.outPort, hot_start.inPort[2]) annotation(
Line(points = {{160, 100}, {212, 100}, {212, -40}, {72, -40}, {72, -30}, {72, -30}}));
connect(position_available.outPort[3], satellite_outage.inPort) annotation(
Line(points = {{110, 58}, {130, 58}, {130, 100}, {154, 100}}, thickness = 0.5));
connect(on_signal, turn_on.condition) annotation(
Line(points = {{-132, 118}, {-116, 118}, {-116, 70}}, color = {255, 0, 255}));
connect(not1.u, on_signal) annotation(
Line(points = {{8, 118}, {-132, 118}}, color = {255, 0, 255}));
connect(turn_on_hot_start.condition, on_signal) annotation(
Line(points = {{100, -34}, {100, 22}, {-106, 22}, {-106, 118}, {-132, 118}}, color = {255, 0, 255}));
connect(turn_on_warm_start.condition, on_signal) annotation(
Line(points = {{44, -60}, {50.75, -60}, {50.75, -50}, {-106, -50}, {-106, 118}, {-132, 118}}, color = {255, 0, 255}));
connect(not1.y, turn_off_antenna.condition) annotation(
Line(points = {{34, 116}, {190, 116}, {190, 18}, {142, 18}}, color = {255, 0, 255}));
connect(not1.y, turn_off_antenna2.condition) annotation(
Line(points = {{34, 116}, {56, 116}, {56, 130}, {-190, 130}, {-190, -6}, {-126, -6}, {-126, 2}}, color = {255, 0, 255}));
connect(turn_off_antenna3.condition, not1.y) annotation(
Line(points = {{-126, -42}, {-126, -48}, {-190, -48}, {-190, 130}, {56, 130}, {56, 116}, {34, 116}}, color = {255, 0, 255}));
connect(not1.y, turn_off_antenna4.condition) annotation(
Line(points = {{34, 116}, {200, 116}, {200, -16}, {104, -16}, {104, -10}}, color = {255, 0, 255}));
connect(turn_off_antenna5.condition, not1.y) annotation(
Line(points = {{78, -60}, {200, -60}, {200, 116}, {34, 116}}, color = {255, 0, 255}));
connect(update_ephemeris_data.inPort, position_available.outPort[2]) annotation(
Line(points = {{150, 58}, {131.25, 58}, {131.25, 56}, {110.5, 56}}));
connect(update_ephemeris_data.outPort, position_available.inPort[2]) annotation(
Line(points = {{155.5, 58}, {185.5, 58}, {185.5, 88}, {75.5, 88}, {75.5, 56}, {89, 56}}));
connect(turn_off_antenna5.outPort, warm_start_available.inPort[2]) annotation(
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_off_antenna4.outPort, hot_start_available.inPort[2]) annotation(
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(
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(
Line(points = {{104, -44}, {130, -44}, {130, -30.5}}));
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(
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}}));
connect(hot_start.outPort[2], lock_freq_and_Phase_4.inPort) annotation(
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(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(
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(
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(
Line(points = {{34, -23}, {34, -40.75}, {30, -40.75}, {30, -58.5}}, thickness = 0.5));
connect(turn_off_antenna3.outPort, GPS_off.inPort[4]) annotation(
Line(points = {{-128, -30}, {-172, -30}, {-172, 58}, {-160, 58}, {-160, 58}}));
connect(freq_and_phase.outPort[2], turn_off_antenna3.inPort) annotation(
Line(points = {{6, 58}, {14, 58}, {14, -30}, {-122, -30}, {-122, -30}}, thickness = 0.5));
connect(turn_off_antenna2.inPort, cold_start.outPort[2]) annotation(
Line(points = {{-122, 14}, {-60, 14}, {-60, 58}, {-72, 58}, {-72, 58}, {-72, 58}}));
connect(turn_off_antenna2.outPort, GPS_off.inPort[3]) annotation(
Line(points = {{-128, 14}, {-172, 14}, {-172, 58}, {-160, 58}, {-160, 58}}));
connect(lock_freq_and_phase_2.outPort, position_available.inPort[3]) annotation(
Line(points = {{70, 26}, {70, 26}, {70, 58}, {90, 58}, {90, 58}}));
connect(get_ephemeris_data.outPort, position_available.inPort[1]) annotation(
Line(points = {{41.5, 58}, {65.25, 58}, {65.25, 56}, {89, 56}}));
connect(lock_freq_and_phase_1.outPort, position_available.inPort[4]) annotation(
Line(points = {{34, 25.5}, {34, 39.5}, {72, 39.5}, {72, 56}, {89, 56}}));
connect(turn_off_antenna.inPort, position_available.outPort[1]) annotation(
Line(points = {{130, 22}, {130, 56}, {110.5, 56}}));
connect(get_ephemeris_data.inPort, freq_and_phase.outPort[1]) annotation(
Line(points = {{36, 58}, {6.5, 58}}));
connect(lock_freq_and_phase.outPort, freq_and_phase.inPort[1]) annotation(
Line(points = {{-38, 58}, {-15, 58}}));
connect(lock_freq_and_Phase_4.outPort, freq_and_phase.inPort[3]) annotation(
Line(points = {{-2, 20}, {-2, 38}, {-24, 38}, {-24, 58}, {-15, 58}}));
connect(lock_freq_and_Phase_3.outPort, freq_and_phase.inPort[2]) annotation(
Line(points = {{-32, 20}, {-32, 38}, {-24, 38}, {-24, 58}, {-15, 58}}));
connect(warm_start.outPort[2], lock_freq_and_Phase_3.inPort) annotation(
Line(points = {{34, -2}, {34, -2}, {34, 4}, {-32, 4}, {-32, 14}, {-32, 14}}, thickness = 0.5));
connect(warm_start.outPort[1], lock_freq_and_phase_1.inPort) annotation(
Line(points = {{34, -2}, {34, -2}, {34, 20}, {34, 20}}, thickness = 0.5));
connect(turn_on.inPort, GPS_off.outPort[1]) annotation(
Line(points = {{-120, 58}, {-137.5, 58}}));
connect(cold_start.inPort[1], turn_on.outPort) annotation(
Line(points = {{-93, 58}, {-112.5, 58}}, thickness = 0.5));
connect(lock_freq_and_phase.inPort, cold_start.outPort[1]) annotation(
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
position_out = position_available.active;
algorithm
when {pre(lock_freq_and_phase.fire), pre(lock_freq_and_phase_1.fire), pre(lock_freq_and_phase_2.fire)} then
sv_tracked_freq_phase := pre(visible_satellites);
end when;
when {pre(on_signal) == false} then
sv_tracked_freq_phase := 0;
end when;
when {pre(visible_satellites) < pre(sv_tracked_freq_phase)} then
sv_tracked_freq_phase := pre(visible_satellites);
end when;
when {pre(visible_satellites) < pre(sv_ephemeris)} then
sv_ephemeris := pre(visible_satellites);
end when;
when {pre(get_ephemeris_data.fire), pre(update_ephemeris_data.fire)} then
sv_ephemeris := visible_satellites;
expiration_time := pre(time + ephemeris_duration);
end when;
when {time > pre(expiration_time)} then
sv_ephemeris := 0;
end when;
annotation(
uses(Modelica(version = "3.2.1")),
Icon(graphics = {Rectangle(fillColor = {0, 201, 223}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-40, 66}, extent = {{-14, 12}, {14, -12}}, textString = "ON"), Text(origin = {-13, -58}, lineColor = {30, 33, 177}, extent = {{-75, 66}, {109, -94}}, textString = "GPS device"), Text(origin = {-97, 45}, extent = {{59, -43}, {9, -5}}, textString = "Visible SV"), Text(origin = {26, -24}, extent = {{-22, 12}, {60, -32}}, textString = "Position available"), Text(origin = {34, 30}, extent = {{-32, 0}, {54, -12}}, textString = "pw consumption")}, coordinateSystem(initialScale = 0.1)),
experiment(StartTime = 0, StopTime = 1000, Tolerance = 1e-6, Interval = 0.002),
__OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl"));
end GPS_pw_simulator_old;
model test_GPS
GPS_pw_modeling.GPS_pw_simulator GPS_pw_simulator1 annotation(
Placement(visible = true, transformation(origin = {70, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanTable onCommand_TTFFandEphemerisExpirationExperiment(table = {5, 71, 90, 91, 110, 111, 130, 131, 150, 151, 1840, 1841, 1850, 1851, 1860, 1861, 1870, 1871, 1880, 1881, 1890, 1891, 1900, 1975, 1985, 1986, 1995, 1996}) annotation(
Placement(visible = true, transformation(origin = {-10, -30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.IntegerConstant stellites_TTFFandEphemerisExpirationExperiment(k = 5) annotation(
Placement(visible = true, transformation(origin = {-10, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.IntegerTable satellites_visibilityLossExperiment(table = [0, 5; 100, 3; 200, 4]) annotation(
Placement(visible = true, transformation(origin = {-10, 90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.BooleanTable onCommand_visibilityLossExperiment(table = {5, 71, 80, 81, 90, 91, 100, 101, 110, 111, 120, 261, 270, 271, 280, 281, 290, 291}) annotation(
Placement(visible = true, transformation(origin = {-10, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(satellites_visibilityLossExperiment.y, GPS_pw_simulator1.visible_satellites) annotation(
Line(points = {{2, 90}, {70, 90}, {70, -20}, {70, -20}}, color = {255, 127, 0}));
connect(GPS_pw_simulator1.on_signal, onCommand_visibilityLossExperiment.y) annotation(
Line(points = {{60, -30}, {30, -30}, {30, 50}, {2, 50}, {2, 50}}, color = {255, 0, 255}));
annotation(
experiment(StartTime = 0, StopTime = 2000, Tolerance = 1e-06, Interval = 0.0006),
__OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl"));
end test_GPS;
model GPS_pw_simulator
// not modeled hot start
/////////////////
// parameters //
/////////////////
//number of satellites required for sufficient accuracy
parameter Integer required_satellites = 4;
//power consumed when antenna is on (assumed constant) [mW]
parameter Real power_consumption = 387.2;
//time to get ephemeris data after freq&phase are locked (wrost case default)
parameter Real time_to_get_ephemeris = 59;
//frequency and phase acquisition time when exaustive search is required (upperbound, can be substituted with random variable)
parameter Real freq_and_phase_acquisition_time = 0.05;
//how long the ephemeris data will be reliable
parameter Real ephemeris_duration = 1800;
///////////////////////
//Inputs and outputs //
///////////////////////
Modelica.Blocks.Interfaces.IntegerInput visible_satellites annotation(
Placement(visible = true, transformation(origin = {-101, 101}, extent = {{-11, -11}, {11, 11}}, rotation = 0), iconTransformation(origin = {-2, 102}, extent = {{-26, -26}, {26, 26}}, rotation = -90)));
Modelica.Blocks.Interfaces.BooleanInput on_signal annotation(
Placement(visible = true, transformation(origin = {-158, 92}, extent = {{-12, -12}, {12, 12}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealOutput power annotation(
Placement(visible = true, transformation(origin = {54, 104}, extent = {{8, -8}, {-8, 8}}, rotation = 0), iconTransformation(origin = {95, 43}, extent = {{-25, -25}, {25, 25}}, rotation = 180)));
Modelica.Blocks.Logical.Not off_signal annotation(
Placement(visible = true, transformation(origin = {162, -24}, extent = {{8, -8}, {-8, 8}}, rotation = 0)));
/////////////
// states //
/////////////
//number of satellites of which frequency and phase are available
Integer sv_freq_phase(start = 0);
//number of satellites of which ephemeris data are available;
Integer sv_ephemeris(start = 0);
//time at which ephemeris data will expire
Real expiration_time(start = -1.0);
//states of the state machine
inner Modelica.StateGraph.StateGraphRoot stateGraphRoot annotation(
Placement(visible = false, transformation(origin = {-90, -90}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.InitialStep no_info(nIn = 3) annotation(
Placement(visible = true, transformation(origin = {-110, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.Step cold_start(nIn = 4, nOut = 2) annotation(
Placement(visible = true, transformation(origin = {-40, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.Step read_ephemeris(nIn = 2, nOut = 3) annotation(
Placement(visible = true, transformation(origin = {38, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.StepWithSignal position_available(nIn = 3, nOut = 4) annotation(
Placement(visible = true, transformation(origin = {112, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.Step warm_start_available(nIn = 2, nOut = 2) annotation(
Placement(visible = true, transformation(origin = {70, -90}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.StateGraph.Step warm_start(nIn = 3, nOut = 3) annotation(
Placement(visible = true, transformation(origin = {50, -38}, extent = {{10, -10}, {-10, 10}}, rotation = -90)));
/////////////////
// transitions //
/////////////////
Modelica.StateGraph.TransitionWithSignal turn_on1 annotation(
Placement(visible = true, transformation(origin = {-76, 48}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_on2 annotation(
Placement(visible = true, transformation(origin = {50, -66}, extent = {{10, -10}, {-10, 10}}, rotation = -90)));
Modelica.StateGraph.Transition fetch_signal1(enableTimer = true, waitTime = freq_and_phase_acquisition_time) annotation(
Placement(visible = true, transformation(origin = {-4, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition get_ephemeris1(enableTimer = true, waitTime = time_to_get_ephemeris) annotation(
Placement(visible = true, transformation(origin = {74, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_off1 annotation(
Placement(visible = true, transformation(origin = {130, -24}, extent = {{-10, 10}, {10, -10}}, rotation = -90)));
Modelica.StateGraph.TransitionWithSignal turn_off2 annotation(
Placement(visible = true, transformation(origin = {90, -38}, extent = {{10, -10}, {-10, 10}}, rotation = 90)));
Modelica.StateGraph.Transition fetch_signal2(enableTimer = true, waitTime = freq_and_phase_acquisition_time) annotation(
Placement(visible = true, transformation(origin = {74, 18}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_off3 annotation(
Placement(visible = true, transformation(origin = {-52, 84}, extent = {{10, 10}, {-10, -10}}, rotation = 0)));
Modelica.StateGraph.TransitionWithSignal turn_off4 annotation(
Placement(visible = true, transformation(origin = {-10, 88}, extent = {{10, 10}, {-10, -10}}, rotation = 0)));
Modelica.StateGraph.Transition get_ephemeris2(enableTimer = true, waitTime = time_to_get_ephemeris) annotation(
Placement(visible = true, transformation(origin = {126, 78}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition ephemeris_expire1(condition = time > expiration_time or sv_ephemeris < required_satellites) annotation(
Placement(visible = true, transformation(origin = {-18, -90}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition ephemeris_expire2(condition = time > expiration_time or sv_ephemeris < required_satellites) annotation(
Placement(visible = true, transformation(origin = {0, -10}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition ephemeris_expire3(condition = time > expiration_time or sv_ephemeris < required_satellites) annotation(
Placement(visible = true, transformation(origin = {72, 86}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition lose_visibility1(condition = sv_freq_phase < required_satellites) annotation(
Placement(visible = true, transformation(origin = {-4, 18}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Modelica.StateGraph.Transition lose_visibility2(condition = sv_freq_phase < required_satellites) annotation(
Placement(visible = true, transformation(origin = {110, -6}, extent = {{10, -10}, {-10, 10}}, rotation = 90)));
Modelica.Blocks.Interfaces.BooleanOutput position annotation(
Placement(visible = true, transformation(origin = {162, 30}, extent = {{10, -10}, {-10, 10}}, rotation = 0), iconTransformation(origin = {95, -27}, extent = {{25, -25}, {-25, 25}}, rotation = 0)));
equation
connect(lose_visibility2.outPort, warm_start.inPort[2]) annotation(
Line(points = {{110, -8}, {110, -8}, {110, -58}, {50, -58}, {50, -48}, {50, -48}}));
connect(lose_visibility2.inPort, position_available.outPort[4]) annotation(
Line(points = {{110, -2}, {110, -2}, {110, 10}, {130, 10}, {130, 48}, {122, 48}, {122, 48}}));
connect(turn_off2.outPort, warm_start_available.inPort[2]) annotation(
Line(points = {{90, -39.5}, {90, -88}, {81, -88}}));
connect(turn_off1.outPort, warm_start_available.inPort[1]) annotation(
Line(points = {{130, -25.5}, {130, -88}, {81, -88}}));
connect(turn_on2.inPort, warm_start_available.outPort[1]) annotation(
Line(points = {{50, -70}, {50, -88}, {59.5, -88}}));
connect(ephemeris_expire1.inPort, warm_start_available.outPort[2]) annotation(
Line(points = {{-14, -90}, {23, -90}, {23, -88}, {59.5, -88}}));
connect(turn_off1.inPort, position_available.outPort[1]) annotation(
Line(points = {{130, -18}, {130, 50}, {122.5, 50}}));
connect(fetch_signal2.outPort, position_available.inPort[2]) annotation(
Line(points = {{75.5, 20}, {93.5, 20}, {93.5, 50}, {101, 50}}));
connect(get_ephemeris1.outPort, position_available.inPort[1]) annotation(
Line(points = {{75.5, 48}, {88.5, 48}, {88.5, 50}, {101, 50}}));
connect(ephemeris_expire3.inPort, position_available.outPort[3]) annotation(
Line(points = {{76, 86}, {140, 86}, {140, 50}, {122.5, 50}}));
connect(get_ephemeris2.inPort, position_available.outPort[2]) annotation(
Line(points = {{130, 78}, {140, 78}, {140, 50}, {122.5, 50}}));
connect(get_ephemeris2.outPort, position_available.inPort[3]) annotation(
Line(points = {{124.5, 78}, {94.5, 78}, {94.5, 50}, {101, 50}}));
connect(get_ephemeris1.inPort, read_ephemeris.outPort[1]) annotation(
Line(points = {{70, 50}, {59.25, 50}, {59.25, 48}, {48.5, 48}}));
connect(lose_visibility1.inPort, read_ephemeris.outPort[3]) annotation(
Line(points = {{0, 18}, {56, 18}, {56, 50}, {48.5, 50}}));
connect(fetch_signal1.outPort, read_ephemeris.inPort[1]) annotation(
Line(points = {{-2.5, 48}, {12.5, 48}, {12.5, 50}, {27, 50}}));
connect(turn_off4.inPort, read_ephemeris.outPort[2]) annotation(
Line(points = {{-6, 88}, {54, 88}, {54, 50}, {48.5, 50}}));
connect(ephemeris_expire3.outPort, read_ephemeris.inPort[2]) annotation(
Line(points = {{70, 86}, {20, 86}, {20, 50}, {27, 50}}));
connect(lose_visibility1.outPort, cold_start.inPort[3]) annotation(
Line(points = {{-6, 18}, {-60, 18}, {-60, 50}, {-51, 50}}));
connect(fetch_signal1.inPort, cold_start.outPort[1]) annotation(
Line(points = {{-8, 48}, {-27.25, 48}, {-27.25, 50}, {-29.5, 50}}));
connect(turn_on1.outPort, cold_start.inPort[1]) annotation(
Line(points = {{-74.5, 48}, {-52.4375, 48}, {-52.4375, 50}, {-51, 50}}));
connect(turn_off3.inPort, cold_start.outPort[2]) annotation(
Line(points = {{-48, 84}, {-22, 84}, {-22, 50}, {-29.5, 50}}));
connect(ephemeris_expire2.outPort, cold_start.inPort[2]) annotation(
Line(points = {{-2, -10}, {-60, -10}, {-60, 50}, {-51, 50}}));
connect(ephemeris_expire2.inPort, warm_start.outPort[3]) annotation(
Line(points = {{4, -10}, {50, -10}, {50, -28}, {50, -28}}));
connect(fetch_signal2.inPort, warm_start.outPort[2]) annotation(
Line(points = {{70, 20}, {50, 20}, {50, -26}}));
connect(ephemeris_expire1.outPort, no_info.inPort[3]) annotation(
Line(points = {{-20, -90}, {-128, -90}, {-128, 48}, {-120, 48}, {-120, 48}}));
connect(on_signal, off_signal.u) annotation(
Line);
connect(turn_off1.condition, off_signal.y) annotation(
Line(points = {{142, -24}, {153, -24}}, color = {255, 0, 255}));
connect(turn_off2.condition, off_signal.y) annotation(
Line(points = {{102, -38}, {150, -38}, {150, -24}, {154, -24}, {154, -24}, {154, -24}}, color = {255, 0, 255}));
connect(turn_off3.condition, off_signal.y) annotation(
Line(points = {{-52, 96}, {-52, 114}, {150, 114}, {150, -24}, {154, -24}}, color = {255, 0, 255}));
connect(turn_off4.condition, off_signal.y) annotation(
Line(points = {{-10, 100}, {-10, 114}, {150, 114}, {150, -24}, {154, -24}}, color = {255, 0, 255}));
connect(turn_off2.inPort, warm_start.outPort[1]) annotation(
Line(points = {{90, -32}, {90, -32}, {90, -20}, {50, -20}, {50, -26}, {50, -26}}));
connect(turn_on2.outPort, warm_start.inPort[1]) annotation(
Line(points = {{50, -64.5}, {50, -47.5}}));
connect(on_signal, turn_on2.condition) annotation(
Line(points = {{-158, 92}, {-140, 92}, {-140, -66}, {38, -66}}, color = {255, 0, 255}));
connect(turn_off4.outPort, no_info.inPort[2]) annotation(
Line(points = {{-11.5, 90}, {-127.5, 90}, {-127.5, 50}, {-119.5, 50}, {-119.5, 50}}));
connect(turn_off3.outPort, no_info.inPort[1]) annotation(
Line(points = {{-53.5, 86}, {-127.5, 86}, {-127.5, 50}, {-119.5, 50}, {-119.5, 50}}));
connect(turn_on1.inPort, no_info.outPort[1]) annotation(
Line(points = {{-80, 50}, {-100, 50}, {-100, 50}, {-100, 50}}));
connect(on_signal, turn_on1.condition) annotation(
Line(points = {{-158, 92}, {-74, 92}, {-74, 60}}, color = {255, 0, 255}));
//power consumption OUTPUT
power = if on_signal then power_consumption else 0;
position = min(sv_ephemeris, sv_freq_phase) > required_satellites;
algorithm
//update tracked satellites when signal is fetched
when {pre(fetch_signal1.fire), pre(fetch_signal2.fire)} then
sv_freq_phase := pre(visible_satellites);
end when;
//update tracked satellites when sensor is turned off
when {pre(off_signal.y) == false} then
sv_freq_phase := 0;
end when;
//update tracked satellites in case of loss of visibility
when {pre(visible_satellites) < pre(sv_freq_phase)} then
sv_freq_phase := pre(visible_satellites);
end when;
//update ephemeris data available in case of loss of visibility
when {pre(visible_satellites) < pre(sv_ephemeris)} then
sv_ephemeris := pre(visible_satellites);
end when;
//updates when ephemeris data are fetched
when {pre(get_ephemeris1.fire), pre(get_ephemeris2.fire)} then
sv_ephemeris := visible_satellites;
expiration_time := pre(time + ephemeris_duration);
end when;
//update ephemeris data available when they expire
when {time > pre(expiration_time)} then
sv_ephemeris := 0;
end when;
annotation(
Icon(graphics = {Rectangle(fillColor = {115, 210, 22}, fillPattern = FillPattern.Solid, extent = {{-96, 96}, {96, -96}}), Text(origin = {-54, 2}, extent = {{-20, 8}, {20, -8}}, textString = "turn_on"), Text(origin = {-45, 73}, extent = {{-17, 9}, {91, -15}}, textString = "visible_satellites"), Text(origin = {44, 41}, extent = {{-72, 15}, {22, -9}}, textString = "power_consumption"), Text(origin = {20, -27}, extent = {{-50, 11}, {50, -11}}, textString = "position_avaialble"), Text(origin = {11, -80}, extent = {{-97, 32}, {79, -24}}, textString = "GPS device")}, coordinateSystem(initialScale = 0.1)),
experiment(StartTime = 0, StopTime = 400, Tolerance = 1e-6, Interval = 0.0008));
end GPS_pw_simulator;
annotation(
uses(Modelica(version = "3.2.1")));
end GPS_pw_modeling;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment