From 6b461f09c58f99588ce2946066faf5d4e712100e Mon Sep 17 00:00:00 2001 From: justi <justi@LAPTOP-258UDA82> Date: Sat, 28 Aug 2021 13:29:48 -0700 Subject: [PATCH] Frank Assignment 3 --- .../homework3/Frank/FrankSimulation.java | 198 ++++++++++-------- 1 file changed, 116 insertions(+), 82 deletions(-) diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankSimulation.java b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankSimulation.java index afc4e6475c..314343f6f6 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankSimulation.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankSimulation.java @@ -2,7 +2,7 @@ * 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 * - + * */ package MV3500Cohort2021JulySeptember.homework3.Frank; @@ -21,8 +21,6 @@ import edu.nps.moves.dis7.pdus.EulerAngles; import edu.nps.moves.dis7.pdus.FirePdu; import edu.nps.moves.dis7.pdus.MunitionDescriptor; 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.utilities.CoordinateConversions; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; @@ -38,8 +36,98 @@ import java.util.logging.Logger; * reporting them to the network. Default settings include PDU recording turned * 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 * for defining and running a new simulation of interest. Welcome! Other @@ -59,7 +147,7 @@ public class FrankSimulation{ * seconds for real-time execution (not simulation time, which may * 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. int simulationLoopCount = 0; // variable, initialized at 0 boolean simulationComplete = false; // sentinel variable as termination condition,, are we done yet? @@ -75,60 +163,22 @@ public class FrankSimulation{ EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); entityStatePdu_1.setEntityID(entityID_1); - - 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); - 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]); + // M1Abrams + entityStatePdu_1.setEntityID(createM1Abrams()); // Calling createM1Abrams Method + entityStatePdu_1.setEntityType(createM1AbramsType()); // Calling createM1AbramsType Method + // Location and Orientation + Vector3Double eloc2 = createLocationVector(); // Calling createLocationVector Method entityStatePdu_1.setEntityLocation(eloc2); - EulerAngles orient2 = new EulerAngles(); - orient2.setPhi((float) 0.0); - orient2.setPsi((float) 0.0); - orient2.setTheta((float) 0.0); - entityStatePdu_1.setEntityOrientation(orient2); + entityStatePdu_1.setEntityOrientation(createOrientation()); // Calling Create Orientation Method EntityStatePdu entityStatePdu2 = pduFactory.makeEntityStatePdu(); - - 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); - entityStatePdu2.setEntityID(T62ID); - 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); - 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); +// //T-62 + entityStatePdu2.setEntityID(createT62ID()); // Calling Create T62 ID method + entityStatePdu2.setEntityType(createT62Type()); // Calling Create T62 Type method + // enemy location and orientation + Vector3Double eloc1 = createEnemyLocation(); // calling create enemylocation method + entityStatePdu2.setEntityLocation(eloc1); // Setting em + entityStatePdu2.setEntityOrientation(createEnemyOrientation()); //calling create Enemy orientation method int T62HitsReceived = 0; @@ -149,37 +199,24 @@ public class FrankSimulation{ firePdu.setFiringEntityID(fireID); firePdu.setTargetEntityID(targetID); - 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); - - firePdu.setDescriptor(M829IT); + firePdu.setDescriptor(createM829IT()); // calling create M829IT Method + EntityID M829ID = new EntityID(); M829ID.setEntityID(1); firePdu.setMunitionExpendibleID(M829ID); - // + 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"); //if(eloc1.getX()) EntityID MTVRID = new EntityID(); -// FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any) - + while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? { 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().setY(entityStatePdu_1.getEntityLocation().getY() - 75); // 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{ Double dz = eloc2.getZ() - eloc1.getZ(); Double range = Math.sqrt(dx * dx + dy * dy); System.out.println("range" + range + " dx:" + dx + " dy:" + dy); - + if (range < 100) { // Range 100 if (!fireBool) { sendSinglePdu(T62SightedComment); @@ -204,18 +241,18 @@ public class FrankSimulation{ System.out.println("M1 Abrams destroys T62 after " + T62HitsReceived + "rounds hit T62 Russian Tank"); narrativeMessage4 = "Destroyed T62"; destBool = true; + simulationComplete = true; } } } // if (Message.equals("BMP Destroyed after" )) { //if client recieved termanation message stop client - // break; - + // break; // your loop termination condition goes here if (simulationLoopCount > 4) // for example { - simulationComplete = true; + simulationComplete = true; } // ============================================================================================= // * your own simulation code starts here! * @@ -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! //firePdu_1a.setLocationInWorldCoordinates(entityStatePdu_1.getEntityLocation()); //byte[] fireArray = firePdu_1a.marshal(); - //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 - // something happens between my simulation entities, la de da de da... //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) narrativeMessage1 = "MV3500 FrankSimulation"; narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; narrativeMessage3 = ""; // intentionally blank for testing // your loop termination condition goes here - if (simulationLoopCount > 4) // for example + if (simulationLoopCount > 10) // for example { simulationComplete = true; } -- GitLab