Skip to content
Snippets Groups Projects
Commit 6b461f09 authored by justi's avatar justi
Browse files

Frank Assignment 3

parent 407cfc29
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. * 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 * This work is provided under a BSD open-source license, see project license.html and license.txt
* *
*
*/ */
package MV3500Cohort2021JulySeptember.homework3.Frank; package MV3500Cohort2021JulySeptember.homework3.Frank;
...@@ -21,8 +21,6 @@ import edu.nps.moves.dis7.pdus.EulerAngles; ...@@ -21,8 +21,6 @@ import edu.nps.moves.dis7.pdus.EulerAngles;
import edu.nps.moves.dis7.pdus.FirePdu; import edu.nps.moves.dis7.pdus.FirePdu;
import edu.nps.moves.dis7.pdus.MunitionDescriptor; import edu.nps.moves.dis7.pdus.MunitionDescriptor;
import edu.nps.moves.dis7.pdus.Pdu; import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.pdus.ResupplyOfferPdu;
import edu.nps.moves.dis7.pdus.SupplyQuantity;
import edu.nps.moves.dis7.pdus.Vector3Double; import edu.nps.moves.dis7.pdus.Vector3Double;
import edu.nps.moves.dis7.utilities.CoordinateConversions; import edu.nps.moves.dis7.utilities.CoordinateConversions;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
...@@ -38,8 +36,98 @@ import java.util.logging.Logger; ...@@ -38,8 +36,98 @@ import java.util.logging.Logger;
* reporting them to the network. Default settings include PDU recording turned * reporting them to the network. Default settings include PDU recording turned
* on by default. * on by default.
*/ */
public class FrankSimulation{ public class FrankSimulation {
private EntityID createM1Abrams() {
EntityID M1AbramsID = new EntityID(); // 1.1.225.1.1.1 Platform,Ground,USA,ArmoredFightingVehicle M1 Abrams
M1AbramsID.setSiteID(1);
M1AbramsID.setApplicationID(13);
M1AbramsID.setEntityID(25);
return M1AbramsID;
}
private EntityType createM1AbramsType() {
EntityType M1AbramsType = new EntityType();
M1AbramsType.setEntityKind(EntityKind.PLATFORM);
M1AbramsType.setDomain(Domain.inst(PlatformDomain.LAND));
M1AbramsType.setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
M1AbramsType.setCategory(1);
M1AbramsType.setSubCategory(1);
M1AbramsType.setSpecific(1);
return M1AbramsType;
}
private Vector3Double createLocationVector() {
Vector3Double eloc2 = new Vector3Double();
double[] loc2 = CoordinateConversions.getXYZfromLatLonDegrees(36.599831, -121.878842, 0); //sloat delmonte intersection
eloc2.setX(loc2[0]);
eloc2.setY(loc2[1]);
eloc2.setZ(loc2[2]);
return eloc2;
}
private EulerAngles createOrientation() {
EulerAngles orient2 = new EulerAngles();
orient2.setPhi((float) 0.0);
orient2.setPsi((float) 0.0);
orient2.setTheta((float) 0.0);
return orient2;
}
private EntityID createT62ID() {
EntityID T62ID = new EntityID();//1.1.45.1.7.1 Platform,Ground,China, Tank, T-62
T62ID.setSiteID(1);
T62ID.setApplicationID(13);
T62ID.setEntityID(2);
return T62ID;
}
private EntityType createT62Type() {
EntityType T62Type = new EntityType();
T62Type.setEntityKind(EntityKind.PLATFORM);
T62Type.setDomain(Domain.inst(PlatformDomain.LAND));
T62Type.setCountry(Country.RUSSIA);
T62Type.setCategory(2);
T62Type.setSubCategory(41);
T62Type.setSpecific(3);
return T62Type;
}
private Vector3Double createEnemyLocation() {
Vector3Double eloc1 = new Vector3Double();
double[] loc1 = CoordinateConversions.getXYZfromLatLonDegrees(36.594116, -121.877463, 0); //NPS Main Gate
eloc1.setX(loc1[0]);
eloc1.setY(loc1[1]);
eloc1.setZ(loc1[2]);
return eloc1;
}
private EulerAngles createEnemyOrientation() {
EulerAngles orient1 = new EulerAngles();
orient1.setPhi((float) 3.1415);
orient1.setPsi((float) 0.0);
orient1.setTheta((float) 0.0);
return orient1;
}
private MunitionDescriptor createM829IT(){
EntityType M829Type = new EntityType(); //2.2.225.2.13.1
M829Type.setEntityKind(EntityKind.MUNITION);
M829Type.setDomain(Domain.inst(PlatformDomain.AIR));
M829Type.setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
M829Type.setCategory(2);
M829Type.setSubCategory(13);
M829Type.setSpecific(1);
MunitionDescriptor M829IT = new MunitionDescriptor();
M829IT.setMunitionType(M829Type);
M829IT.setQuantity(3);
M829IT.setFuse(MunitionDescriptorFuse.CONTACT_GRAZE);
M829IT.setRate(200);
return M829IT;
}
/** /**
* This runSimulation() method is for you, a programmer-modifiable method * This runSimulation() method is for you, a programmer-modifiable method
* for defining and running a new simulation of interest. Welcome! Other * for defining and running a new simulation of interest. Welcome! Other
...@@ -59,7 +147,7 @@ public class FrankSimulation{ ...@@ -59,7 +147,7 @@ public class FrankSimulation{
* seconds for real-time execution (not simulation time, which may * seconds for real-time execution (not simulation time, which may
* or may not be the same) * or may not be the same)
*/ */
final double SIMULATION_LOOP_DURATION_SECONDS = 1.0; final double SIMULATION_LOOP_DURATION_SECONDS = 2.0;
final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out out there! also avoid infinite loops. final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out out there! also avoid infinite loops.
int simulationLoopCount = 0; // variable, initialized at 0 int simulationLoopCount = 0; // variable, initialized at 0
boolean simulationComplete = false; // sentinel variable as termination condition,, are we done yet? boolean simulationComplete = false; // sentinel variable as termination condition,, are we done yet?
...@@ -75,60 +163,22 @@ public class FrankSimulation{ ...@@ -75,60 +163,22 @@ public class FrankSimulation{
EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu();
entityStatePdu_1.setEntityID(entityID_1); entityStatePdu_1.setEntityID(entityID_1);
// M1Abrams
EntityID M1AbramsID = new EntityID(); // 1.1.225.1.1.1 Platform,Ground,USA,ArmoredFightingVehicle M1 Abrams entityStatePdu_1.setEntityID(createM1Abrams()); // Calling createM1Abrams Method
M1AbramsID.setSiteID(1); entityStatePdu_1.setEntityType(createM1AbramsType()); // Calling createM1AbramsType Method
M1AbramsID.setApplicationID(13); // Location and Orientation
M1AbramsID.setEntityID(25); Vector3Double eloc2 = createLocationVector(); // Calling createLocationVector Method
entityStatePdu_1.setEntityID(M1AbramsID);
EntityType M1AbramsType = new EntityType();
M1AbramsType.setEntityKind(EntityKind.PLATFORM);
M1AbramsType.setDomain(Domain.inst(PlatformDomain.LAND));
M1AbramsType.setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
M1AbramsType.setCategory(1);
M1AbramsType.setSubCategory(1);
M1AbramsType.setSpecific(1);
entityStatePdu_1.setEntityType(M1AbramsType);
Vector3Double eloc2 = new Vector3Double();
double[] loc2 = CoordinateConversions.getXYZfromLatLonDegrees(36.599831, -121.878842, 0); //sloat delmonte intersection
eloc2.setX(loc2[0]);
eloc2.setY(loc2[1]);
eloc2.setZ(loc2[2]);
entityStatePdu_1.setEntityLocation(eloc2); entityStatePdu_1.setEntityLocation(eloc2);
EulerAngles orient2 = new EulerAngles(); entityStatePdu_1.setEntityOrientation(createOrientation()); // Calling Create Orientation Method
orient2.setPhi((float) 0.0);
orient2.setPsi((float) 0.0);
orient2.setTheta((float) 0.0);
entityStatePdu_1.setEntityOrientation(orient2);
EntityStatePdu entityStatePdu2 = pduFactory.makeEntityStatePdu(); EntityStatePdu entityStatePdu2 = pduFactory.makeEntityStatePdu();
// //T-62
EntityID T62ID = new EntityID();//1.1.45.1.7.1 Platform,Ground,China, Tank, T-62 entityStatePdu2.setEntityID(createT62ID()); // Calling Create T62 ID method
T62ID.setSiteID(1); entityStatePdu2.setEntityType(createT62Type()); // Calling Create T62 Type method
T62ID.setApplicationID(13); // enemy location and orientation
T62ID.setEntityID(2); Vector3Double eloc1 = createEnemyLocation(); // calling create enemylocation method
entityStatePdu2.setEntityID(T62ID); entityStatePdu2.setEntityLocation(eloc1); // Setting em
EntityType T62Type = new EntityType(); entityStatePdu2.setEntityOrientation(createEnemyOrientation()); //calling create Enemy orientation method
T62Type.setEntityKind(EntityKind.PLATFORM);
T62Type.setDomain(Domain.inst(PlatformDomain.LAND));
T62Type.setCountry(Country.RUSSIA);
T62Type.setCategory(2);
T62Type.setSubCategory(41);
T62Type.setSpecific(3);
entityStatePdu2.setEntityType(T62Type);
Vector3Double eloc1 = new Vector3Double();
double[] loc1 = CoordinateConversions.getXYZfromLatLonDegrees(36.594116, -121.877463, 0); //NPS Main Gate
eloc1.setX(loc1[0]);
eloc1.setY(loc1[1]);
eloc1.setZ(loc1[2]);
entityStatePdu2.setEntityLocation(eloc1);
EulerAngles orient1 = new EulerAngles();
orient1.setPhi((float) 3.1415);
orient1.setPsi((float) 0.0);
orient1.setTheta((float) 0.0);
entityStatePdu2.setEntityOrientation(orient1);
int T62HitsReceived = 0; int T62HitsReceived = 0;
...@@ -149,37 +199,24 @@ public class FrankSimulation{ ...@@ -149,37 +199,24 @@ public class FrankSimulation{
firePdu.setFiringEntityID(fireID); firePdu.setFiringEntityID(fireID);
firePdu.setTargetEntityID(targetID); firePdu.setTargetEntityID(targetID);
EntityType M829Type = new EntityType(); //2.2.225.2.13.1 firePdu.setDescriptor(createM829IT()); // calling create M829IT Method
M829Type.setEntityKind(EntityKind.MUNITION);
M829Type.setDomain(Domain.inst(PlatformDomain.AIR));
M829Type.setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
M829Type.setCategory(2);
M829Type.setSubCategory(13);
M829Type.setSpecific(1);
MunitionDescriptor M829IT = new MunitionDescriptor();
M829IT.setMunitionType(M829Type);
M829IT.setQuantity(3);
M829IT.setFuse(MunitionDescriptorFuse.CONTACT_GRAZE);
M829IT.setRate(200);
firePdu.setDescriptor(M829IT);
EntityID M829ID = new EntityID(); EntityID M829ID = new EntityID();
M829ID.setEntityID(1); M829ID.setEntityID(1);
firePdu.setMunitionExpendibleID(M829ID); firePdu.setMunitionExpendibleID(M829ID);
//
CommentReliablePdu T62DestroyedComment = pduFactory.makeCommentReliablePdu("T62 DESTROYED BY M1 Abrams AFTER 2 rounds M829I-T ON TARGET"); CommentReliablePdu T62DestroyedComment = pduFactory.makeCommentReliablePdu("T62 DESTROYED BY M1 Abrams AFTER 2 rounds M829I-T ON TARGET");
CommentReliablePdu T62SightedComment = pduFactory.makeCommentReliablePdu("M1 Abrams Acquires Target - T62 with in firing distance"); CommentReliablePdu T62SightedComment = pduFactory.makeCommentReliablePdu("M1 Abrams Acquires Target - T62 with in firing distance");
//if(eloc1.getX()) //if(eloc1.getX())
EntityID MTVRID = new EntityID(); EntityID MTVRID = new EntityID();
//
FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any) FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any)
while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet?
{ {
simulationLoopCount++; // good practice: increment loop counter as first action in that loop simulationLoopCount++; // good practice: increment loop counter as first action in that loop
// Where is my entity? // Where is my entity?
entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() - 20); // 1m per timestep entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() - 20); // 1m per timestep
entityStatePdu_1.getEntityLocation().setY(entityStatePdu_1.getEntityLocation().getY() - 75); entityStatePdu_1.getEntityLocation().setY(entityStatePdu_1.getEntityLocation().getY() - 75);
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at! // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at!
...@@ -188,7 +225,7 @@ public class FrankSimulation{ ...@@ -188,7 +225,7 @@ public class FrankSimulation{
Double dz = eloc2.getZ() - eloc1.getZ(); Double dz = eloc2.getZ() - eloc1.getZ();
Double range = Math.sqrt(dx * dx + dy * dy); Double range = Math.sqrt(dx * dx + dy * dy);
System.out.println("range" + range + " dx:" + dx + " dy:" + dy); System.out.println("range" + range + " dx:" + dx + " dy:" + dy);
if (range < 100) { // Range 100 if (range < 100) { // Range 100
if (!fireBool) { if (!fireBool) {
sendSinglePdu(T62SightedComment); sendSinglePdu(T62SightedComment);
...@@ -204,18 +241,18 @@ public class FrankSimulation{ ...@@ -204,18 +241,18 @@ public class FrankSimulation{
System.out.println("M1 Abrams destroys T62 after " + T62HitsReceived + "rounds hit T62 Russian Tank"); System.out.println("M1 Abrams destroys T62 after " + T62HitsReceived + "rounds hit T62 Russian Tank");
narrativeMessage4 = "Destroyed T62"; narrativeMessage4 = "Destroyed T62";
destBool = true; destBool = true;
simulationComplete = true;
} }
} }
} }
// if (Message.equals("BMP Destroyed after" )) { //if client recieved termanation message stop client // if (Message.equals("BMP Destroyed after" )) { //if client recieved termanation message stop client
// break; // break;
// your loop termination condition goes here // your loop termination condition goes here
if (simulationLoopCount > 4) // for example if (simulationLoopCount > 4) // for example
{ {
simulationComplete = true; simulationComplete = true;
} }
// ============================================================================================= // =============================================================================================
// * your own simulation code starts here! * // * your own simulation code starts here! *
...@@ -228,20 +265,17 @@ public class FrankSimulation{ ...@@ -228,20 +265,17 @@ public class FrankSimulation{
// decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at! // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at!
//firePdu_1a.setLocationInWorldCoordinates(entityStatePdu_1.getEntityLocation()); //firePdu_1a.setLocationInWorldCoordinates(entityStatePdu_1.getEntityLocation());
//byte[] fireArray = firePdu_1a.marshal(); //byte[] fireArray = firePdu_1a.marshal();
//System.out.println("FirePdu_1a #" + simulationLoopCount + " firePdu=[FireMissionIndex=" + firePdu_1a.getFireMissionIndex() + ", descriptor=" + firePdu_1a.getDescriptor() + "]"); //System.out.println("FirePdu_1a #" + simulationLoopCount + " firePdu=[FireMissionIndex=" + firePdu_1a.getFireMissionIndex() + ", descriptor=" + firePdu_1a.getDescriptor() + "]");
// etc. etc. your code goes here for your simulation of interest // etc. etc. your code goes here for your simulation of interest
// something happens between my simulation entities, la de da de da... // something happens between my simulation entities, la de da de da...
//System.out.println("... My simulation just did something, no really..."); //System.out.println("... My simulation just did something, no really...");
// make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending)
narrativeMessage1 = "MV3500 FrankSimulation"; narrativeMessage1 = "MV3500 FrankSimulation";
narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; narrativeMessage2 = "runSimulation() loop " + simulationLoopCount;
narrativeMessage3 = ""; // intentionally blank for testing narrativeMessage3 = ""; // intentionally blank for testing
// your loop termination condition goes here // your loop termination condition goes here
if (simulationLoopCount > 4) // for example if (simulationLoopCount > 10) // for example
{ {
simulationComplete = true; simulationComplete = true;
} }
......
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