Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
16f44331
Commit
16f44331
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
improved comments
parent
7445e9e8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+47
-38
47 additions, 38 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
with
47 additions
and
38 deletions
examples/src/OpenDis7Examples/ExampleSimulationProgram.java
+
47
−
38
View file @
16f44331
/**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
* @author brutzman@nps.edu
*/
package
OpenDis7Examples
;
...
...
@@ -24,60 +25,66 @@ import java.util.logging.Logger;
public
class
ExampleSimulationProgram
{
/**
* This runSimulation() method is for you! This block is programmer-modifiable method
* for defining and running a new simulation of interest.
* Support include DIS EntityStatePdu, FirePdu and CommentPdu all available for
* This runSimulation() method is for you, a
* programmer-modifiable method for defining and running a new simulation of interest.
* Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that
* you can focus on your model entities and activities.
* Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for
* modification and sending in a simulation loop.
* Continuous improvement efforts seek to make this program as easy and straightforward
* as possible for new simulationists to use and adapt.
* All of the other methods are setup, teardown and configuration that you don't have to worry about.
* as possible for DIS simulationists to use and adapt.
* All of the other methods are setup, teardown and configuration that you may find
* interesting, even helpful, but don't really have to worry about.
*/
@SuppressWarnings
(
"SleepWhileInLoop"
)
@SuppressWarnings
(
"SleepWhileInLoop"
)
// yes we do that
public
void
runSimulation
()
{
try
{
/** seconds for real-time execution (not simulation time, which may or may not be the same) */
final
double
LOOP_DURATION_SECONDS
=
1.0
;
final
int
MAX_LOOP_COUNT
=
10
;
// be deliberate out out there!
int
l
oopCount
=
0
;
// initialized at 0
boolean
simulationComplete
=
false
;
// sentinel variable as termination condition,, are we done yet?
final
double
SIMULATION_
LOOP_DURATION_SECONDS
=
1.0
;
final
int
SIMULATION_
MAX_LOOP_COUNT
=
10
;
// be deliberate out out there!
also avoid infinite loops.
int
simulationL
oopCount
=
0
;
//
variable,
initialized at 0
boolean
simulationComplete
=
false
;
// sentinel variable as termination condition,, are we done yet?
// TODO reset clock to zero each time for consistent outputs
//
y
our model setup: who's who in this zoo?
//
create PDU objects and set their values
//
Y
our model setup:
define participants.
who's who in this zoo?
//
Assuming you keep track of entity objects... here is some support for for Entity 1.
// create PDU objects and set their values.
EntityID
entityID_1
=
new
EntityID
();
entityID_1
.
setSiteID
(
1
).
setApplicationID
(
2
).
setEntityID
(
3
);
// made-up example ID;
// TODO use enumerations; is there a unique site triplet for MOVES Institute?
// TODO
someday,
use enumerations; is there a unique site triplet for MOVES Institute?
EntityStatePdu
entityStatePdu
=
pduFactory
.
makeEntityStatePdu
();
entityStatePdu
.
setEntityID
(
entityID_1
);
EntityStatePdu
entityStatePdu
_1
=
pduFactory
.
makeEntityStatePdu
();
entityStatePdu
_1
.
setEntityID
(
entityID_1
);
FirePdu
firePdu
=
pduFactory
.
makeFirePdu
();
FirePdu
firePdu_1a
=
pduFactory
.
makeFirePdu
();
// for entity 1 first weapon (if any)
FirePdu
firePdu_1b
=
pduFactory
.
makeFirePdu
();
// for entity 1 second weapon (if any)
// should we customize this munition? what is it for your simulation?
// TODO simulation management PDUs for startup
// TODO simulation management PDUs for startup
, planning to design special class support
// loop the simulation while allowed, programmer can set additional conditions to break out and finish
while
(
loopCount
<
MAX_LOOP_COUNT
)
// are we done yet?
while
(
simulationLoopCount
<
SIMULATION_
MAX_LOOP_COUNT
)
// are we done yet?
{
l
oopCount
++;
// good practice: increment loop counter as first action
simulationL
oopCount
++;
// good practice: increment loop counter as first action
in that loop
// =============================================================================================
// your own simulation code starts here!
// * your own simulation code starts here! *
// =============================================================================================
// are there any other variables to modify at the beginning of your loop?
// compute a track, update an ESPDU, whatever it is that your model is doing...
// Where is my entity? Insert changes in position.
entityStatePdu
.
getEntityLocation
().
setX
(
entityStatePdu
.
getEntityLocation
().
getX
()
+
1.0
);
// 1m per timestep
// Where is my entity? Insert changes in
position; this sample only changes X
position.
entityStatePdu
_1
.
getEntityLocation
().
setX
(
entityStatePdu
_1
.
getEntityLocation
().
getX
()
+
1.0
);
// 1m per timestep
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at!
// etc. etc. your code goes here
// etc. etc. your code goes here
for your simulation of interest
// something happens between my simulation entities, la de da de da...
System
.
out
.
println
(
"... My simulation just did something, no really..."
);
...
...
@@ -85,37 +92,38 @@ public class ExampleSimulationProgram
// make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending)
narrativeMessage1
=
"MV3500 ExampleSimulationProgram"
;
narrativeMessage2
=
"runSimulation() loop "
+
l
oopCount
;
narrativeMessage2
=
"runSimulation() loop "
+
simulationL
oopCount
;
narrativeMessage3
=
""
;
// intentionally blank for testing
// your loop termination condition goes here
if
(
l
oopCount
>
4
)
// for example
if
(
simulationL
oopCount
>
4
)
// for example
{
simulationComplete
=
true
;
}
// your own simulation code is finished here!
// =============================================================================================
// * your own simulation code is finished here! *
// =============================================================================================
//
keep track of
timestep: wait duration for elapsed time in this loop
//
staying synchronized with
timestep: wait duration for elapsed time in this loop
// Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes
Thread
.
sleep
((
long
)(
LOOP_DURATION_SECONDS
*
1000
));
// seconds * (1000 msec/sec) = milliseconds
System
.
out
.
println
(
"... [Pausing for "
+
LOOP_DURATION_SECONDS
+
" seconds]"
);
Thread
.
sleep
((
long
)(
SIMULATION_
LOOP_DURATION_SECONDS
*
1000
));
// seconds * (1000 msec/sec) = milliseconds
System
.
out
.
println
(
"... [Pausing for "
+
SIMULATION_
LOOP_DURATION_SECONDS
+
" seconds]"
);
// send the status PDUs for this loop and continue
System
.
out
.
println
(
"sending PDUs for simulation step "
+
l
oopCount
+
", monitor loopback to confirm sent"
);
sendAllPdusForLoopTimestep
(
entityStatePdu
,
firePdu
,
timeStepComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
//
OK now
send the status PDUs for this loop
,
and
then
continue
System
.
out
.
println
(
"sending PDUs for simulation step "
+
simulationL
oopCount
+
", monitor loopback to confirm sent"
);
sendAllPdusForLoopTimestep
(
entityStatePdu
_1
,
firePdu
_1a
,
timeStepComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
System
.
out
.
println
(
"... [PDUs successfully sent for this loop]"
);
// ===============================
// loop now finished,
thus
terminate if simulation complete, otherwise
send latest PDUs and
continue
if
(
simulationComplete
||
(
l
oopCount
>
10000
))
// for example; including fail-safe condition is good
// loop now finished,
check whether to
terminate if simulation complete, otherwise continue
if
(
simulationComplete
||
(
simulationL
oopCount
>
10000
))
// for example; including fail-safe condition is good
{
System
.
out
.
println
(
"... [Termination condition met, simulationComplete="
+
simulationComplete
+
"]"
);
// ", final loopCount=" + loopCount +
break
;
}
}
// end of
while
loop
// all done
narrativeMessage2
=
"runSimulation() completed successfully"
;
}
// end of
simulation
loop
narrativeMessage2
=
"runSimulation() completed successfully"
;
// all done
sendCommentPdu
(
narrativeComment
,
narrativeMessage1
,
narrativeMessage2
,
narrativeMessage3
);
System
.
out
.
println
(
"... [final CommentPdu successfully sent for simulation]"
);
// TODO simulation management PDUs
...
...
@@ -133,6 +141,7 @@ public class ExampleSimulationProgram
String
narrativeMessage3
=
new
String
();
/* VariableRecordType enumerations have potential use with CommentPdu logs */
/* TODO contrast to EntityType */
VariableRecordType
descriptionComment
=
VariableRecordType
.
DESCRIPTION
;
VariableRecordType
narrativeComment
=
VariableRecordType
.
COMPLETE_EVENT_REPORT
;
VariableRecordType
statusComment
=
VariableRecordType
.
APPLICATION_STATUS
;
...
...
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