Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/com/pesterenan/MechPeste.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static ListModel<String> 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) {
}
});
Expand Down Expand Up @@ -91,13 +91,13 @@ public static ListModel<String> 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) {
}
Expand All @@ -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"));
}
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/pesterenan/controllers/DockingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,15 +57,15 @@ public DockingController(Map<String, String> 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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down
68 changes: 34 additions & 34 deletions src/main/java/com/pesterenan/controllers/LandingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,7 +36,7 @@ public class LandingController extends Controller {
public LandingController(Map<String, String> commands) {
super();
this.commands = commands;
this.navigation = new Navigation(getNaveAtual());
this.navigation = new Navigation(getActiveVessel());
this.initializeParameters();
}

Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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();
Expand All @@ -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...");
Expand All @@ -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();
Expand All @@ -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...");
Expand All @@ -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"));
Expand All @@ -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);
}
}
Expand All @@ -246,29 +246,29 @@ 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;
}
return false;
}

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;
}
Expand Down
Loading