From a681498557c71c92022615f4ccef12d3408ee508 Mon Sep 17 00:00:00 2001 From: Pesterenan Date: Sun, 16 Feb 2025 15:06:36 -0300 Subject: [PATCH] [MP-5]: Translate portuguese variable names to english --- src/main/java/com/pesterenan/MechPeste.java | 18 +-- .../controllers/DockingController.java | 32 ++-- .../controllers/LandingController.java | 68 ++++---- .../controllers/LiftoffController.java | 67 ++++---- .../controllers/ManeuverController.java | 152 +++++++++--------- .../controllers/RoverController.java | 134 +++++++-------- .../com/pesterenan/model/ActiveVessel.java | 100 ++++++------ .../java/com/pesterenan/utils/Module.java | 52 ++++++ .../java/com/pesterenan/utils/Modulos.java | 52 ------ .../com/pesterenan/utils/PathFinding.java | 6 +- .../com/pesterenan/views/DockingJPanel.java | 8 +- .../views/FunctionsAndTelemetryJPanel.java | 12 +- .../com/pesterenan/views/LandingJPanel.java | 14 +- .../com/pesterenan/views/LiftoffJPanel.java | 22 +-- .../java/com/pesterenan/views/MainGui.java | 16 +- .../com/pesterenan/views/RoverJPanel.java | 14 +- .../pesterenan/views/RunManeuverJPanel.java | 20 +-- 17 files changed, 394 insertions(+), 393 deletions(-) create mode 100644 src/main/java/com/pesterenan/utils/Module.java delete mode 100644 src/main/java/com/pesterenan/utils/Modulos.java diff --git a/src/main/java/com/pesterenan/MechPeste.java b/src/main/java/com/pesterenan/MechPeste.java index 0367073..53f199d 100644 --- a/src/main/java/com/pesterenan/MechPeste.java +++ b/src/main/java/com/pesterenan/MechPeste.java @@ -61,8 +61,8 @@ public static ListModel getActiveVessels(String search) { vessels = vessels.stream().filter(v -> filterVessels(v, search)).collect(Collectors.toList()); vessels.forEach(v -> { try { - String naveStr = v.hashCode() + " - \t" + v.getName(); - list.addElement(naveStr); + String vesselName = v.hashCode() + " - \t" + v.getName(); + list.addElement(vesselName); } catch (RPCException ignored) { } }); @@ -91,13 +91,13 @@ public static ListModel getCurrentManeuvers() { public static String getVesselInfo(int selectedIndex) { try { - Vessel naveAtual = spaceCenter.getVessels().stream().filter(v -> v.hashCode() == selectedIndex).findFirst() + Vessel activeVessel = spaceCenter.getVessels().stream().filter(v -> v.hashCode() == selectedIndex).findFirst() .get(); - String name = naveAtual.getName().length() > 40 - ? naveAtual.getName().substring(0, 40) + "..." - : naveAtual.getName(); + String name = activeVessel.getName().length() > 40 + ? activeVessel.getName().substring(0, 40) + "..." + : activeVessel.getName(); String vesselInfo = String.format("Nome: %s\t\t\t | Corpo: %s", name, - naveAtual.getOrbit().getBody().getName()); + activeVessel.getOrbit().getBody().getName()); return vesselInfo; } catch (RPCException | NullPointerException ignored) { } @@ -106,9 +106,9 @@ public static String getVesselInfo(int selectedIndex) { public static void changeToVessel(int selectedIndex) { try { - Vessel naveAtual = spaceCenter.getVessels().stream().filter(v -> v.hashCode() == selectedIndex).findFirst() + Vessel activeVessel = spaceCenter.getVessels().stream().filter(v -> v.hashCode() == selectedIndex).findFirst() .get(); - spaceCenter.setActiveVessel(naveAtual); + spaceCenter.setActiveVessel(activeVessel); } catch (RPCException | NullPointerException e) { System.out.println(Bundle.getString("status_couldnt_switch_vessel")); } diff --git a/src/main/java/com/pesterenan/controllers/DockingController.java b/src/main/java/com/pesterenan/controllers/DockingController.java index 93e3872..4144515 100644 --- a/src/main/java/com/pesterenan/controllers/DockingController.java +++ b/src/main/java/com/pesterenan/controllers/DockingController.java @@ -6,7 +6,7 @@ import java.util.Map; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Utilities; import com.pesterenan.utils.Vector; import com.pesterenan.views.DockingJPanel; @@ -57,15 +57,15 @@ public DockingController(Map commands) { private void initializeParameters() { try { - DOCKING_MAX_SPEED = Double.parseDouble(commands.get(Modulos.VELOCIDADE_MAX.get())); - SAFE_DISTANCE = Double.parseDouble(commands.get(Modulos.DISTANCIA_SEGURA.get())); + DOCKING_MAX_SPEED = Double.parseDouble(commands.get(Module.MAX_SPEED.get())); + SAFE_DISTANCE = Double.parseDouble(commands.get(Module.SAFE_DISTANCE.get())); drawing = Drawing.newInstance(getConnection()); targetVessel = getSpaceCenter().getTargetVessel(); - control = getNaveAtual().getControl(); - vesselRefFrame = getNaveAtual().getReferenceFrame(); - orbitalRefVessel = getNaveAtual().getOrbitalReferenceFrame(); + control = getActiveVessel().getControl(); + vesselRefFrame = getActiveVessel().getReferenceFrame(); + orbitalRefVessel = getActiveVessel().getOrbitalReferenceFrame(); - myDockingPort = getNaveAtual().getParts().getDockingPorts().get(0); + myDockingPort = getActiveVessel().getParts().getDockingPorts().get(0); targetDockingPort = targetVessel.getParts().getDockingPorts().get(0); dockingStep = DOCKING_STEPS.STOP_RELATIVE_SPEED; @@ -77,25 +77,25 @@ private void initializeParameters() { @Override public void run() { - if (commands.get(Modulos.MODULO.get()).equals(Modulos.MODULO_DOCKING.get())) { + if (commands.get(Module.MODULO.get()).equals(Module.DOCKING.get())) { startDocking(); } } private void pointToTarget(Vector targetDirection) throws RPCException, InterruptedException { - getNaveAtual().getAutoPilot().setReferenceFrame(orbitalRefVessel); - getNaveAtual().getAutoPilot().setTargetDirection(targetDirection.toTriplet()); - getNaveAtual().getAutoPilot().setTargetRoll(90); - getNaveAtual().getAutoPilot().engage(); + getActiveVessel().getAutoPilot().setReferenceFrame(orbitalRefVessel); + getActiveVessel().getAutoPilot().setTargetDirection(targetDirection.toTriplet()); + getActiveVessel().getAutoPilot().setTargetRoll(90); + getActiveVessel().getAutoPilot().engage(); // Fazer a nave apontar usando o piloto automático, na marra - while (Math.abs(getNaveAtual().getAutoPilot().getError()) > 3) { + while (Math.abs(getActiveVessel().getAutoPilot().getError()) > 3) { if (Thread.interrupted()) { throw new InterruptedException(); } Thread.sleep(100); - System.out.println(getNaveAtual().getAutoPilot().getError()); + System.out.println(getActiveVessel().getAutoPilot().getError()); } - getNaveAtual().getAutoPilot().disengage(); + getActiveVessel().getAutoPilot().disengage(); control.setSAS(true); control.setSASMode(SASMode.STABILITY_ASSIST); } @@ -128,7 +128,7 @@ public void startDocking() { Vector targetPosition = new Vector(targetVessel.position(vesselRefFrame)); if (targetPosition.magnitude() > SAFE_DISTANCE) { // Apontar para o alvo: - Vector targetDirection = new Vector(getNaveAtual().position(orbitalRefVessel)) + Vector targetDirection = new Vector(getActiveVessel().position(orbitalRefVessel)) .subtract(new Vector(targetVessel.position(orbitalRefVessel))).multiply(-1); pointToTarget(targetDirection); diff --git a/src/main/java/com/pesterenan/controllers/LandingController.java b/src/main/java/com/pesterenan/controllers/LandingController.java index df9072c..b93cc3d 100644 --- a/src/main/java/com/pesterenan/controllers/LandingController.java +++ b/src/main/java/com/pesterenan/controllers/LandingController.java @@ -6,7 +6,7 @@ import com.pesterenan.resources.Bundle; import com.pesterenan.utils.ControlePID; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Navigation; import com.pesterenan.utils.Utilities; @@ -36,7 +36,7 @@ public class LandingController extends Controller { public LandingController(Map commands) { super(); this.commands = commands; - this.navigation = new Navigation(getNaveAtual()); + this.navigation = new Navigation(getActiveVessel()); this.initializeParameters(); } @@ -49,17 +49,17 @@ private void initializeParameters() { @Override public void run() { - if (commands.get(Modulos.MODULO.get()).equals(Modulos.MODULO_POUSO_SOBREVOAR.get())) { + if (commands.get(Module.MODULO.get()).equals(Module.HOVERING.get())) { hoverArea(); } - if (commands.get(Modulos.MODULO.get()).equals(Modulos.MODULO_POUSO.get())) { + if (commands.get(Module.MODULO.get()).equals(Module.LANDING.get())) { autoLanding(); } } private void hoverArea() { try { - hoverAltitude = Double.parseDouble(commands.get(Modulos.ALTITUDE_SOBREVOO.get())); + hoverAltitude = Double.parseDouble(commands.get(Module.HOVER_ALTITUDE.get())); hoveringMode = true; ap.engage(); tuneAutoPilot(); @@ -68,7 +68,7 @@ private void hoverArea() { throw new InterruptedException(); } try { - altitudeErrorPercentage = altitudeSup.get() / hoverAltitude * HUNDRED_PERCENT; + altitudeErrorPercentage = surfaceAltitude.get() / hoverAltitude * HUNDRED_PERCENT; // Select which mode depending on altitude error: if (altitudeErrorPercentage > HUNDRED_PERCENT) { currentMode = MODE.GOING_DOWN; @@ -90,9 +90,9 @@ private void hoverArea() { private void autoLanding() { try { landingMode = true; - maxTWR = Float.parseFloat(commands.get(Modulos.MAX_TWR.get())); - hoverAfterApproximation = Boolean.parseBoolean(commands.get(Modulos.SOBREVOO_POS_POUSO.get())); - hoverAltitude = Double.parseDouble(commands.get(Modulos.ALTITUDE_SOBREVOO.get())); + maxTWR = Float.parseFloat(commands.get(Module.MAX_TWR.get())); + hoverAfterApproximation = Boolean.parseBoolean(commands.get(Module.HOVER_AFTER_LANDING.get())); + hoverAltitude = Double.parseDouble(commands.get(Module.HOVER_ALTITUDE.get())); if (!hoverAfterApproximation) { hoverAltitude = 100; } @@ -106,7 +106,7 @@ private void autoLanding() { if (Thread.interrupted()) { throw new InterruptedException(); } - getNaveAtual().getControl().setBrakes(true); + getActiveVessel().getControl().setBrakes(true); changeControlMode(); Thread.sleep(sleepTime); } @@ -125,7 +125,7 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt currentMode = MODE.WAITING; break; case WAITING: - if (velVertical.get() > 0) { + if (verticalVelocity.get() > 0) { setCurrentStatus(Bundle.getString("status_waiting_for_landing")); throttle(0.0f); } else { @@ -144,13 +144,13 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt ((currentVelocity + zeroVelocity) - landingDistanceThreshold) / landingDistanceThreshold, 0, 1); altPID = altitudeCtrl.calculate(currentVelocity / sleepTime, zeroVelocity / sleepTime); - velPID = velocityCtrl.calculate(velVertical.get() / sleepTime, - (-Utilities.clamp(altitudeSup.get() * 0.1, 3, 20) / sleepTime)); + velPID = velocityCtrl.calculate(verticalVelocity.get() / sleepTime, + (-Utilities.clamp(surfaceAltitude.get() * 0.1, 3, 20) / sleepTime)); throttle(Utilities.linearInterpolation(velPID, altPID, threshold)); navigation.aimForLanding(); - if (threshold < 0.15 || altitudeSup.get() < landingDistanceThreshold) { + if (threshold < 0.15 || surfaceAltitude.get() < landingDistanceThreshold) { hoverAltitude = landingDistanceThreshold; - getNaveAtual().getControl().setGear(true); + getActiveVessel().getControl().setGear(true); if (hoverAfterApproximation) { landingMode = false; hoverArea(); @@ -166,7 +166,7 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt altitudeCtrl.setOutput(-0.5, 0.5); velocityCtrl.setOutput(-0.5, 0.5); altPID = altitudeCtrl.calculate(altitudeErrorPercentage, HUNDRED_PERCENT); - velPID = velocityCtrl.calculate(velVertical.get(), MAX_VELOCITY); + velPID = velocityCtrl.calculate(verticalVelocity.get(), MAX_VELOCITY); throttle(altPID + velPID); navigation.aimAtRadialOut(); setCurrentStatus("Subindo altitude..."); @@ -182,7 +182,7 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt altitudeCtrl.reset(); velocityCtrl.reset(); controlThrottleByMatchingVerticalVelocity( - velHorizontal.get() > 4 ? 0 : -Utilities.clamp(altitudeSup.get() * 0.1, 1, 10)); + horizontalVelocity.get() > 4 ? 0 : -Utilities.clamp(surfaceAltitude.get() * 0.1, 1, 10)); navigation.aimForLanding(); setCurrentStatus("Pousando..."); hasTheVesselLanded(); @@ -193,7 +193,7 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt altitudeCtrl.setOutput(-0.5, 0.5); velocityCtrl.setOutput(-0.5, 0.5); altPID = altitudeCtrl.calculate(altitudeErrorPercentage, HUNDRED_PERCENT); - velPID = velocityCtrl.calculate(velVertical.get(), 0); + velPID = velocityCtrl.calculate(verticalVelocity.get(), 0); throttle(altPID + velPID); navigation.aimAtRadialOut(); setCurrentStatus("Sobrevoando area..."); @@ -204,16 +204,16 @@ private void changeControlMode() throws RPCException, StreamException, Interrupt private void controlThrottleByMatchingVerticalVelocity(double velocityToMatch) throws RPCException, StreamException { velocityCtrl.setOutput(0, 1); - throttle(velocityCtrl.calculate(velVertical.get(), velocityToMatch + velHorizontal.get())); + throttle(velocityCtrl.calculate(verticalVelocity.get(), velocityToMatch + horizontalVelocity.get())); } private void deOrbitShip() throws RPCException, StreamException, InterruptedException { throttle(0.0f); - if (getNaveAtual().getSituation().equals(VesselSituation.ORBITING) || - getNaveAtual().getSituation().equals(VesselSituation.SUB_ORBITAL)) { + if (getActiveVessel().getSituation().equals(VesselSituation.ORBITING) || + getActiveVessel().getSituation().equals(VesselSituation.SUB_ORBITAL)) { setCurrentStatus(Bundle.getString("status_going_suborbital")); ap.engage(); - getNaveAtual().getControl().setRCS(true); + getActiveVessel().getControl().setRCS(true); while (ap.getError() > 5) { navigation.aimForLanding(); setCurrentStatus(Bundle.getString("status_orienting_ship")); @@ -222,13 +222,13 @@ private void deOrbitShip() throws RPCException, StreamException, InterruptedExce } double targetPeriapsis = currentBody.getAtmosphereDepth(); targetPeriapsis = targetPeriapsis > 0 ? targetPeriapsis / 2 : -currentBody.getEquatorialRadius() / 2; - while (periastro.get() > -apoastro.get()) { + while (periapsis.get() > -apoapsis.get()) { navigation.aimForLanding(); - throttle(altitudeCtrl.calculate(targetPeriapsis, periastro.get())); + throttle(altitudeCtrl.calculate(targetPeriapsis, periapsis.get())); setCurrentStatus(Bundle.getString("status_lowering_periapsis")); Thread.sleep(sleepTime); } - getNaveAtual().getControl().setRCS(false); + getActiveVessel().getControl().setRCS(false); throttle(0.0f); } } @@ -246,15 +246,15 @@ private void adjustPIDbyTWR() throws RPCException, StreamException { } private boolean hasTheVesselLanded() throws RPCException { - if (getNaveAtual().getSituation().equals(VesselSituation.LANDED) || - getNaveAtual().getSituation().equals(VesselSituation.SPLASHED)) { + if (getActiveVessel().getSituation().equals(VesselSituation.LANDED) || + getActiveVessel().getSituation().equals(VesselSituation.SPLASHED)) { setCurrentStatus(Bundle.getString("status_landed")); hoveringMode = false; landingMode = false; throttle(0.0f); - getNaveAtual().getControl().setSAS(true); - getNaveAtual().getControl().setRCS(true); - getNaveAtual().getControl().setBrakes(false); + getActiveVessel().getControl().setSAS(true); + getActiveVessel().getControl().setRCS(true); + getActiveVessel().getControl().setBrakes(false); ap.disengage(); return true; } @@ -262,13 +262,13 @@ private boolean hasTheVesselLanded() throws RPCException { } private double calculateCurrentVelocityMagnitude() throws RPCException, StreamException { - double timeToGround = altitudeSup.get() / velVertical.get(); - double horizontalDistance = velHorizontal.get() * timeToGround; - return calculateEllipticTrajectory(horizontalDistance, altitudeSup.get()); + double timeToGround = surfaceAltitude.get() / verticalVelocity.get(); + double horizontalDistance = horizontalVelocity.get() * timeToGround; + return calculateEllipticTrajectory(horizontalDistance, surfaceAltitude.get()); } private double calculateZeroVelocityMagnitude() throws RPCException, StreamException { - double zeroVelocityDistance = calculateEllipticTrajectory(velHorizontal.get(), velVertical.get()); + double zeroVelocityDistance = calculateEllipticTrajectory(horizontalVelocity.get(), verticalVelocity.get()); double zeroVelocityBurnTime = zeroVelocityDistance / getMaxAcel(maxTWR); return zeroVelocityDistance * zeroVelocityBurnTime; } diff --git a/src/main/java/com/pesterenan/controllers/LiftoffController.java b/src/main/java/com/pesterenan/controllers/LiftoffController.java index b81b0d8..1311232 100644 --- a/src/main/java/com/pesterenan/controllers/LiftoffController.java +++ b/src/main/java/com/pesterenan/controllers/LiftoffController.java @@ -2,21 +2,22 @@ import static com.pesterenan.MechPeste.getSpaceCenter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; import com.pesterenan.utils.ControlePID; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Navigation; import com.pesterenan.utils.Utilities; + import krpc.client.RPCException; import krpc.client.StreamException; import krpc.client.services.SpaceCenter.Engine; import krpc.client.services.SpaceCenter.Fairing; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class LiftoffController extends Controller { private static final float PITCH_UP = 90; @@ -28,25 +29,25 @@ public class LiftoffController extends Controller { private float maxTWR; private boolean willDecoupleStages, willOpenPanelsAndAntenna; - private String gravityCurveModel = Modulos.CIRCULAR.get(); + private String gravityCurveModel = Module.CIRCULAR.get(); private Navigation navigation; public LiftoffController(Map commands) { super(); this.commands = commands; - this.navigation = new Navigation(getNaveAtual()); + this.navigation = new Navigation(getActiveVessel()); initializeParameters(); } private void initializeParameters() { currentPitch = PITCH_UP; - setFinalApoapsisAlt(Float.parseFloat(commands.get(Modulos.APOASTRO.get()))); - setHeading(Float.parseFloat(commands.get(Modulos.DIRECAO.get()))); - setRoll(Float.parseFloat(commands.get(Modulos.ROLAGEM.get()))); - maxTWR = (float) Utilities.clamp(Float.parseFloat(commands.get(Modulos.MAX_TWR.get())), 1.2, 5.0); - setGravityCurveModel(commands.get(Modulos.INCLINACAO.get())); - willOpenPanelsAndAntenna = Boolean.parseBoolean(commands.get(Modulos.ABRIR_PAINEIS.get())); - willDecoupleStages = Boolean.parseBoolean(commands.get(Modulos.USAR_ESTAGIOS.get())); + setFinalApoapsisAlt(Float.parseFloat(commands.get(Module.APOAPSIS.get()))); + setHeading(Float.parseFloat(commands.get(Module.DIRECTION.get()))); + setRoll(Float.parseFloat(commands.get(Module.ROLL.get()))); + maxTWR = (float) Utilities.clamp(Float.parseFloat(commands.get(Module.MAX_TWR.get())), 1.2, 5.0); + setGravityCurveModel(commands.get(Module.INCLINATION.get())); + willOpenPanelsAndAntenna = Boolean.parseBoolean(commands.get(Module.OPEN_PANELS.get())); + willDecoupleStages = Boolean.parseBoolean(commands.get(Module.STAGE.get())); thrControl = new ControlePID(getSpaceCenter(), 25); thrControl.setOutput(0.0, 1.0); } @@ -73,7 +74,7 @@ private void gravityCurve() throws RPCException, StreamException, InterruptedExc double startCurveAlt = altitude.get(); while (currentPitch > 1) { - if (apoastro.get() > getFinalApoapsis()) { + if (apoapsis.get() > getFinalApoapsis()) { throttle(0); break; } @@ -82,7 +83,7 @@ private void gravityCurve() throws RPCException, StreamException, InterruptedExc currentPitch = (float) (calculateCurrentPitch(altitudeProgress)); double currentMaxTWR = calculateTWRBasedOnPressure(currentPitch); ap.setTargetPitch(currentPitch); - throttle(Math.min(thrControl.calculate(apoastro.get() / getFinalApoapsis() * 1000, 1000), + throttle(Math.min(thrControl.calculate(apoapsis.get() / getFinalApoapsis() * 1000, 1000), getMaxThrottleForTWR(currentMaxTWR))); if (willDecoupleStages && isCurrentStageWithoutFuel()) { @@ -98,7 +99,7 @@ private void gravityCurve() throws RPCException, StreamException, InterruptedExc } private double calculateTWRBasedOnPressure(float currentPitch) throws RPCException { - float currentPressure = parametrosDeVoo.getDynamicPressure(); + float currentPressure = flightParameters.getDynamicPressure(); if (currentPressure <= 10) { return Utilities.remap(90.0, 0.0, maxTWR, 5.0, currentPitch, true); } @@ -107,14 +108,14 @@ private double calculateTWRBasedOnPressure(float currentPitch) throws RPCExcepti private void finalizeCurve() throws RPCException, StreamException, InterruptedException { setCurrentStatus(Bundle.getString("status_maintaining_until_orbit")); - getNaveAtual().getControl().setRCS(true); + getActiveVessel().getControl().setRCS(true); - while (parametrosDeVoo.getDynamicPressure() > 10) { + while (flightParameters.getDynamicPressure() > 10) { if (Thread.interrupted()) { throw new InterruptedException(); } navigation.aimAtPrograde(); - throttle(thrControl.calculate(apoastro.get() / getFinalApoapsis() * 1000, 1000)); + throttle(thrControl.calculate(apoapsis.get() / getFinalApoapsis() * 1000, 1000)); Thread.sleep(25); } throttle(0.0f); @@ -129,14 +130,14 @@ private void finalizeCurve() throws RPCException, StreamException, InterruptedEx private void circularizeOrbitOnApoapsis() { setCurrentStatus(Bundle.getString("status_planning_orbit")); Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), Modulos.MODULE_MANEUVER.get()); - commands.put(Modulos.FUNCAO.get(), Modulos.APOASTRO.get()); - commands.put(Modulos.AJUSTE_FINO.get(), String.valueOf(false)); + commands.put(Module.MODULO.get(), Module.MANEUVER.get()); + commands.put(Module.FUNCTION.get(), Module.APOAPSIS.get()); + commands.put(Module.FINE_ADJUST.get(), String.valueOf(false)); MechPeste.newInstance().startModule(commands); } private void jettisonFairings() throws RPCException, InterruptedException { - List fairings = getNaveAtual().getParts().getFairings(); + List fairings = getActiveVessel().getParts().getFairings(); if (fairings.size() > 0) { setCurrentStatus(Bundle.getString("status_jettisoning_shields")); for (Fairing f : fairings) { @@ -152,30 +153,30 @@ private void jettisonFairings() throws RPCException, InterruptedException { } private void openPanelsAndAntenna() throws RPCException, InterruptedException { - getNaveAtual().getControl().setSolarPanels(true); - getNaveAtual().getControl().setRadiators(true); - getNaveAtual().getControl().setAntennas(true); + getActiveVessel().getControl().setSolarPanels(true); + getActiveVessel().getControl().setRadiators(true); + getActiveVessel().getControl().setAntennas(true); } private double calculateCurrentPitch(double currentAltitude) { - if (gravityCurveModel.equals(Modulos.QUADRATICA.get())) { + if (gravityCurveModel.equals(Module.QUADRATIC.get())) { return Utilities.easeInQuad(currentAltitude) * PITCH_UP; } - if (gravityCurveModel.equals(Modulos.CUBICA.get())) { + if (gravityCurveModel.equals(Module.CUBIC.get())) { return Utilities.easeInCubic(currentAltitude) * PITCH_UP; } - if (gravityCurveModel.equals(Modulos.SINUSOIDAL.get())) { + if (gravityCurveModel.equals(Module.SINUSOIDAL.get())) { return Utilities.easeInSine(currentAltitude) * PITCH_UP; } - if (gravityCurveModel.equals(Modulos.EXPONENCIAL.get())) { + if (gravityCurveModel.equals(Module.EXPONENCIAL.get())) { return Utilities.easeInExpo(currentAltitude) * PITCH_UP; } return Utilities.easeInCirc(currentAltitude) * PITCH_UP; } private boolean isCurrentStageWithoutFuel() throws RPCException { - for (Engine engine : getNaveAtual().getParts().getEngines()) { - if (engine.getPart().getStage() == getNaveAtual().getControl().getCurrentStage() && !engine.getHasFuel()) { + for (Engine engine : getActiveVessel().getParts().getEngines()) { + if (engine.getPart().getStage() == getActiveVessel().getControl().getCurrentStage() && !engine.getHasFuel()) { return true; } } diff --git a/src/main/java/com/pesterenan/controllers/ManeuverController.java b/src/main/java/com/pesterenan/controllers/ManeuverController.java index 10f4f96..a46c6fd 100644 --- a/src/main/java/com/pesterenan/controllers/ManeuverController.java +++ b/src/main/java/com/pesterenan/controllers/ManeuverController.java @@ -11,7 +11,7 @@ import com.pesterenan.resources.Bundle; import com.pesterenan.utils.Attributes; import com.pesterenan.utils.ControlePID; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Navigation; import com.pesterenan.utils.Vector; import com.pesterenan.views.RunManeuverJPanel; @@ -39,7 +39,7 @@ public class ManeuverController extends Controller { public ManeuverController(Map commands) { super(); this.commands = commands; - this.navigation = new Navigation(getNaveAtual()); + this.navigation = new Navigation(getActiveVessel()); initializeParameters(); } @@ -48,7 +48,7 @@ private void initializeParameters() { ctrlManeuver = new ControlePID(getSpaceCenter(), 25); ctrlManeuver.setPIDValues(1, 0.001, 0.1); ctrlRCS.setOutput(0.5, 1.0); - fineAdjustment = canFineAdjust(commands.get(Modulos.AJUSTE_FINO.get())); + fineAdjustment = canFineAdjust(commands.get(Module.FINE_ADJUST.get())); try { lowOrbitAltitude = new Attributes().getLowOrbitAltitude(currentBody.getName()); System.out.println("lowOrbitAltitude: " + lowOrbitAltitude); @@ -59,9 +59,9 @@ private void initializeParameters() { @Override public void run() { calculateManeuver(); - if (!(commands.get(Modulos.FUNCAO.get()).equals(Modulos.RENDEZVOUS.get()) - || commands.get(Modulos.FUNCAO.get()).equals(Modulos.ORBITA_BAIXA.get()) - || commands.get(Modulos.FUNCAO.get()).equals(Modulos.AJUSTAR.get()))) { + if (!(commands.get(Module.FUNCTION.get()).equals(Module.RENDEZVOUS.get()) + || commands.get(Module.FUNCTION.get()).equals(Module.LOW_ORBIT.get()) + || commands.get(Module.FUNCTION.get()).equals(Module.ADJUST.get()))) { executeNextManeuver(); } } @@ -69,7 +69,7 @@ public void run() { private Node biEllipticTransferToOrbit(double targetAltitude, double timeToStart) { double[] totalDv = { 0, 0, 0 }; try { - Orbit currentOrbit = getNaveAtual().getOrbit(); + Orbit currentOrbit = getActiveVessel().getOrbit(); double startingRadius = currentOrbit.getApoapsis(); double gravParameter = currentBody.getGravitationalParameter(); @@ -103,42 +103,42 @@ public void calculateManeuver() { try { tuneAutoPilot(); System.out.println(commands + " calculate maneuvers"); - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.EXECUTAR.get())) { + if (commands.get(Module.FUNCTION.get()).equals(Module.EXECUTE.get())) { return; } - if (getNaveAtual().getSituation() == VesselSituation.LANDED || - getNaveAtual().getSituation() == VesselSituation.SPLASHED) { + if (getActiveVessel().getSituation() == VesselSituation.LANDED || + getActiveVessel().getSituation() == VesselSituation.SPLASHED) { throw new InterruptedException(); } - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.AJUSTAR.get())) { + if (commands.get(Module.FUNCTION.get()).equals(Module.ADJUST.get())) { this.alignPlanesWithTargetVessel(); return; } - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.RENDEZVOUS.get())) { + if (commands.get(Module.FUNCTION.get()).equals(Module.RENDEZVOUS.get())) { this.rendezvousWithTargetVessel(); return; } - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.ORBITA_BAIXA.get())) { - biEllipticTransferToOrbit(lowOrbitAltitude, getNaveAtual().getOrbit().getTimeToPeriapsis()); + if (commands.get(Module.FUNCTION.get()).equals(Module.LOW_ORBIT.get())) { + biEllipticTransferToOrbit(lowOrbitAltitude, getActiveVessel().getOrbit().getTimeToPeriapsis()); return; } double gravParameter = currentBody.getGravitationalParameter(); - double altitudeInicial = 0, tempoAteAltitude = 0; - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.APOASTRO.get())) { - altitudeInicial = getNaveAtual().getOrbit().getApoapsis(); - tempoAteAltitude = getNaveAtual().getOrbit().getTimeToApoapsis(); + double startingAltitutde = 0, timeUntilAltitude = 0; + if (commands.get(Module.FUNCTION.get()).equals(Module.APOAPSIS.get())) { + startingAltitutde = getActiveVessel().getOrbit().getApoapsis(); + timeUntilAltitude = getActiveVessel().getOrbit().getTimeToApoapsis(); } - if (commands.get(Modulos.FUNCAO.get()).equals(Modulos.PERIASTRO.get())) { - altitudeInicial = getNaveAtual().getOrbit().getPeriapsis(); - tempoAteAltitude = getNaveAtual().getOrbit().getTimeToPeriapsis(); + if (commands.get(Module.FUNCTION.get()).equals(Module.PERIAPSIS.get())) { + startingAltitutde = getActiveVessel().getOrbit().getPeriapsis(); + timeUntilAltitude = getActiveVessel().getOrbit().getTimeToPeriapsis(); } - double semiEixoMaior = getNaveAtual().getOrbit().getSemiMajorAxis(); - double velOrbitalAtual = Math.sqrt(gravParameter * ((2.0 / altitudeInicial) - (1.0 / semiEixoMaior))); - double velOrbitalAlvo = Math.sqrt(gravParameter * ((2.0 / altitudeInicial) - (1.0 / altitudeInicial))); - double deltaVdaManobra = velOrbitalAlvo - velOrbitalAtual; - double[] deltaV = { deltaVdaManobra, 0, 0 }; - createManeuver(tempoAteAltitude, deltaV); + double semiMajorAxis = getActiveVessel().getOrbit().getSemiMajorAxis(); + double currentOrbitalVelocity = Math.sqrt(gravParameter * ((2.0 / startingAltitutde) - (1.0 / semiMajorAxis))); + double targetOrbitalVelocity = Math.sqrt(gravParameter * ((2.0 / startingAltitutde) - (1.0 / startingAltitutde))); + double maneuverDeltaV = targetOrbitalVelocity - currentOrbitalVelocity; + double[] deltaV = { maneuverDeltaV, 0, 0 }; + createManeuver(timeUntilAltitude, deltaV); } catch (RPCException | InterruptedException e) { setCurrentStatus(Bundle.getString("status_maneuver_not_possible")); } @@ -149,7 +149,7 @@ public void matchOrbitApoapsis() { Orbit targetOrbit = getTargetOrbit(); System.out.println(targetOrbit.getApoapsis() + "-- APO"); Node maneuver = biEllipticTransferToOrbit(targetOrbit.getApoapsis(), - getNaveAtual().getOrbit().getTimeToPeriapsis()); + getActiveVessel().getOrbit().getTimeToPeriapsis()); while (true) { if (Thread.interrupted()) { throw new InterruptedException(); @@ -183,7 +183,7 @@ private Node createManeuverAtClosestIncNode(Orbit targetOrbit) { } private double[] getTimeToIncNodes(Orbit targetOrbit) throws RPCException { - Orbit vesselOrbit = getNaveAtual().getOrbit(); + Orbit vesselOrbit = getActiveVessel().getOrbit(); double ascendingNode = vesselOrbit.trueAnomalyAtAN(targetOrbit); double descendingNode = vesselOrbit.trueAnomalyAtDN(targetOrbit); return new double[] { vesselOrbit.uTAtTrueAnomaly(ascendingNode), vesselOrbit.uTAtTrueAnomaly(descendingNode) }; @@ -191,8 +191,8 @@ private double[] getTimeToIncNodes(Orbit targetOrbit) throws RPCException { private void alignPlanesWithTargetVessel() { try { - Vessel vessel = getNaveAtual(); - Orbit vesselOrbit = getNaveAtual().getOrbit(); + Vessel vessel = getActiveVessel(); + Orbit vesselOrbit = getActiveVessel().getOrbit(); Orbit targetVesselOrbit = getSpaceCenter().getTargetVessel().getOrbit(); boolean hasManeuverNodes = vessel.getControl().getNodes().size() > 0; System.out.println("hasManeuverNodes: " + hasManeuverNodes); @@ -224,22 +224,22 @@ private void alignPlanesWithTargetVessel() { private void rendezvousWithTargetVessel() { try { - boolean hasManeuverNodes = getNaveAtual().getControl().getNodes().size() > 0; - List currentManeuvers = getNaveAtual().getControl().getNodes(); + boolean hasManeuverNodes = getActiveVessel().getControl().getNodes().size() > 0; + List currentManeuvers = getActiveVessel().getControl().getNodes(); Node lastManeuverNode; double lastManeuverNodeUT = 60; if (hasManeuverNodes) { - currentManeuvers = getNaveAtual().getControl().getNodes(); + currentManeuvers = getActiveVessel().getControl().getNodes(); lastManeuverNode = currentManeuvers.get(currentManeuvers.size() - 1); lastManeuverNodeUT += lastManeuverNode.getUT(); RunManeuverJPanel.createManeuver(lastManeuverNodeUT); } else { RunManeuverJPanel.createManeuver(); } - currentManeuvers = getNaveAtual().getControl().getNodes(); + currentManeuvers = getActiveVessel().getControl().getNodes(); lastManeuverNode = currentManeuvers.get(currentManeuvers.size() - 1); - Orbit activeVesselOrbit = getNaveAtual().getOrbit(); + Orbit activeVesselOrbit = getActiveVessel().getOrbit(); Orbit targetVesselOrbit = getSpaceCenter().getTargetVessel().getOrbit(); ReferenceFrame currentBodyRefFrame = activeVesselOrbit.getBody().getNonRotatingReferenceFrame(); @@ -380,10 +380,10 @@ private Orbit getTargetOrbit() throws RPCException { private Node createManeuver(double laterTime, double[] deltaV) { Node maneuverNode = null; try { - getNaveAtual().getControl() + getActiveVessel().getControl() .addNode(getSpaceCenter().getUT() + laterTime, (float) deltaV[0], (float) deltaV[1], (float) deltaV[2]); - List currentNodes = getNaveAtual().getControl().getNodes(); + List currentNodes = getActiveVessel().getControl().getNodes(); maneuverNode = currentNodes.get(currentNodes.size() - 1); } catch (UnsupportedOperationException | RPCException e) { setCurrentStatus(Bundle.getString("status_maneuver_not_possible")); @@ -393,7 +393,7 @@ private Node createManeuver(double laterTime, double[] deltaV) { public void executeNextManeuver() { try { - Node maneuverNode = getNaveAtual().getControl().getNodes().get(0); + Node maneuverNode = getActiveVessel().getControl().getNodes().get(0); double burnTime = calculateBurnTime(maneuverNode); orientToManeuverNode(maneuverNode); executeBurn(maneuverNode, burnTime); @@ -421,48 +421,48 @@ public void orientToManeuverNode(Node maneuverNode) throws InterruptedException, } - public double calculateBurnTime(Node noDeManobra) throws RPCException { + public double calculateBurnTime(Node maneuverNode) throws RPCException { - List motores = getNaveAtual().getParts().getEngines(); - for (Engine motor : motores) { - if (motor.getPart().getStage() == getNaveAtual().getControl().getCurrentStage() && !motor.getActive()) { - motor.setActive(true); + List engines = getActiveVessel().getParts().getEngines(); + for (Engine engine : engines) { + if (engine.getPart().getStage() == getActiveVessel().getControl().getCurrentStage() && !engine.getActive()) { + engine.setActive(true); } } - double empuxo = getNaveAtual().getAvailableThrust(); - double isp = getNaveAtual().getSpecificImpulse() * CONST_GRAV; - double massaTotal = getNaveAtual().getMass(); - double massaSeca = massaTotal / Math.exp(noDeManobra.getDeltaV() / isp); - double taxaDeQueima = empuxo / isp; - double duracaoDaQueima = (massaTotal - massaSeca) / taxaDeQueima; - - setCurrentStatus("Tempo de Queima da Manobra: " + duracaoDaQueima + " segundos"); - return duracaoDaQueima; + double thrust = getActiveVessel().getAvailableThrust(); + double isp = getActiveVessel().getSpecificImpulse() * CONST_GRAV; + double totalMass = getActiveVessel().getMass(); + double dryMass = totalMass / Math.exp(maneuverNode.getDeltaV() / isp); + double burnRatio = thrust / isp; + double burnDuration = (totalMass - dryMass) / burnRatio; + + setCurrentStatus("Tempo de Queima da Manobra: " + burnDuration + " segundos"); + return burnDuration; } - public void executeBurn(Node noDeManobra, double duracaoDaQueima) { + public void executeBurn(Node maneuverNode, double burnDuration) { try { - double inicioDaQueima = noDeManobra.getTimeTo() - (duracaoDaQueima / 2.0) - (fineAdjustment ? 5 : 0); + double burnStartTime = maneuverNode.getTimeTo() - (burnDuration / 2.0) - (fineAdjustment ? 5 : 0); setCurrentStatus(Bundle.getString("status_maneuver_warp")); - if (inicioDaQueima > 30) { - getSpaceCenter().warpTo((getSpaceCenter().getUT() + inicioDaQueima - 10), 100000, 4); + if (burnStartTime > 30) { + getSpaceCenter().warpTo((getSpaceCenter().getUT() + burnStartTime - 10), 100000, 4); } // Mostrar tempo de ignição: - setCurrentStatus(String.format(Bundle.getString("status_maneuver_duration"), duracaoDaQueima)); - while (inicioDaQueima > 0) { + setCurrentStatus(String.format(Bundle.getString("status_maneuver_duration"), burnDuration)); + while (burnStartTime > 0) { if (Thread.interrupted()) { throw new InterruptedException(); } - inicioDaQueima = Math.max(noDeManobra.getTimeTo() - (duracaoDaQueima / 2.0), 0.0); - navigation.aimAtManeuver(noDeManobra); - setCurrentStatus(String.format(Bundle.getString("status_maneuver_ignition_in"), inicioDaQueima)); + burnStartTime = Math.max(maneuverNode.getTimeTo() - (burnDuration / 2.0), 0.0); + navigation.aimAtManeuver(maneuverNode); + setCurrentStatus(String.format(Bundle.getString("status_maneuver_ignition_in"), burnStartTime)); Thread.sleep(100); } // Executar a manobra: - Stream> remainingBurn = getConnection().addStream(noDeManobra, - "remainingBurnVector", noDeManobra.getReferenceFrame()); + Stream> remainingBurn = getConnection().addStream(maneuverNode, + "remainingBurnVector", maneuverNode.getReferenceFrame()); setCurrentStatus(Bundle.getString("status_maneuver_executing")); - while (noDeManobra != null) { + while (maneuverNode != null) { double burnDvLeft = remainingBurn.get().getValue1(); if (Thread.interrupted()) { throw new InterruptedException(); @@ -471,10 +471,10 @@ public void executeBurn(Node noDeManobra, double duracaoDaQueima) { throttle(0.0f); break; } - navigation.aimAtManeuver(noDeManobra); + navigation.aimAtManeuver(maneuverNode); float limitValue = burnDvLeft > 100 ? 1000 : 100; - throttle(ctrlManeuver.calculate((noDeManobra.getDeltaV() - Math.floor(burnDvLeft)) / - noDeManobra.getDeltaV() * limitValue, limitValue)); + throttle(ctrlManeuver.calculate((maneuverNode.getDeltaV() - Math.floor(burnDvLeft)) / + maneuverNode.getDeltaV() * limitValue, limitValue)); Thread.sleep(25); } throttle(0.0f); @@ -483,10 +483,10 @@ public void executeBurn(Node noDeManobra, double duracaoDaQueima) { } ap.setReferenceFrame(surfaceReferenceFrame); ap.disengage(); - getNaveAtual().getControl().setSAS(true); - getNaveAtual().getControl().setRCS(false); + getActiveVessel().getControl().setSAS(true); + getActiveVessel().getControl().setRCS(false); remainingBurn.remove(); - noDeManobra.remove(); + maneuverNode.remove(); setCurrentStatus(Bundle.getString("status_ready")); } catch (StreamException | RPCException e) { setCurrentStatus(Bundle.getString("status_data_unavailable")); @@ -497,22 +497,22 @@ public void executeBurn(Node noDeManobra, double duracaoDaQueima) { private void adjustManeuverWithRCS(Stream> remainingDeltaV) throws RPCException, StreamException, InterruptedException { - getNaveAtual().getControl().setRCS(true); + getActiveVessel().getControl().setRCS(true); while (Math.floor(remainingDeltaV.get().getValue1()) > 0.2) { if (Thread.interrupted()) { throw new InterruptedException(); } - getNaveAtual().getControl().setForward((float) ctrlRCS.calculate(-remainingDeltaV.get().getValue1() * 10, + getActiveVessel().getControl().setForward((float) ctrlRCS.calculate(-remainingDeltaV.get().getValue1() * 10, 0)); Thread.sleep(25); } - getNaveAtual().getControl().setForward(0); + getActiveVessel().getControl().setForward(0); } private boolean canFineAdjust(String string) { if (string.equals("true")) { try { - List rcsEngines = getNaveAtual().getParts().getRCS(); + List rcsEngines = getActiveVessel().getParts().getRCS(); if (rcsEngines.size() > 0) { for (RCS rcs : rcsEngines) { if (rcs.getHasFuel()) { @@ -541,7 +541,7 @@ private double calculatePhaseAngle(Triplet startPos, Tri double targetOrbit = endPosition.magnitude(); - double activeVesselSMA = getNaveAtual().getOrbit().getSemiMajorAxis(); + double activeVesselSMA = getActiveVessel().getOrbit().getSemiMajorAxis(); angularDifference = targetPhaseAngle + Math.PI * (1 - (1 / (2 * Math.sqrt(2))) * Math.sqrt(Math.pow((activeVesselSMA / targetOrbit + 1), 3))); diff --git a/src/main/java/com/pesterenan/controllers/RoverController.java b/src/main/java/com/pesterenan/controllers/RoverController.java index aeab195..cdee276 100644 --- a/src/main/java/com/pesterenan/controllers/RoverController.java +++ b/src/main/java/com/pesterenan/controllers/RoverController.java @@ -2,7 +2,7 @@ import com.pesterenan.resources.Bundle; import com.pesterenan.utils.ControlePID; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.PathFinding; import com.pesterenan.utils.Utilities; import com.pesterenan.utils.Vector; @@ -41,9 +41,9 @@ public RoverController(Map commands) { private void initializeParameters() { try { - maxSpeed = Float.parseFloat(commands.get(Modulos.VELOCIDADE_MAX.get())); - roverReferenceFrame = getNaveAtual().getReferenceFrame(); - roverDirection = new Vector(getNaveAtual().direction(roverReferenceFrame)); + maxSpeed = Float.parseFloat(commands.get(Module.MAX_SPEED.get())); + roverReferenceFrame = getActiveVessel().getReferenceFrame(); + roverDirection = new Vector(getActiveVessel().direction(roverReferenceFrame)); pathFinding = new PathFinding(); acelCtrl.setOutput(0, 1); sterringCtrl.setOutput(-1, 1); @@ -62,7 +62,7 @@ private boolean isSolarPanelNotBroken(SolarPanel sp) { @Override public void run() { - if (commands.get(Modulos.MODULO.get()).equals(Modulos.MODULO_ROVER.get())) { + if (commands.get(Module.MODULO.get()).equals(Module.ROVER.get())) { setTarget(); driveRoverToTarget(); } @@ -70,12 +70,12 @@ public void run() { private void setTarget() { try { - if (commands.get(Modulos.TIPO_ALVO_ROVER.get()).equals(Modulos.MARCADOR_MAPA.get())) { - pathFinding.addWaypointsOnSameBody(commands.get(Modulos.NOME_MARCADOR.get())); + if (commands.get(Module.ROVER_TARGET_TYPE.get()).equals(Module.MAP_MARKER.get())) { + pathFinding.addWaypointsOnSameBody(commands.get(Module.MARKER_NAME.get())); setCurrentStatus("Calculando rota até o alvo..."); pathFinding.buildPathToTarget(pathFinding.findNearestWaypoint()); } - if (commands.get(Modulos.TIPO_ALVO_ROVER.get()).equals(Modulos.NAVE_ALVO.get())) { + if (commands.get(Module.ROVER_TARGET_TYPE.get()).equals(Module.TARGET_VESSEL.get())) { Vector targetVesselPosition = new Vector( getSpaceCenter().getTargetVessel().position(orbitalReferenceFrame)); setCurrentStatus("Calculando rota até o alvo..."); @@ -116,7 +116,7 @@ private void driveRoverToTarget() { } } catch (InterruptedException | RPCException | IOException | StreamException ignored) { try { - getNaveAtual().getControl().setBrakes(true); + getActiveVessel().getControl().setBrakes(true); pathFinding.removeDrawnPath(); isAutoRoverRunning = false; setCurrentStatus(Bundle.getString("lbl_stat_ready")); @@ -127,9 +127,9 @@ private void driveRoverToTarget() { private void setNextPointInPath() throws RPCException, IOException, InterruptedException { pathFinding.removePathsCurrentPoint(); - getNaveAtual().getControl().setBrakes(true); + getActiveVessel().getControl().setBrakes(true); if (pathFinding.isPathToTargetEmpty()) { - if (commands.get(Modulos.TIPO_ALVO_ROVER.get()).equals(Modulos.MARCADOR_MAPA.get())) { + if (commands.get(Module.ROVER_TARGET_TYPE.get()).equals(Module.MAP_MARKER.get())) { pathFinding.removeWaypointFromList(); if (pathFinding.isWaypointsToReachEmpty()) { throw new InterruptedException(); @@ -143,13 +143,13 @@ private void setNextPointInPath() throws RPCException, IOException, InterruptedE } private boolean isFarFromTarget() throws RPCException { - double distance = Vector.distance(new Vector(getNaveAtual().position(orbitalReferenceFrame)), targetPoint); + double distance = Vector.distance(new Vector(getActiveVessel().position(orbitalReferenceFrame)), targetPoint); return distance > distanceFromTargetLimit; } private boolean needToChargeBatteries() throws RPCException, IOException, StreamException, InterruptedException { - float totalCharge = getNaveAtual().getResources().max("ElectricCharge"); - float currentCharge = getNaveAtual().getResources().amount("ElectricCharge"); + float totalCharge = getActiveVessel().getResources().max("ElectricCharge"); + float currentCharge = getActiveVessel().getResources().amount("ElectricCharge"); float minChargeLevel = 10.0f; float chargePercentage = (float) Math.ceil(currentCharge * 100 / totalCharge); return (chargePercentage < minChargeLevel); @@ -157,18 +157,18 @@ private boolean needToChargeBatteries() throws RPCException, IOException, Stream private void rechargeRover() throws RPCException, StreamException, InterruptedException { - float totalCharge = getNaveAtual().getResources().max("ElectricCharge"); - float currentCharge = getNaveAtual().getResources().amount("ElectricCharge"); + float totalCharge = getActiveVessel().getResources().max("ElectricCharge"); + float currentCharge = getActiveVessel().getResources().amount("ElectricCharge"); setRoverThrottle(0); - getNaveAtual().getControl().setLights(false); - getNaveAtual().getControl().setBrakes(true); + getActiveVessel().getControl().setLights(false); + getActiveVessel().getControl().setBrakes(true); - if (velHorizontal.get() < 1 && getNaveAtual().getControl().getBrakes()) { + if (horizontalVelocity.get() < 1 && getActiveVessel().getControl().getBrakes()) { Thread.sleep(1000); double chargeTime; double totalEnergyFlow = 0; - List solarPanels = getNaveAtual().getParts() + List solarPanels = getActiveVessel().getParts() .getSolarPanels() .stream() .filter(this::isSolarPanelNotBroken) @@ -183,14 +183,14 @@ private void rechargeRover() throws RPCException, StreamException, InterruptedEx chargeTime = 3600; } getSpaceCenter().warpTo((getSpaceCenter().getUT() + chargeTime), 10000, 4); - getNaveAtual().getControl().setLights(true); + getActiveVessel().getControl().setLights(true); } } private void driveRover() throws RPCException, IOException, StreamException { Vector targetDirection = posSurfToRover(posOrbToSurf(targetPoint)).normalize(); Vector radarSourcePosition = posRoverToSurf( - new Vector(getNaveAtual().position(roverReferenceFrame)).sum(new Vector(0.0, 3.0, + new Vector(getActiveVessel().position(roverReferenceFrame)).sum(new Vector(0.0, 3.0, 0.0))); double roverAngle = (roverDirection.heading()); @@ -201,12 +201,12 @@ private void driveRover() throws RPCException, IOException, StreamException { // usar esse valor pra muiltiplicar a direcao alvo double targetAndRadarAngle = (targetDirection.multiply(steeringPower) .sum(directionFromRadar( - getNaveAtual().boundingBox(roverReferenceFrame))) + getActiveVessel().boundingBox(roverReferenceFrame))) .normalize()).heading(); double deltaAngle = Math.abs(targetAndRadarAngle - roverAngle); - getNaveAtual().getControl().setSAS(deltaAngle < 1); + getActiveVessel().getControl().setSAS(deltaAngle < 1); // Control Rover Throttle - setRoverThrottle(acelCtrl.calculate(velHorizontal.get() / maxSpeed * 50, 50)); + setRoverThrottle(acelCtrl.calculate(horizontalVelocity.get() / maxSpeed * 50, 50)); // Control Rover Steering if (deltaAngle > 1) { setRoverSteering(sterringCtrl.calculate(roverAngle / (targetAndRadarAngle) * 100, 100)); @@ -226,47 +226,47 @@ private Vector directionFromRadar( Vector RFD = new Vector(boundingBox.getValue1()); // Pre-calculated bbox positions - Vector lateralEsq = new Vector(LBU.x, LBU.y * 0.5 + RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); - Vector latFrontEsq = new Vector(LBU.x, RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); - Vector frontalEsq = new Vector(LBU.x, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); - Vector frontalEsq2 = new Vector(LBU.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); - Vector frontal = new Vector(LBU.x * 0.5 + RFD.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); - Vector frontalDir2 = new Vector(RFD.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); - Vector frontalDir = new Vector(RFD.x, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); - Vector latFrontDir = new Vector(RFD.x, RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); - Vector lateralDir = new Vector(RFD.x, LBU.y * 0.5 + RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); + Vector lateralLeft = new Vector(LBU.x, LBU.y * 0.5 + RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); + Vector latFrontLeft = new Vector(LBU.x, RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); + Vector frontLeft = new Vector(LBU.x, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); + Vector frontLeft2 = new Vector(LBU.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); + Vector front = new Vector(LBU.x * 0.5 + RFD.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); + Vector frontRight2 = new Vector(RFD.x * 0.5, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); + Vector frontRight = new Vector(RFD.x, RFD.y, LBU.z * 0.5 + RFD.z * 0.5); + Vector latFrontRight = new Vector(RFD.x, RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); + Vector lateralRight = new Vector(RFD.x, LBU.y * 0.5 + RFD.y * 0.5, LBU.z * 0.5 + RFD.z * 0.5); // Pre-calculated bbox directions - Vector lateralEsqAngulo = new Vector(-Math.sin(Math.toRadians(90)), Math.cos(Math.toRadians(90)), 0.0); - Vector latFrontEsqAngulo = new Vector(-Math.sin(Math.toRadians(67.5)), Math.cos(Math.toRadians(67.5)), 0.0); - Vector frontalEsqAngulo = new Vector(-Math.sin(Math.toRadians(45)), Math.cos(Math.toRadians(45)), 0.0); - Vector frontalEsqAngulo2 = new Vector(-Math.sin(Math.toRadians(22.5)), Math.cos(Math.toRadians(22.5)), 0.0); - Vector frontalAngulo = new Vector(0.0, 1.0, 0.0); - Vector frontalDirAngulo2 = new Vector(Math.sin(Math.toRadians(22.5)), Math.cos(Math.toRadians(22.5)), 0.0); - Vector frontalDirAngulo = new Vector(Math.sin(Math.toRadians(45)), Math.cos(Math.toRadians(45)), 0.0); - Vector latFrontDirAngulo = new Vector(Math.sin(Math.toRadians(67.5)), Math.cos(Math.toRadians(67.5)), 0.0); - Vector lateralDirAngulo = new Vector(Math.sin(Math.toRadians(90)), Math.cos(Math.toRadians(90)), 0.0); + Vector lateralLeftAngle = new Vector(-Math.sin(Math.toRadians(90)), Math.cos(Math.toRadians(90)), 0.0); + Vector latFrontLeftAngle = new Vector(-Math.sin(Math.toRadians(67.5)), Math.cos(Math.toRadians(67.5)), 0.0); + Vector frontLeftAngle = new Vector(-Math.sin(Math.toRadians(45)), Math.cos(Math.toRadians(45)), 0.0); + Vector frontLeftAngle2 = new Vector(-Math.sin(Math.toRadians(22.5)), Math.cos(Math.toRadians(22.5)), 0.0); + Vector frontAngle = new Vector(0.0, 1.0, 0.0); + Vector frontRightAngle2 = new Vector(Math.sin(Math.toRadians(22.5)), Math.cos(Math.toRadians(22.5)), 0.0); + Vector frontRightAngle = new Vector(Math.sin(Math.toRadians(45)), Math.cos(Math.toRadians(45)), 0.0); + Vector latFrontRightAngle = new Vector(Math.sin(Math.toRadians(67.5)), Math.cos(Math.toRadians(67.5)), 0.0); + Vector lateralRightAngle = new Vector(Math.sin(Math.toRadians(90)), Math.cos(Math.toRadians(90)), 0.0); // Raytracing distance from points: - Vector lateralEsqRay = calculateRaycastDirection(lateralEsq, lateralEsqAngulo, 15); - Vector latFrontEsqRay = calculateRaycastDirection(latFrontEsq, latFrontEsqAngulo, 19); - Vector frontalEsqRay = calculateRaycastDirection(frontalEsq, frontalEsqAngulo, 23); - Vector frontalEsqRay2 = calculateRaycastDirection(frontalEsq2, frontalEsqAngulo2, 27); - Vector frontalRay = calculateRaycastDirection(frontal, frontalAngulo, 35); - Vector frontalDirRay2 = calculateRaycastDirection(frontalDir2, frontalDirAngulo2, 27); - Vector frontalDirRay = calculateRaycastDirection(frontalDir, frontalDirAngulo, 23); - Vector latFrontDirRay = calculateRaycastDirection(latFrontDir, latFrontDirAngulo, 19); - Vector lateralDirRay = calculateRaycastDirection(lateralDir, lateralDirAngulo, 15); - - Vector calculatedDirection = new Vector().sum(lateralEsqRay) - .sum(latFrontEsqRay) - .sum(frontalEsqRay) - .sum(frontalEsqRay2) - .sum(frontalRay) - .sum(frontalDirRay2) - .sum(frontalDirRay) - .sum(latFrontDirRay) - .sum(lateralDirRay); + Vector lateralLeftRay = calculateRaycastDirection(lateralLeft, lateralLeftAngle, 15); + Vector lateralFrontLeftRay = calculateRaycastDirection(latFrontLeft, latFrontLeftAngle, 19); + Vector frontLeftRay = calculateRaycastDirection(frontLeft, frontLeftAngle, 23); + Vector frontLeftRay2 = calculateRaycastDirection(frontLeft2, frontLeftAngle2, 27); + Vector frontRay = calculateRaycastDirection(front, frontAngle, 35); + Vector frontRightRay2 = calculateRaycastDirection(frontRight2, frontRightAngle2, 27); + Vector frontRightRay = calculateRaycastDirection(frontRight, frontRightAngle, 23); + Vector lateralFrontRightRay = calculateRaycastDirection(latFrontRight, latFrontRightAngle, 19); + Vector lateralRightRay = calculateRaycastDirection(lateralRight, lateralRightAngle, 15); + + Vector calculatedDirection = new Vector().sum(lateralLeftRay) + .sum(lateralFrontLeftRay) + .sum(frontLeftRay) + .sum(frontLeftRay2) + .sum(frontRay) + .sum(frontRightRay2) + .sum(frontRightRay) + .sum(lateralFrontRightRay) + .sum(lateralRightRay); return (calculatedDirection.normalize()); } @@ -299,16 +299,16 @@ private Vector posOrbToSurf(Vector vector) throws RPCException { } private void setRoverThrottle(double throttle) throws RPCException, StreamException { - if (velHorizontal.get() < (maxSpeed * 1.01)) { - getNaveAtual().getControl().setBrakes(false); - getNaveAtual().getControl().setWheelThrottle((float) throttle); + if (horizontalVelocity.get() < (maxSpeed * 1.01)) { + getActiveVessel().getControl().setBrakes(false); + getActiveVessel().getControl().setWheelThrottle((float) throttle); } else { - getNaveAtual().getControl().setBrakes(true); + getActiveVessel().getControl().setBrakes(true); } } private void setRoverSteering(double steering) throws RPCException { - getNaveAtual().getControl().setWheelSteering((float) steering); + getActiveVessel().getControl().setWheelSteering((float) steering); } private enum MODE { diff --git a/src/main/java/com/pesterenan/model/ActiveVessel.java b/src/main/java/com/pesterenan/model/ActiveVessel.java index 99efa65..cad2016 100644 --- a/src/main/java/com/pesterenan/model/ActiveVessel.java +++ b/src/main/java/com/pesterenan/model/ActiveVessel.java @@ -8,7 +8,7 @@ import com.pesterenan.controllers.RoverController; import com.pesterenan.controllers.DockingController; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Telemetry; import com.pesterenan.utils.Vector; import krpc.client.RPCException; @@ -29,23 +29,23 @@ public class ActiveVessel { - protected Vessel naveAtual; + protected Vessel activeVessel; private final Map telemetryData = new HashMap<>(); public AutoPilot ap; - public Flight parametrosDeVoo; + public Flight flightParameters; public ReferenceFrame orbitalReferenceFrame; - protected Stream massaTotal; + protected Stream totalMass; public ReferenceFrame surfaceReferenceFrame; - public float bateriaTotal; + public float totalCharge; public float gravityAcel; public CelestialBody currentBody; public Stream altitude; - public Stream altitudeSup; - public Stream apoastro; - public Stream periastro; - public Stream velVertical; - public Stream tempoMissao; - public Stream velHorizontal; + public Stream surfaceAltitude; + public Stream apoapsis; + public Stream periapsis; + public Stream verticalVelocity; + public Stream missionTime; + public Stream horizontalVelocity; public Map commands; protected int currentVesselId = 0; protected Thread controllerThread = null; @@ -60,21 +60,21 @@ public ActiveVessel() { private void initializeParameters() { try { - setNaveAtual(getSpaceCenter().getActiveVessel()); - currentVesselId = getNaveAtual().hashCode(); - ap = getNaveAtual().getAutoPilot(); - currentBody = getNaveAtual().getOrbit().getBody(); + setActiveVessel(getSpaceCenter().getActiveVessel()); + currentVesselId = getActiveVessel().hashCode(); + ap = getActiveVessel().getAutoPilot(); + currentBody = getActiveVessel().getOrbit().getBody(); gravityAcel = currentBody.getSurfaceGravity(); orbitalReferenceFrame = currentBody.getReferenceFrame(); - surfaceReferenceFrame = getNaveAtual().getSurfaceReferenceFrame(); - parametrosDeVoo = getNaveAtual().flight(orbitalReferenceFrame); - massaTotal = getConnection().addStream(getNaveAtual(), "getMass"); - altitude = getConnection().addStream(parametrosDeVoo, "getMeanAltitude"); - altitudeSup = getConnection().addStream(parametrosDeVoo, "getSurfaceAltitude"); - apoastro = getConnection().addStream(getNaveAtual().getOrbit(), "getApoapsisAltitude"); - periastro = getConnection().addStream(getNaveAtual().getOrbit(), "getPeriapsisAltitude"); - velVertical = getConnection().addStream(parametrosDeVoo, "getVerticalSpeed"); - velHorizontal = getConnection().addStream(parametrosDeVoo, "getHorizontalSpeed"); + surfaceReferenceFrame = getActiveVessel().getSurfaceReferenceFrame(); + flightParameters = getActiveVessel().flight(orbitalReferenceFrame); + totalMass = getConnection().addStream(getActiveVessel(), "getMass"); + altitude = getConnection().addStream(flightParameters, "getMeanAltitude"); + surfaceAltitude = getConnection().addStream(flightParameters, "getSurfaceAltitude"); + apoapsis = getConnection().addStream(getActiveVessel().getOrbit(), "getApoapsisAltitude"); + periapsis = getConnection().addStream(getActiveVessel().getOrbit(), "getPeriapsisAltitude"); + verticalVelocity = getConnection().addStream(flightParameters, "getVerticalSpeed"); + horizontalVelocity = getConnection().addStream(flightParameters, "getHorizontalSpeed"); } catch (RPCException | StreamException e) { MechPeste.newInstance().checkConnection(); } @@ -95,16 +95,16 @@ public int getCurrentVesselId() { return currentVesselId; } - public Vessel getNaveAtual() { - return naveAtual; + public Vessel getActiveVessel() { + return activeVessel; } - public void setNaveAtual(Vessel currentVessel) { - naveAtual = currentVessel; + public void setActiveVessel(Vessel currentVessel) { + activeVessel = currentVessel; } public void throttle(float acel) throws RPCException { - getNaveAtual().getControl().setThrottle(Math.min(acel, 1.0f)); + getActiveVessel().getControl().setThrottle(Math.min(acel, 1.0f)); } public void throttle(double acel) throws RPCException { @@ -118,9 +118,9 @@ public void tuneAutoPilot() throws RPCException { public void liftoff() { try { - getNaveAtual().getControl().setSAS(true); + getActiveVessel().getControl().setSAS(true); throttleUp(getMaxThrottleForTWR(2.0), 1); - if (getNaveAtual().getSituation().equals(VesselSituation.PRE_LAUNCH)) { + if (getActiveVessel().getSituation().equals(VesselSituation.PRE_LAUNCH)) { for (double count = 5.0; count >= 0; count -= 0.1) { if (Thread.interrupted()) { throw new InterruptedException(); @@ -128,8 +128,8 @@ public void liftoff() { setCurrentStatus(String.format(Bundle.getString("status_launching_in"), count)); Thread.sleep(100); } - getSpaceCenter().setActiveVessel(naveAtual); - getNaveAtual().getControl().activateNextStage(); + getSpaceCenter().setActiveVessel(activeVessel); + getActiveVessel().getControl().activateNextStage(); } setCurrentStatus(Bundle.getString("status_liftoff")); } catch (RPCException | InterruptedException | StreamException ignored) { @@ -139,11 +139,11 @@ public void liftoff() { protected void decoupleStage() throws RPCException, InterruptedException { setCurrentStatus(Bundle.getString("status_separating_stage")); - MechPeste.getSpaceCenter().setActiveVessel(getNaveAtual()); - double currentThrottle = getNaveAtual().getControl().getThrottle(); + MechPeste.getSpaceCenter().setActiveVessel(getActiveVessel()); + double currentThrottle = getActiveVessel().getControl().getThrottle(); throttle(0); Thread.sleep(1000); - getNaveAtual().getControl().activateNextStage(); + getActiveVessel().getControl().activateNextStage(); throttleUp(currentThrottle, 1); } @@ -157,7 +157,7 @@ protected void throttleUp(double throttleAmount, double seconds) throws RPCExcep } public double getTWR() throws RPCException, StreamException { - return getNaveAtual().getAvailableThrust() / (massaTotal.get() * gravityAcel); + return getActiveVessel().getAvailableThrust() / (totalMass.get() * gravityAcel); } public double getMaxThrottleForTWR(double targetTWR) throws RPCException, StreamException { @@ -169,29 +169,29 @@ public double getMaxAcel(float maxTWR) throws RPCException, StreamException { } public void startModule(Map commands) { - String currentFunction = commands.get(Modulos.MODULO.get()); + String currentFunction = commands.get(Module.MODULO.get()); if (controllerThread != null) { controllerThread.interrupt(); runningModule = false; } - if (currentFunction.equals(Modulos.MODULO_DECOLAGEM.get())) { + if (currentFunction.equals(Module.LIFTOFF.get())) { controller = new LiftoffController(commands); runningModule = true; } - if (currentFunction.equals(Modulos.MODULO_POUSO_SOBREVOAR.get()) || - currentFunction.equals(Modulos.MODULO_POUSO.get())) { + if (currentFunction.equals(Module.HOVERING.get()) || + currentFunction.equals(Module.LANDING.get())) { controller = new LandingController(commands); runningModule = true; } - if (currentFunction.equals(Modulos.MODULE_MANEUVER.get())) { + if (currentFunction.equals(Module.MANEUVER.get())) { controller = new ManeuverController(commands); runningModule = true; } - if (currentFunction.equals(Modulos.MODULO_ROVER.get())) { + if (currentFunction.equals(Module.ROVER.get())) { controller = new RoverController(commands); runningModule = true; } - if (currentFunction.equals(Modulos.MODULO_DOCKING.get())) { + if (currentFunction.equals(Module.DOCKING.get())) { controller = new DockingController(commands); System.out.println("escolheu modulo docking"); runningModule = true; @@ -201,17 +201,17 @@ public void startModule(Map commands) { } public void recordTelemetryData() throws RPCException { - if (getNaveAtual().getOrbit().getBody() != currentBody) { + if (getActiveVessel().getOrbit().getBody() != currentBody) { initializeParameters(); } synchronized (telemetryData) { try { telemetryData.put(Telemetry.ALTITUDE, altitude.get() < 0 ? 0 : altitude.get()); - telemetryData.put(Telemetry.ALT_SURF, altitudeSup.get() < 0 ? 0 : altitudeSup.get()); - telemetryData.put(Telemetry.APOAPSIS, apoastro.get() < 0 ? 0 : apoastro.get()); - telemetryData.put(Telemetry.PERIAPSIS, periastro.get() < 0 ? 0 : periastro.get()); - telemetryData.put(Telemetry.VERT_SPEED, velVertical.get()); - telemetryData.put(Telemetry.HORZ_SPEED, velHorizontal.get() < 0 ? 0 : velHorizontal.get()); + telemetryData.put(Telemetry.ALT_SURF, surfaceAltitude.get() < 0 ? 0 : surfaceAltitude.get()); + telemetryData.put(Telemetry.APOAPSIS, apoapsis.get() < 0 ? 0 : apoapsis.get()); + telemetryData.put(Telemetry.PERIAPSIS, periapsis.get() < 0 ? 0 : periapsis.get()); + telemetryData.put(Telemetry.VERT_SPEED, verticalVelocity.get()); + telemetryData.put(Telemetry.HORZ_SPEED, horizontalVelocity.get() < 0 ? 0 : horizontalVelocity.get()); } catch (RPCException | StreamException ignored) { } } diff --git a/src/main/java/com/pesterenan/utils/Module.java b/src/main/java/com/pesterenan/utils/Module.java new file mode 100644 index 0000000..5efd173 --- /dev/null +++ b/src/main/java/com/pesterenan/utils/Module.java @@ -0,0 +1,52 @@ +package com.pesterenan.utils; + +public enum Module { + + ADJUST("Ajustar"), + APOAPSIS("Apoastro"), + CIRCULAR("Circular"), + CREATE_MANEUVER("CRIAR_MANOBRAS"), + CUBIC("Cúbica"), + DIRECTION("Direção"), + DOCKING("DOCKING"), + EXECUTE("Executar"), + EXPONENCIAL("Exponencial"), + FINE_ADJUST("Ajuste Fino"), + FUNCTION("Função"), + HOVERING("HOVER"), + HOVER_AFTER_LANDING("SOBREVOO PÓS POUSO"), + HOVER_ALTITUDE("Altitude Sobrevoo"), + INCLINATION("Inclinação"), + LAND("Pousar nave"), + LANDING("LANDING"), + LIFTOFF("LIFTOFF"), + LOW_ORBIT("ÓRBITA BAIXA"), + MANEUVER("MANEUVER"), + MAP_MARKER("Marcador no mapa"), + MARKER_NAME("Nome do marcador"), + MAX_SPEED("Velocidade Máxima"), + MAX_TWR("Max_TWR"), + MODULO("Módulo"), + OPEN_PANELS("Abrir Painéis"), + PERIAPSIS("Periastro"), + QUADRATIC("Quadrática"), + RENDEZVOUS("Rendezvous"), + ROLL("Rolagem"), + ROVER("ROVER"), + ROVER_TARGET_TYPE("Tipo de Alvo do Rover"), + SAFE_DISTANCE("Distância Segura"), + SINUSOIDAL("Sinusoidal"), + STAGE("Usar Estágios"), + TARGET_VESSEL("Nave alvo"), + TELEMETRY("TELEMETRY"); + + final String t; + + Module(String t) { + this.t = t; + } + + public String get() { + return this.t; + } +} diff --git a/src/main/java/com/pesterenan/utils/Modulos.java b/src/main/java/com/pesterenan/utils/Modulos.java deleted file mode 100644 index d583171..0000000 --- a/src/main/java/com/pesterenan/utils/Modulos.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.pesterenan.utils; - -public enum Modulos { - - ABRIR_PAINEIS("Abrir Painéis"), - AJUSTAR("Ajustar"), - AJUSTE_FINO("Ajuste Fino"), - ALTITUDE_SOBREVOO("Altitude Sobrevoo"), - APOASTRO("Apoastro"), - CIRCULAR("Circular"), - CUBICA("Cúbica"), - DIRECAO("Direção"), - DISTANCIA_SEGURA("Distância Segura"), - EXECUTAR("Executar"), - EXPONENCIAL("Exponencial"), - FUNCAO("Função"), - INCLINACAO("Inclinação"), - MARCADOR_MAPA("Marcador no mapa"), - MAX_TWR("Max_TWR"), - MODULE_MANEUVER("MANEUVER"), - MODULO("Módulo"), - MODULO_CRIAR_MANOBRAS("CRIAR_MANOBRAS"), - MODULO_DECOLAGEM("LIFTOFF"), - MODULO_DOCKING("DOCKING"), - MODULO_POUSO("LANDING"), - MODULO_POUSO_SOBREVOAR("HOVER"), - MODULO_ROVER("ROVER"), - MODULO_TELEMETRIA("TELEMETRY"), - NAVE_ALVO("Nave alvo"), - NOME_MARCADOR("Nome do marcador"), - ORBITA_BAIXA("ÓRBITA BAIXA"), - PERIASTRO("Periastro"), - POUSAR("Pousar nave"), - QUADRATICA("Quadrática"), - RENDEZVOUS("Rendezvous"), - ROLAGEM("Rolagem"), - SINUSOIDAL("Sinusoidal"), - SOBREVOO_POS_POUSO("SOBREVOO PÓS POUSO"), - TIPO_ALVO_ROVER("Tipo de Alvo do Rover"), - USAR_ESTAGIOS("Usar Estágios"), - VELOCIDADE_MAX("Velocidade Máxima"); - - final String t; - - Modulos(String t) { - this.t = t; - } - - public String get() { - return this.t; - } -} diff --git a/src/main/java/com/pesterenan/utils/PathFinding.java b/src/main/java/com/pesterenan/utils/PathFinding.java index f5848e0..a762926 100644 --- a/src/main/java/com/pesterenan/utils/PathFinding.java +++ b/src/main/java/com/pesterenan/utils/PathFinding.java @@ -62,9 +62,9 @@ public Vector findNearestWaypoint() throws RPCException, IOException, Interrupte double w1Distance = 0; double w2Distance = 0; try { - w1Distance = Vector.distance(new Vector(getNaveAtual().position(orbitalReferenceFrame)), + w1Distance = Vector.distance(new Vector(getActiveVessel().position(orbitalReferenceFrame)), waypointPosOnSurface(w1)); - w2Distance = Vector.distance(new Vector(getNaveAtual().position(orbitalReferenceFrame)), + w2Distance = Vector.distance(new Vector(getActiveVessel().position(orbitalReferenceFrame)), waypointPosOnSurface(w2)); } catch (RPCException e) { } @@ -137,7 +137,7 @@ public void buildPathToTarget(Vector targetPosition) throws IOException, RPCExce // centimeters on height: Vector roverHeight = new Vector(0.2, 0.0, 0.0); Vector currentRoverPos = transformSurfToOrb( - new Vector(getNaveAtual().position(surfaceReferenceFrame)).sum(roverHeight)); + new Vector(getActiveVessel().position(surfaceReferenceFrame)).sum(roverHeight)); // Calculate distance from rover to target on Orbital Ref: double distanceToTarget = Vector.distance(currentRoverPos, targetPosition); // Add rover pos as first point, on Orbital Ref diff --git a/src/main/java/com/pesterenan/views/DockingJPanel.java b/src/main/java/com/pesterenan/views/DockingJPanel.java index 84fa835..d1f2689 100644 --- a/src/main/java/com/pesterenan/views/DockingJPanel.java +++ b/src/main/java/com/pesterenan/views/DockingJPanel.java @@ -2,7 +2,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -127,9 +127,9 @@ public static void setDockingStep(String step) { private void handleStartDocking(ActionEvent e) { if (validateTextFields()) { Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), Modulos.MODULO_DOCKING.get()); - commands.put(Modulos.DISTANCIA_SEGURA.get(), txfSafeDistance.getText()); - commands.put(Modulos.VELOCIDADE_MAX.get(), txfMaxSpeed.getText()); + commands.put(Module.MODULO.get(), Module.DOCKING.get()); + commands.put(Module.SAFE_DISTANCE.get(), txfSafeDistance.getText()); + commands.put(Module.MAX_SPEED.get(), txfMaxSpeed.getText()); MechPeste.newInstance().startModule(commands); } } diff --git a/src/main/java/com/pesterenan/views/FunctionsAndTelemetryJPanel.java b/src/main/java/com/pesterenan/views/FunctionsAndTelemetryJPanel.java index 5a6dc03..467d34b 100644 --- a/src/main/java/com/pesterenan/views/FunctionsAndTelemetryJPanel.java +++ b/src/main/java/com/pesterenan/views/FunctionsAndTelemetryJPanel.java @@ -2,7 +2,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import com.pesterenan.utils.Telemetry; import com.pesterenan.utils.Utilities; @@ -69,23 +69,23 @@ public void setupComponents() { btnCancel.setMaximumSize(btnFuncDimension); btnCancel.setPreferredSize(btnFuncDimension); btnLanding.addActionListener(this::changeFunctionPanel); - btnLanding.setActionCommand(Modulos.MODULO_POUSO.get()); + btnLanding.setActionCommand(Module.LANDING.get()); btnLanding.setMaximumSize(btnFuncDimension); btnLanding.setPreferredSize(btnFuncDimension); btnLiftoff.addActionListener(this::changeFunctionPanel); - btnLiftoff.setActionCommand(Modulos.MODULO_DECOLAGEM.get()); + btnLiftoff.setActionCommand(Module.LIFTOFF.get()); btnLiftoff.setMaximumSize(btnFuncDimension); btnLiftoff.setPreferredSize(btnFuncDimension); btnManeuvers.addActionListener(this::changeFunctionPanel); - btnManeuvers.setActionCommand(Modulos.MODULE_MANEUVER.get()); + btnManeuvers.setActionCommand(Module.MANEUVER.get()); btnManeuvers.setMaximumSize(btnFuncDimension); btnManeuvers.setPreferredSize(btnFuncDimension); btnRover.addActionListener(this::changeFunctionPanel); - btnRover.setActionCommand(Modulos.MODULO_ROVER.get()); + btnRover.setActionCommand(Module.ROVER.get()); btnRover.setMaximumSize(btnFuncDimension); btnRover.setPreferredSize(btnFuncDimension); btnDocking.addActionListener(this::changeFunctionPanel); - btnDocking.setActionCommand(Modulos.MODULO_DOCKING.get()); + btnDocking.setActionCommand(Module.DOCKING.get()); btnDocking.setMaximumSize(btnFuncDimension); btnDocking.setPreferredSize(btnFuncDimension); } diff --git a/src/main/java/com/pesterenan/views/LandingJPanel.java b/src/main/java/com/pesterenan/views/LandingJPanel.java index ce315b1..f63b890 100644 --- a/src/main/java/com/pesterenan/views/LandingJPanel.java +++ b/src/main/java/com/pesterenan/views/LandingJPanel.java @@ -2,7 +2,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import javax.swing.*; import javax.swing.border.Border; @@ -64,11 +64,11 @@ public void setupComponents() { txfMaxTWR.setHorizontalAlignment(JTextField.RIGHT); btnAutoLanding.addActionListener(this::handleLandingAction); - btnAutoLanding.setActionCommand(Modulos.MODULO_POUSO.get()); + btnAutoLanding.setActionCommand(Module.LANDING.get()); btnAutoLanding.setPreferredSize(BTN_DIMENSION); btnAutoLanding.setMaximumSize(BTN_DIMENSION); btnHover.addActionListener(this::handleLandingAction); - btnHover.setActionCommand(Modulos.MODULO_POUSO_SOBREVOAR.get()); + btnHover.setActionCommand(Module.HOVERING.get()); btnHover.setPreferredSize(BTN_DIMENSION); btnHover.setMaximumSize(BTN_DIMENSION); btnBack.addActionListener(MainGui::backToTelemetry); @@ -142,11 +142,11 @@ public void layoutComponents() { private void handleLandingAction(ActionEvent e) { try { Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), e.getActionCommand()); + commands.put(Module.MODULO.get(), e.getActionCommand()); validateTextFields(); - commands.put(Modulos.ALTITUDE_SOBREVOO.get(), txfHover.getText()); - commands.put(Modulos.MAX_TWR.get(), txfMaxTWR.getText()); - commands.put(Modulos.SOBREVOO_POS_POUSO.get(), String.valueOf(chkHoverAfterLanding.isSelected())); + commands.put(Module.HOVER_ALTITUDE.get(), txfHover.getText()); + commands.put(Module.MAX_TWR.get(), txfMaxTWR.getText()); + commands.put(Module.HOVER_AFTER_LANDING.get(), String.valueOf(chkHoverAfterLanding.isSelected())); MechPeste.newInstance().startModule(commands); MainGui.backToTelemetry(e); chkHoverAfterLanding.setSelected(false); diff --git a/src/main/java/com/pesterenan/views/LiftoffJPanel.java b/src/main/java/com/pesterenan/views/LiftoffJPanel.java index 7c5e488..2a369cd 100644 --- a/src/main/java/com/pesterenan/views/LiftoffJPanel.java +++ b/src/main/java/com/pesterenan/views/LiftoffJPanel.java @@ -2,7 +2,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -86,8 +86,8 @@ public void setupComponents() { txfLimitTWR.setHorizontalAlignment(JTextField.RIGHT); cbGravityCurveModel.setModel(new DefaultComboBoxModel<>( - new String[] { Modulos.SINUSOIDAL.get(), Modulos.QUADRATICA.get(), Modulos.CUBICA.get(), - Modulos.CIRCULAR.get(), Modulos.EXPONENCIAL.get() })); + new String[] { Module.SINUSOIDAL.get(), Module.QUADRATIC.get(), Module.CUBIC.get(), + Module.CIRCULAR.get(), Module.EXPONENCIAL.get() })); cbGravityCurveModel.setSelectedIndex(3); cbGravityCurveModel.setPreferredSize(BTN_DIMENSION); cbGravityCurveModel.setMaximumSize(BTN_DIMENSION); @@ -200,14 +200,14 @@ private boolean validateTextFields() { private void handleLiftoff(ActionEvent e) { if (validateTextFields()) { Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), Modulos.MODULO_DECOLAGEM.get()); - commands.put(Modulos.APOASTRO.get(), txfFinalApoapsis.getText()); - commands.put(Modulos.DIRECAO.get(), txfHeading.getText()); - commands.put(Modulos.MAX_TWR.get(), txfLimitTWR.getText()); - commands.put(Modulos.ROLAGEM.get(), String.valueOf(sldRoll.getValue())); - commands.put(Modulos.INCLINACAO.get(), cbGravityCurveModel.getSelectedItem().toString()); - commands.put(Modulos.USAR_ESTAGIOS.get(), String.valueOf(chkDecoupleStages.isSelected())); - commands.put(Modulos.ABRIR_PAINEIS.get(), String.valueOf(chkOpenPanels.isSelected())); + commands.put(Module.MODULO.get(), Module.LIFTOFF.get()); + commands.put(Module.APOAPSIS.get(), txfFinalApoapsis.getText()); + commands.put(Module.DIRECTION.get(), txfHeading.getText()); + commands.put(Module.MAX_TWR.get(), txfLimitTWR.getText()); + commands.put(Module.ROLL.get(), String.valueOf(sldRoll.getValue())); + commands.put(Module.INCLINATION.get(), cbGravityCurveModel.getSelectedItem().toString()); + commands.put(Module.STAGE.get(), String.valueOf(chkDecoupleStages.isSelected())); + commands.put(Module.OPEN_PANELS.get(), String.valueOf(chkOpenPanels.isSelected())); MechPeste.newInstance().startModule(commands); MainGui.backToTelemetry(e); } diff --git a/src/main/java/com/pesterenan/views/MainGui.java b/src/main/java/com/pesterenan/views/MainGui.java index f824d7f..5678bc6 100644 --- a/src/main/java/com/pesterenan/views/MainGui.java +++ b/src/main/java/com/pesterenan/views/MainGui.java @@ -1,7 +1,7 @@ package com.pesterenan.views; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -127,12 +127,12 @@ public void layoutComponents() { pnlManeuverJTabbedPane.addTab("Executar Manobras", pnlRunManeuvers); cardJPanels.setLayout(cardLayout); - cardJPanels.add(pnlFunctionsAndTelemetry, Modulos.MODULO_TELEMETRIA.get()); - cardJPanels.add(pnlLiftoff, Modulos.MODULO_DECOLAGEM.get()); - cardJPanels.add(pnlLanding, Modulos.MODULO_POUSO.get()); - cardJPanels.add(pnlManeuverJTabbedPane, Modulos.MODULE_MANEUVER.get()); - cardJPanels.add(pnlRover, Modulos.MODULO_ROVER.get()); - cardJPanels.add(pnlDocking, Modulos.MODULO_DOCKING.get()); + cardJPanels.add(pnlFunctionsAndTelemetry, Module.TELEMETRY.get()); + cardJPanels.add(pnlLiftoff, Module.LIFTOFF.get()); + cardJPanels.add(pnlLanding, Module.LANDING.get()); + cardJPanels.add(pnlManeuverJTabbedPane, Module.MANEUVER.get()); + cardJPanels.add(pnlRover, Module.ROVER.get()); + cardJPanels.add(pnlDocking, Module.DOCKING.get()); } public void actionPerformed(ActionEvent e) { @@ -181,7 +181,7 @@ public static void changeToPage(ActionEvent e) { } public static void backToTelemetry(ActionEvent e) { - cardLayout.show(cardJPanels, Modulos.MODULO_TELEMETRIA.get()); + cardLayout.show(cardJPanels, Module.TELEMETRY.get()); } protected void handleMntmAboutActionPerformed(ActionEvent e) { diff --git a/src/main/java/com/pesterenan/views/RoverJPanel.java b/src/main/java/com/pesterenan/views/RoverJPanel.java index 8590f82..ae1972c 100644 --- a/src/main/java/com/pesterenan/views/RoverJPanel.java +++ b/src/main/java/com/pesterenan/views/RoverJPanel.java @@ -2,7 +2,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import javax.swing.*; import javax.swing.border.EtchedBorder; @@ -66,9 +66,9 @@ public void setupComponents() { txfMaxSpeed.setPreferredSize(BTN_DIMENSION); rbTargetVessel.setSelected(true); - rbTargetVessel.setActionCommand(Modulos.NAVE_ALVO.get()); + rbTargetVessel.setActionCommand(Module.TARGET_VESSEL.get()); rbTargetVessel.addActionListener(this::handleTargetSelection); - rbWaypointOnMap.setActionCommand(Modulos.MARCADOR_MAPA.get()); + rbWaypointOnMap.setActionCommand(Module.MAP_MARKER.get()); rbWaypointOnMap.addActionListener(this::handleTargetSelection); bgTargetChoice = new ButtonGroup(); @@ -144,10 +144,10 @@ private void handleTargetSelection(ActionEvent e) { private void handleDriveTo(ActionEvent e) { if (validateTextFields()) { Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), Modulos.MODULO_ROVER.get()); - commands.put(Modulos.TIPO_ALVO_ROVER.get(), bgTargetChoice.getSelection().getActionCommand()); - commands.put(Modulos.NOME_MARCADOR.get(), txfWaypointName.getText()); - commands.put(Modulos.VELOCIDADE_MAX.get(), txfMaxSpeed.getText()); + commands.put(Module.MODULO.get(), Module.ROVER.get()); + commands.put(Module.ROVER_TARGET_TYPE.get(), bgTargetChoice.getSelection().getActionCommand()); + commands.put(Module.MARKER_NAME.get(), txfWaypointName.getText()); + commands.put(Module.MAX_SPEED.get(), txfMaxSpeed.getText()); MechPeste.newInstance().startModule(commands); } } diff --git a/src/main/java/com/pesterenan/views/RunManeuverJPanel.java b/src/main/java/com/pesterenan/views/RunManeuverJPanel.java index 037ecd8..4dd69d4 100644 --- a/src/main/java/com/pesterenan/views/RunManeuverJPanel.java +++ b/src/main/java/com/pesterenan/views/RunManeuverJPanel.java @@ -3,7 +3,7 @@ import com.pesterenan.MechPeste; import com.pesterenan.resources.Bundle; import com.pesterenan.utils.ControlePID; -import com.pesterenan.utils.Modulos; +import com.pesterenan.utils.Module; import krpc.client.RPCException; import krpc.client.services.SpaceCenter.Node; @@ -208,22 +208,22 @@ public void layoutComponents() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == btnExecute) { - handleManeuverFunction(Modulos.EXECUTAR.get()); + handleManeuverFunction(Module.EXECUTE.get()); } if (e.getSource() == btnLowerOrbit) { - handleManeuverFunction(Modulos.ORBITA_BAIXA.get()); + handleManeuverFunction(Module.LOW_ORBIT.get()); } if (e.getSource() == btnApoapsis) { - handleManeuverFunction(Modulos.APOASTRO.get()); + handleManeuverFunction(Module.APOAPSIS.get()); } if (e.getSource() == btnPeriapsis) { - handleManeuverFunction(Modulos.PERIASTRO.get()); + handleManeuverFunction(Module.PERIAPSIS.get()); } if (e.getSource() == btnAlignPlanes) { - handleManeuverFunction(Modulos.AJUSTAR.get()); + handleManeuverFunction(Module.ADJUST.get()); } if (e.getSource() == btnRendezvous) { - handleManeuverFunction(Modulos.RENDEZVOUS.get()); + handleManeuverFunction(Module.RENDEZVOUS.get()); } if (e.getSource() == btnBack) { MainGui.backToTelemetry(e); @@ -232,9 +232,9 @@ public void actionPerformed(ActionEvent e) { protected void handleManeuverFunction(String maneuverFunction) { Map commands = new HashMap<>(); - commands.put(Modulos.MODULO.get(), Modulos.MODULE_MANEUVER.get()); - commands.put(Modulos.FUNCAO.get(), maneuverFunction.toString()); - commands.put(Modulos.AJUSTE_FINO.get(), String.valueOf(chkFineAdjusment.isSelected())); + commands.put(Module.MODULO.get(), Module.MANEUVER.get()); + commands.put(Module.FUNCTION.get(), maneuverFunction.toString()); + commands.put(Module.FINE_ADJUST.get(), String.valueOf(chkFineAdjusment.isSelected())); MechPeste.newInstance().startModule(commands); } }