Skip to content
Snippets Groups Projects
Commit c3b96ecc authored by Brutzman, Don's avatar Brutzman, Don
Browse files

simulation testing, demonstrate track advancement

parent bacb9f21
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,8 @@ public class ExampleSimulationProgram
boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet?
// TODO reset clock to zero each time for consistent outputs
pduRecorder.setVerbose(true);
// Your 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.
......@@ -374,7 +376,7 @@ public class ExampleSimulationProgram
* Initial execution via main() method: handle args array of initialization arguments here
* @param args command-line parameters: network address and port
*/
private static void handleArgs (String[] args)
protected void handleArgs (String[] args)
{
// initial execution: handle args array of initialization arguments here
if (args.length == 2)
......@@ -404,18 +406,20 @@ public class ExampleSimulationProgram
{
System.out.println(TRACE_PREFIX + "main() started...");
thisProgram = new ExampleSimulationProgram(); // creates instance of self within static main() method
// OK here we go...
handleArgs (args);
thisProgram = new ExampleSimulationProgram(); // creates instance of self within static main() method
// OK here we go...
thisProgram.handleArgs (args); // process command-line invocation arguments
thisProgram.setUpNetworkInterface();
thisProgram.runSimulationLoops (); // ... your simulation execution code goes in there ...
thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ...
thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering
System.out.println(TRACE_PREFIX + "complete."); // report successful completion
System.exit(0); // ensure all threading lets go
}
}
......@@ -8,36 +8,40 @@ compile-single:
run-single:
[OpenDis7Examples.ExampleSimulationProgram] main() started...
[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete.
DisThreadedNetworkInterface createThreads() receiveThread.isAlive()=true
DisThreadedNetworkInterface createThreads() sendingThread.isAlive()=true
Network confirmation: address=239.1.2.3 port=3000
Beginning pdu save to directory ./pduLog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog29.dislog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog50.dislog
[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete.
DisThreadedNetworkInterface createThreads() receiveThread.isAlive()=true
DisThreadedNetworkInterface createThreads() sendingThread.isAlive()=true
[PduRecorder ExampleSimulationProgram pduRecorder] listening to IP address 239.1.2.3 on port 3000
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 1, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 1] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 1] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 1] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 1]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 4] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 4] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 2, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 5] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 5] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 5] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 5] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 5] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 5] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 6] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 6] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 6] DisPduType 02 FIRE, size 96 bytes)
......@@ -45,16 +49,16 @@ sending PDUs for simulation step 2, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 7] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 7] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 2]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 3, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 9] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 9] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 9] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 10] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 10] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 10] DisPduType 02 FIRE, size 96 bytes)
......@@ -62,33 +66,33 @@ sending PDUs for simulation step 3, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 11] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 11] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 3]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 12] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 12] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 12] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 4, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 13] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 13] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 13] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 13] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 13] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 13] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 4]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 16] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 16] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 16] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 5, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 17] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 17] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 17] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 18] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 18] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 18] DisPduType 02 FIRE, size 96 bytes)
......@@ -96,9 +100,9 @@ sending PDUs for simulation step 5, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 19] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 19] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 5]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 20] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 20] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 20] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... [Termination condition met, simulationComplete=true]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 21] DisPduType 22 COMMENT, size 120 bytes)
......@@ -106,7 +110,13 @@ sending PDUs for simulation step 5, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 21] DisPduType 22 COMMENT, size 120 bytes)
*** [Narrative comment sent: COMPLETE_EVENT_REPORT] [MV3500 ExampleSimulationProgram, runSimulation() completed successfully]
... [final CommentPdu successfully sent for simulation]
*** setKillSentinelAndInterrupts() killed=true sendingThread.isInterrupted()=false receiveThread.isInterrupted()=true
*** DisThreadedNetworkInterface close(): pdus2send.size()=0 baos.size()=0 dos.size()=0
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] datagramSocket.leaveGroup address=239.1.2.3 port=3000 isClosed()=true close() complete.
*** killThread() status: sendingThread.isAlive()=false sendingThread.isInterrupted()=true
*** killThread() status: receiveThread.isAlive()=false receiveThread.isInterrupted()=true
*** Thread close status: sendingThread.isAlive()=false receiveThread.isAlive()=false
Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog29.dislog
Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog50.dislog
[OpenDis7Examples.ExampleSimulationProgram] complete.
BUILD SUCCESSFUL (total time: 9 seconds)
BUILD SUCCESSFUL (total time: 10 seconds)
......@@ -7,11 +7,10 @@
package OpenDis7Examples;
import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon;
import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton;
import edu.nps.moves.dis7.enumerations.ForceID;
import edu.nps.moves.dis7.pdus.EntityID;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.FirePdu;
import edu.nps.moves.dis7.pdus.Vector3Double;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -45,7 +44,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
@Override // indicates that this method supercedes corresponding superclass method
public void runSimulationLoops() {
try {
final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out there! also avoid infinite loops.
final int SIMULATION_MAX_LOOP_COUNT = 50; // be deliberate out there! also avoid infinite loops.
int simulationLoopCount = 0; // variable, initialized at 0
boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet?
......@@ -61,20 +60,18 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
EntityID entityID_2 = new EntityID();
entityID_1.setSiteID(1).setApplicationID(2).setEntityID(4); // made-up example ID;
// TODO someday, use enumerations; is there a unique site triplet for MOVES Institute?
EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu();
entityStatePdu_1.setEntityID(entityID_1);
entityStatePdu_1.setForceId(ForceID.FRIENDLY);
entityStatePdu_1.setEntityType(new _001Poseidon()); // note import statement above
EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu();
entityStatePdu_2.setEntityID(entityID_2);
entityStatePdu_2.setForceId(ForceID.OPPOSING);
entityStatePdu_2.setEntityType(new _002Triton()); // note import statement above
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?
pduRecorder.setVerbose(false);
EntityStatePdu espdu_1 = pduFactory.makeEntityStatePdu();
espdu_1.setEntityID(entityID_1);
espdu_1.setForceId(ForceID.FRIENDLY);
espdu_1.setEntityType(new _001Poseidon()); // note import statement above
espdu_1.clearMarking();
espdu_1.setMarking("blah");
espdu_1.getMarkingString(); // trace
espdu_1.setEntityLocation(new Vector3Double().setX(0).setY(0).setZ(0));
// espdu_1.setEntityLocation(0, 0, 0); // utility method
// 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
......@@ -88,14 +85,26 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
// =============================================================================================
// 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...
// Pick direction
EntityStatePdu.Direction directionEntity1;
if (simulationLoopCount <= 10)
directionEntity1 = EntityStatePdu.Direction.NORTH;
else if (simulationLoopCount <= 20)
directionEntity1 = EntityStatePdu.Direction.EAST;
else if (simulationLoopCount <= 30)
directionEntity1 = EntityStatePdu.Direction.SOUTH;
else // if (simulationLoopCount <= 40)
directionEntity1 = EntityStatePdu.Direction.WEST;
float speed = 1.0f; // meters/second
espdu_1.setEntityLinearVelocity(speed, directionEntity1);
// 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
// entityStatePdu_1.setTimestamp(simulationTime);
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoot at!
// 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...");
espdu_1.advanceEntityLocation(currentTimeStep);
Vector3Double location = espdu_1.getEntityLocation();
System.out.println ("Entity location=(" + location.getX() + ", " + location.getY() + ", " + location.getZ() + ")");
// make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending)
narrativeMessage1 = "MV3500 TrackSimulationProgram";
......@@ -103,7 +112,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
narrativeMessage3 = ""; // intentionally blank for testing
// your loop termination condition goes here
if (simulationLoopCount > 4) // for example
if (simulationLoopCount > 40) // for example
{
simulationComplete = true;
}
......@@ -113,13 +122,16 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
// 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) (currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds
System.out.println("... [Pausing for " + currentTimeStep + " seconds]");
if (false) // real-time operation
{
Thread.sleep((long) (currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds
System.out.println("... [Pausing for " + currentTimeStep + " seconds]");
}
// OK now send the status PDUs for this loop, and then continue
System.out.println("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent");
sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
sendSinglePdu(entityStatePdu_2); // me too i.e. 2!
sendSinglePdu(espdu_1);
sendCommentPdu(timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
System.out.println("... [PDUs successfully sent for this loop]");
// ===============================
......@@ -135,7 +147,8 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
System.out.println("... [final CommentPdu successfully sent for simulation]");
// TODO simulation management PDUs
} catch (InterruptedException iex) // handle any exception that your code might choose to provoke!
}
catch (InterruptedException iex) // handle any exception that your code might choose to provoke!
{
Logger.getLogger(ExampleTrackInterpolation.class.getName()).log(Level.SEVERE, null, iex);
}
......@@ -151,25 +164,15 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
* @param args command-line arguments are an array of optional String
* parameters that are passed from execution environment during invocation
*/
public static void main(String[] args) {
public static void main(String[] args)
{
System.out.println(TRACE_PREFIX + "main() started...");
// OK here we go...
ExampleTrackInterpolation thisProgram = new ExampleTrackInterpolation(); // creates instance within static main() method
// initial execution: handle args array of initialization arguments here
if (args.length == 2) {
if ((args[0] != null) && !args[0].isEmpty()) {
thisProgram.setNetworkAddress(args[0]);
}
thisProgram = new ExampleTrackInterpolation(); // creates instance of self within static main() method
if ((args[1] != null) && !args[1].isEmpty()) {
thisProgram.setNetworkPort(Integer.parseInt(args[1]));
}
} else if (args.length != 0) {
System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]");
System.exit(-1);
}
// OK here we go...
thisProgram.handleArgs (args); // process command-line invocation arguments
thisProgram.setUpNetworkInterface();
......@@ -178,6 +181,8 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering
System.out.println(TRACE_PREFIX + "complete."); // report successful completion
System.exit(0); // ensure all threading lets go
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment