From 47b1ca64062f808bc0a5564a73ddbbacaed0f65c Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Fri, 10 Jun 2022 23:01:40 -0700 Subject: [PATCH] Added further model detail. TODO fix sendSinglePduDelayed thread handling since it is blocking... --- .../TwoCraneBerthsOpenDis7.java | 71 ++++++++++++++----- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java b/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java index 8299b965fb..c5e105ff25 100644 --- a/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java +++ b/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java @@ -2,6 +2,8 @@ package SimkitOpenDis7Examples; import edu.nps.moves.dis7.enumerations.DisPduType; import edu.nps.moves.dis7.pdus.EntityStatePdu; +import edu.nps.moves.dis7.pdus.EulerAngles; +import edu.nps.moves.dis7.pdus.Vector3Double; import edu.nps.moves.dis7.utilities.DisChannel; import edu.nps.moves.dis7.utilities.PduFactory; import java.util.SortedSet; @@ -22,7 +24,8 @@ import simkit.SimEntityBase; */ public class TwoCraneBerthsOpenDis7 extends SimEntityBase { - private final DisChannel disChannel = new DisChannel(); + // Utility constructor method: initial descriptor and verboseness of disNetworkInterface, pduRecorder + private final DisChannel disChannel = new DisChannel("TwoCraneBerthsOpenDis7", false, true); /** * Queue of Ships waiting to go into the berth @@ -185,52 +188,82 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase waitDelay("EndUnloadingOneCrane", ship.getRemainingUnloadingTime(), ship); } - PduFactory pduFactory = new PduFactory(); + // can be member variables (for efficiency, move above) or else embdedded within method (move below) + PduFactory pduFactory = new PduFactory(); + EntityStatePdu espduCrane = (EntityStatePdu) pduFactory.createPdu(DisPduType.ENTITY_STATE); + + /** + * Perform crane unloading operations and send PDUs to report progress + * @param numberContainers how many containers to offload + * @param positionOfCrane Y coordinate down pier across from ship's berth, aligned with cargo + */ public void performCraneUnloadOperations( // which crane // which berth - int numberOfContainers, + int numberContainers, double positionOfCrane - // lenthOfCrane + // lengthOfCrane ) { + // Pier coordinate system follows, Right-Hand Rule (RHR) throughout: + // +X axis to right with X=0 on centerline of pier (train tracks + // +Y axis down pier with Y=0 at head of pier, + // +Z axis vertical with Z=0 at level of pier + // phi is rotation about +X axis, radians + // theta is rotation about +Y axis, radians + // psi is rotation about +X axis, radians + double craneLinearSpeed = 1.0; // m/sec double craneRotationRate = 10.0; // degrees/second double containerHookupTime = 60.0; // seconds average double containerDetachTime = 30.0; // seconds average + + Vector3Double positionPierHead = new Vector3Double(); +// Vector3Double positionPierHead = new Vector3Double(0.0, 0.0, 0.0); // TODO needs utility constructor - EntityStatePdu espduCrane = (EntityStatePdu) pduFactory.createPdu(DisPduType.ENTITY_STATE); - // 1. Crane at head of pier, operatior present, boom elevated vertically in stow postion - // espduCrane1.setPosition 0 0 0 + // not modeling crane elevation angle, only orientation of crane cab and gantry + EulerAngles orientationToShip = (new EulerAngles()).setPsi((float) (90.0 * Math.PI/180.0)); // TODO utility methods needed + EulerAngles orientationToPier = (new EulerAngles()).setPsi((float) ( 0.0 * Math.PI/180.0)); // TODO utility methods needed + +// espduCrane.reset(); // TODO intialization utility method +// espduCrane.setEntityAppearance(TODO); // highlight active crane? + + // 1. Crane at head of pier, operator present, boom elevated vertically in stow postion +// espduCrane.setEntityLocation(0.0, 0.0, 0.0); // ambiguous, error prone + espduCrane.setEntityLocation(positionPierHead); // preferred // 2, Ship arrives, tug departs - // shop PDU here or assum it happened earlier + // ship PDU could be sent here, or probably more logical to ensure it happened earlier // 3. Crane moves to position of ship - espduCrane.setEntityLocation(positionOfCrane, 0.0, 0.0); + espduCrane.setEntityLocation(positionOfCrane, 0.0, 0.0); // head of pier, ambiguous // TODO compute travel time // update: travel to positionOfCrane by craneLinearSpeed - // 4. repeat until done: Crane rotates, lift container, rotates, lower container - for (int containerIndex = 1; containerIndex <= numberOfContainers; containerIndex++) + // 4. repeat until done: Crane rotates, lift container, rotates, lower container + for (int containerIndex = 1; containerIndex <= numberContainers; containerIndex++) { // perform one operation - espduCrane.setEntityOrientation(0, 0, 0); + espduCrane.setEntityOrientation(orientationToShip); disChannel.sendSinglePdu(espduCrane); - espduCrane.setEntityOrientation(0, 0, 0); - double rotationDelay = 90.0 / craneRotationRate; + espduCrane.setEntityOrientation(orientationToPier); + double rotationDelay = 90.0 / craneRotationRate; // units analysis: degrees / (degrees/second) = seconds disChannel.sendCommentPdu(disChannel.COMMENTPDU_NARRATIVE, "Hooking up Container " + containerIndex + " to crane"); - disChannel.sendSinglePduDelayed(containerHookupTime, espduCrane); + + // TODO fix sendSinglePduDelayed thread handling since it is blocking... + // disChannel.sendSinglePduDelayed(containerHookupTime, espduCrane); disChannel.sendCommentPdu(disChannel.COMMENTPDU_NARRATIVE, "Container hooked up"); - disChannel.sendSinglePduDelayed(containerHookupTime, espduCrane); - espduCrane.setEntityOrientation(90, 0, 0); - disChannel.sendSinglePduDelayed(rotationDelay, espduCrane); +// espduCrane.setEntityOrientation(0, 0, 90); // ambiguous, degrees or radians? TODO javadoc + espduCrane.setEntityOrientation(orientationToPier); + // TODO fix sendSinglePduDelayed thread handling since it is blocking... + // disChannel.sendSinglePduDelayed(containerHookupTime + rotationDelay, espduCrane); // unhook // rotate back + // send PDUs accordingly - // if this container is special, meaning on watchlist, report it + // Future work: if this container is special, meaning on watchlist, report it } // 4. Crane stows boom in vertical position -- GitLab