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

walk a box perimeter NORTH EAST SOUTH WEST

parent 8265d054
No related branches found
No related tags found
No related merge requests found
......@@ -22,12 +22,6 @@ import java.util.logging.Logger;
*/
public class ExampleTrackInterpolation extends ExampleSimulationProgram {
/**
* Output prefix to identify this class (override in subclass), helps with
* logging
*/
private final static String TRACE_PREFIX = "[" + ExampleTrackInterpolation.class.getName() + "] ";
/**
* This runSimulationLoops() method is a programmer-modifiable method for
* defining and running a new simulation of interest. Welcome! Other parts
......@@ -48,27 +42,24 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
int simulationLoopCount = 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
// TODO reset Clock Time to today's date and timestamp to zero, providing consistent outputs for each simulation run
simulationTime = initialTime - currentTimeStep; // pre-initialization for first loop
// 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.
// create PDU objects and set their values.
EntityID entityID_1 = new EntityID();
entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID;
// create PDU objects and set their values.
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?
pduRecorder.setVerbose(false);
pduRecorder.hasVerboseOutput();
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.setMarking("track path");
espdu_1.getMarkingString(); // trace
espdu_1.setEntityLocation(new Vector3Double().setX(0).setY(0).setZ(0));
// espdu_1.setEntityLocation(0, 0, 0); // utility method
......@@ -86,25 +77,28 @@ 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;
// Pick direction, change each 10 seconds, traverse a box. No physics.
EntityStatePdu.Direction directionEntity_1;
if (simulationLoopCount <= 10)
directionEntity1 = EntityStatePdu.Direction.NORTH;
directionEntity_1 = EntityStatePdu.Direction.NORTH;
else if (simulationLoopCount <= 20)
directionEntity1 = EntityStatePdu.Direction.EAST;
directionEntity_1 = EntityStatePdu.Direction.EAST;
else if (simulationLoopCount <= 30)
directionEntity1 = EntityStatePdu.Direction.SOUTH;
directionEntity_1 = EntityStatePdu.Direction.SOUTH;
else // if (simulationLoopCount <= 40)
directionEntity1 = EntityStatePdu.Direction.WEST;
directionEntity_1 = EntityStatePdu.Direction.WEST;
float speed = 1.0f; // meters/second
espdu_1.setEntityLinearVelocity(speed, directionEntity1);
float speedEntity_1 = 1.0f; // meters/second
espdu_1.setEntityLinearVelocity(speedEntity_1, directionEntity_1);
// Where is my entity? Insert changes in position; this sample only changes X position.
espdu_1.advanceEntityLocation(currentTimeStep);
Vector3Double location = espdu_1.getEntityLocation();
System.out.println ("Entity location=(" + location.getX() + ", " + location.getY() + ", " + location.getZ() + ")");
System.out.println (String.format("%2d ", simulationLoopCount) + "Entity location=(" +
String.format("%4.1f", location.getX()) + ", " +
String.format("%4.1f", location.getY()) + ", " +
String.format("%4.1f", location.getZ()) + ")");
// make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending)
narrativeMessage1 = "MV3500 TrackSimulationProgram";
......@@ -112,7 +106,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
narrativeMessage3 = ""; // intentionally blank for testing
// your loop termination condition goes here
if (simulationLoopCount > 40) // for example
if (simulationLoopCount >= 40) // for example
{
simulationComplete = true;
}
......@@ -122,17 +116,19 @@ 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
if (false) // real-time operation
if (false) // real-time operation or simulation speedup
{
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");
if (pduRecorder.hasVerboseOutput())
System.out.println("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent");
sendSinglePdu(espdu_1);
sendCommentPdu(timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
System.out.println("... [PDUs successfully sent for this loop]");
sendCommentPdu(currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
if (pduRecorder.hasVerboseOutput())
System.out.println("... [PDUs successfully sent for this loop]");
// ===============================
// loop now finished, check whether to terminate if simulation complete, otherwise continue
......@@ -145,7 +141,8 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
narrativeMessage2 = "runSimulation() completed successfully"; // all done
sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
System.out.println("... [final CommentPdu successfully sent for simulation]");
if (pduRecorder.hasVerboseOutput())
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!
......@@ -166,23 +163,29 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram {
*/
public static void main(String[] args)
{
TRACE_PREFIX = "[" + ExampleTrackInterpolation.class.getName() + "] ";
System.out.println(TRACE_PREFIX + "main() started...");
// OK here we go...
thisProgram = new ExampleTrackInterpolation(); // creates instance of self within static main() method
thisProgram.handleArgs (args); // process command-line invocation arguments
thisProgram.setUpNetworkInterface();
thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder");
thisProgram.pduRecorder.setVerbose(false);
thisProgram.setVerboseComments(false);
thisProgram.disNetworkInterface.setVerbose(false);
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
System.exit(0); // ensure all threads and sockets released
}
}
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