Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
193b214
[MP-2]: Created button for Create Maneuvers Panel (#16)
Pesterenan Feb 22, 2023
1b79fe0
[MP-2]: Making liftoff button get back to telemetry jpanel (#17)
Pesterenan Feb 22, 2023
dc4a226
[MP-2]: Incremented patch version for bugfix (#18)
Pesterenan Feb 22, 2023
1962615
[DEV]: Updated KRPC, Protobuf and README
Pesterenan Mar 9, 2023
c8449b1
Merge branch 'dev' of https://www.github.com/Pesterenan/MechPeste-Jav…
Pesterenan Mar 9, 2023
29f47b1
Merge https://github.com/Pesterenan/MechPeste-Java into dev
Pesterenan Apr 7, 2023
7134431
[DEV]: Adding new version of KRPC, safer de-orbiting
Pesterenan Apr 7, 2023
a2ca55a
[MP-2]: Create the UI for maneuver creation helper (#20)
Pesterenan Dec 5, 2023
5708dd6
Docking test (#21)
Pesterenan Dec 5, 2023
0a0664b
[Maven]: Implement Maven project manager (#22)
Pesterenan Dec 5, 2023
3c1bf29
[CI]: Add CI workflow to project using Maven
Pesterenan Dec 7, 2023
aa1f650
[CI]: Add KRPC as a Local Library on GHA
Pesterenan Dec 7, 2023
c1ce611
[CI]: Add release script
Pesterenan Dec 7, 2023
bd28676
[CI]: Update release script
Pesterenan Dec 7, 2023
3cc0f01
[CI]: Install KRPC before build
Pesterenan Dec 7, 2023
b740741
Merge branch 'master' into dev
Pesterenan Dec 7, 2023
9347c5b
[CI]: Release script test
Pesterenan Dec 7, 2023
ed34f50
[CI]: Create tags test
Pesterenan Dec 7, 2023
e4c9e40
[CI]: Set version using ENV variables
Pesterenan Dec 7, 2023
0373932
[Release]: Creating tag before release
Pesterenan Dec 7, 2023
2449ed8
Merge branch 'master' into dev
Pesterenan Dec 7, 2023
a82f174
[CI]: Updated release scripts
Pesterenan Dec 8, 2023
cdaaf27
[CI]: Separate env and tag steps
Pesterenan Dec 8, 2023
12cecc7
[Release]: Adjust tag name
Pesterenan Dec 8, 2023
3b21c8e
[Release]: Release new version when pushing to master
Pesterenan Dec 8, 2023
361c8fd
Merge branch 'master' into dev
Pesterenan Dec 8, 2023
e90d0e7
[MP-3]: Add docking step texts, sort lines on Bundle files (#28)
Pesterenan Feb 15, 2025
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.pesterenan</groupId>
<artifactId>MechPeste</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>

<build>
<plugins>
Expand Down
76 changes: 44 additions & 32 deletions src/main/java/com/pesterenan/controllers/DockingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import java.util.Map;

import com.pesterenan.resources.Bundle;
import com.pesterenan.utils.Modulos;
import com.pesterenan.utils.Utilities;
import com.pesterenan.utils.Vector;
import com.pesterenan.views.DockingJPanel;
import com.pesterenan.views.StatusJPanel;

import krpc.client.RPCException;
Expand All @@ -27,7 +29,6 @@ public class DockingController extends Controller {

private ReferenceFrame orbitalRefVessel;
private ReferenceFrame vesselRefFrame;
private ReferenceFrame orbitalRefBody;
private Line distanceLine;
private Line distLineXAxis;
private Line distLineYAxis;
Expand All @@ -37,8 +38,8 @@ public class DockingController extends Controller {
private Vector positionMyDockingPort;
private Vector positionTargetDockingPort;

private final double DISTANCE_LIMIT = 25.0;
private double SPEED_LIMIT = 3.0;
private double DOCKING_MAX_SPEED = 3.0;
private double SAFE_DISTANCE = 25.0;
private double currentXAxisSpeed = 0.0;
private double currentYAxisSpeed = 0.0;
private double currentZAxisSpeed = 0.0;
Expand All @@ -56,16 +57,17 @@ public DockingController(Map<String, String> commands) {

private void initializeParameters() {
try {
SPEED_LIMIT = Double.parseDouble(commands.get(Modulos.VELOCIDADE_MAX.get()));
DOCKING_MAX_SPEED = Double.parseDouble(commands.get(Modulos.VELOCIDADE_MAX.get()));
SAFE_DISTANCE = Double.parseDouble(commands.get(Modulos.DISTANCIA_SEGURA.get()));
drawing = Drawing.newInstance(getConnection());
targetVessel = getSpaceCenter().getTargetVessel();
control = getNaveAtual().getControl();
vesselRefFrame = getNaveAtual().getReferenceFrame();
orbitalRefVessel = getNaveAtual().getOrbitalReferenceFrame();
orbitalRefBody = getNaveAtual().getOrbit().getBody().getReferenceFrame();

myDockingPort = getNaveAtual().getParts().getDockingPorts().get(0);
targetDockingPort = targetVessel.getParts().getDockingPorts().get(0);
dockingStep = DOCKING_STEPS.STOP_RELATIVE_SPEED;

positionMyDockingPort = new Vector(myDockingPort.position(orbitalRefVessel));
positionTargetDockingPort = new Vector(targetDockingPort.position(orbitalRefVessel));
Expand Down Expand Up @@ -103,12 +105,12 @@ private void getCloserToTarget(Vector targetPosition) throws InterruptedExceptio
lastYTargetPos = targetPosition.y;
lastZTargetPos = targetPosition.z;

while (Math.abs(lastYTargetPos) >= DISTANCE_LIMIT) {
while (Math.abs(lastYTargetPos) >= SAFE_DISTANCE) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
targetPosition = new Vector(targetVessel.position(vesselRefFrame));
controlShipRCS(targetPosition, DISTANCE_LIMIT);
controlShipRCS(targetPosition, SAFE_DISTANCE);
Thread.sleep(sleepTime);
}

Expand All @@ -124,7 +126,7 @@ public void startDocking() {

// PRIMEIRA PARTE DO DOCKING: APROXIMAÇÃO
Vector targetPosition = new Vector(targetVessel.position(vesselRefFrame));
if (targetPosition.magnitude() > DISTANCE_LIMIT) {
if (targetPosition.magnitude() > SAFE_DISTANCE) {
// Apontar para o alvo:
Vector targetDirection = new Vector(getNaveAtual().position(orbitalRefVessel))
.subtract(new Vector(targetVessel.position(orbitalRefVessel))).multiply(-1);
Expand Down Expand Up @@ -159,7 +161,7 @@ public void startDocking() {
Thread.sleep(sleepTime);
}
} catch (RPCException | InterruptedException | IllegalArgumentException e) {
StatusJPanel.setStatusMessage("Docking aborted.");
StatusJPanel.setStatusMessage("Docking interrupted.");
}
}

Expand All @@ -176,22 +178,7 @@ public void startDocking() {
*/

private enum DOCKING_STEPS {
APPROACH, LINE_UP_WITH_TARGET, GO_IN_FRONT_OF_TARGET
}

private DOCKING_STEPS checkDockingStep(Vector targetPosition, double forwardsDistanceLimit) {
double sidewaysDistance = Math.abs(targetPosition.x);
double upwardsDistance = Math.abs(targetPosition.z);
boolean isInFrontOfTarget = Math.signum(targetPosition.y) == 1;
boolean isOnTheBackOfTarget = Math.signum(targetPosition.y) == -1 && targetPosition.y < forwardsDistanceLimit;

if (isOnTheBackOfTarget) {
return DOCKING_STEPS.GO_IN_FRONT_OF_TARGET;
}
if (isInFrontOfTarget && (sidewaysDistance > 5 || upwardsDistance > 5)) {
return DOCKING_STEPS.LINE_UP_WITH_TARGET;
}
return DOCKING_STEPS.APPROACH;
APPROACH, STOP_RELATIVE_SPEED, LINE_UP_WITH_TARGET, GO_IN_FRONT_OF_TARGET
}

private void controlShipRCS(Vector targetPosition, double forwardsDistanceLimit) {
Expand All @@ -205,36 +192,61 @@ private void controlShipRCS(Vector targetPosition, double forwardsDistanceLimit)
currentYAxisSpeed = (targetPosition.y - lastYTargetPos) * sleepTime;
currentZAxisSpeed = (targetPosition.z - lastZTargetPos) * sleepTime;

dockingStep = checkDockingStep(targetPosition, forwardsDistanceLimit);
double sidewaysDistance = Math.abs(targetPosition.x);
double upwardsDistance = Math.abs(targetPosition.z);
boolean isInFrontOfTarget = Math.signum(targetPosition.y) == 1;
boolean isOnTheBackOfTarget = Math.signum(targetPosition.y) == -1 && targetPosition.y < forwardsDistanceLimit;
float forwardsError, upwardsError, sidewaysError = 0;

switch (dockingStep) {
case APPROACH:
// Calcular a aceleração para cada eixo no RCS:
forwardsError = calculateThrottle(forwardsDistanceLimit, forwardsDistanceLimit * 3, currentYAxisSpeed,
targetPosition.y, SPEED_LIMIT);
sidewaysError = calculateThrottle(0, 5, currentXAxisSpeed, targetPosition.x, SPEED_LIMIT);
upwardsError = calculateThrottle(0, 5, currentZAxisSpeed, targetPosition.z, SPEED_LIMIT);
targetPosition.y, DOCKING_MAX_SPEED);
sidewaysError = calculateThrottle(0, 5, currentXAxisSpeed, targetPosition.x, DOCKING_MAX_SPEED);
upwardsError = calculateThrottle(0, 5, currentZAxisSpeed, targetPosition.z, DOCKING_MAX_SPEED);
control.setForward(forwardsError);
control.setRight(sidewaysError);
control.setUp(-upwardsError);
DockingJPanel.setDockingStep(Bundle.getString("pnl_docking_step_approach"));
break;
case LINE_UP_WITH_TARGET:
forwardsError = calculateThrottle(forwardsDistanceLimit, forwardsDistanceLimit * 3, currentYAxisSpeed,
targetPosition.y, 0);
sidewaysError = calculateThrottle(0, 10, currentXAxisSpeed, targetPosition.x, SPEED_LIMIT);
upwardsError = calculateThrottle(0, 10, currentZAxisSpeed, targetPosition.z, SPEED_LIMIT);
sidewaysError = calculateThrottle(0, 10, currentXAxisSpeed, targetPosition.x, DOCKING_MAX_SPEED);
upwardsError = calculateThrottle(0, 10, currentZAxisSpeed, targetPosition.z, DOCKING_MAX_SPEED);
control.setForward(forwardsError);
control.setRight(sidewaysError);
control.setUp(-upwardsError);
DockingJPanel.setDockingStep(Bundle.getString("pnl_docking_step_line_up_with_target"));
break;
case GO_IN_FRONT_OF_TARGET:
forwardsError = calculateThrottle(-20, -10, currentYAxisSpeed,
targetPosition.y, SPEED_LIMIT);
targetPosition.y, DOCKING_MAX_SPEED);
sidewaysError = calculateThrottle(0, 5, currentXAxisSpeed, targetPosition.x, 0);
upwardsError = calculateThrottle(0, 5, currentZAxisSpeed, targetPosition.z, 0);
control.setForward(forwardsError);
control.setRight(sidewaysError);
control.setUp(-upwardsError);
if (isInFrontOfTarget) {
dockingStep = DOCKING_STEPS.STOP_RELATIVE_SPEED;
break;
}
DockingJPanel.setDockingStep(Bundle.getString("pnl_docking_step_go_in_front_of_target"));
break;
case STOP_RELATIVE_SPEED:
forwardsError = calculateThrottle(0, 5, currentYAxisSpeed, targetPosition.y, 0);
sidewaysError = calculateThrottle(0, 5, currentXAxisSpeed, targetPosition.x, 0);
upwardsError = calculateThrottle(0, 5, currentZAxisSpeed, targetPosition.z, 0);
control.setForward(forwardsError);
control.setRight(sidewaysError);
control.setUp(-upwardsError);
if ((Math.abs(currentXAxisSpeed) < 1) && (Math.abs(currentYAxisSpeed) < 1)
&& (Math.abs(currentZAxisSpeed) < 1)) {
dockingStep = DOCKING_STEPS.APPROACH;
break;
}
DockingJPanel.setDockingStep(Bundle.getString("pnl_docking_step_stop_relative_speed"));
break;
}
System.out.println(dockingStep);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/pesterenan/utils/Modulos.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ public enum Modulos {
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"),
MODULE_MANEUVER("MANEUVER"),
MODULO_POUSO_SOBREVOAR("HOVER"),
MODULO_DOCKING("DOCKING"),
MODULO_POUSO("LANDING"),
MODULO_POUSO_SOBREVOAR("HOVER"),
MODULO_ROVER("ROVER"),
MODULO_DOCKING("DOCKING"),
MODULO_TELEMETRIA("TELEMETRY"),
MODULO("Módulo"),
NAVE_ALVO("Nave alvo"),
NOME_MARCADOR("Nome do marcador"),
ORBITA_BAIXA("ÓRBITA BAIXA"),
Expand Down
72 changes: 53 additions & 19 deletions src/main/java/com/pesterenan/views/DockingJPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public class DockingJPanel extends JPanel implements UIMethods {

private static final long serialVersionUID = 0L;

private JLabel lblMaxSpeed;
private JTextField txfMaxSpeed;
private JLabel lblMaxSpeed, lblSafeDistance, lblCurrentDockingStepText;
private static JLabel lblDockingStep;

private JTextField txfMaxSpeed, txfSafeDistance;
private JButton btnBack, btnStartDocking;

public DockingJPanel() {
Expand All @@ -32,10 +34,13 @@ public DockingJPanel() {
@Override
public void initComponents() {
// Labels:
lblMaxSpeed = new JLabel(Bundle.getString("pnl_rover_lbl_max_speed"));

lblMaxSpeed = new JLabel(Bundle.getString("pnl_docking_max_speed"));
lblSafeDistance = new JLabel(Bundle.getString("pnl_docking_safe_distance"));
lblDockingStep = new JLabel(Bundle.getString("pnl_docking_step_ready"));
lblCurrentDockingStepText = new JLabel(Bundle.getString("pnl_docking_current_step"));
// Textfields:
txfMaxSpeed = new JTextField("3");
txfSafeDistance = new JTextField("50");

// Buttons:
btnBack = new JButton(Bundle.getString("pnl_rover_btn_back"));
Expand All @@ -51,6 +56,9 @@ public void setupComponents() {
txfMaxSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
txfMaxSpeed.setMaximumSize(BTN_DIMENSION);
txfMaxSpeed.setPreferredSize(BTN_DIMENSION);
txfSafeDistance.setHorizontalAlignment(SwingConstants.RIGHT);
txfSafeDistance.setMaximumSize(BTN_DIMENSION);
txfSafeDistance.setPreferredSize(BTN_DIMENSION);

btnBack.addActionListener(MainGui::backToTelemetry);
btnBack.setMaximumSize(BTN_DIMENSION);
Expand All @@ -74,12 +82,27 @@ public void layoutComponents() {
pnlMaxSpeed.add(Box.createHorizontalGlue());
pnlMaxSpeed.add(txfMaxSpeed);

JPanel pnlRoverControls = new JPanel();
pnlRoverControls.setLayout(new BoxLayout(pnlRoverControls, BoxLayout.Y_AXIS));
pnlRoverControls.setBorder(MARGIN_BORDER_10_PX_LR);
pnlRoverControls.add(MainGui.createMarginComponent(0, 6));
pnlRoverControls.add(pnlMaxSpeed);
pnlRoverControls.add(Box.createVerticalGlue());
JPanel pnlSafeDistance = new JPanel();
pnlSafeDistance.setLayout(new BoxLayout(pnlSafeDistance, BoxLayout.X_AXIS));
pnlSafeDistance.add(lblSafeDistance);
pnlSafeDistance.add(Box.createHorizontalGlue());
pnlSafeDistance.add(txfSafeDistance);

JPanel pnlDockingStep = new JPanel();
pnlDockingStep.setLayout(new BoxLayout(pnlDockingStep, BoxLayout.X_AXIS));
pnlDockingStep.add(lblCurrentDockingStepText);
pnlDockingStep.add(Box.createHorizontalGlue());
pnlDockingStep.add(lblDockingStep);

JPanel pnlDockingControls = new JPanel();
pnlDockingControls.setLayout(new BoxLayout(pnlDockingControls, BoxLayout.Y_AXIS));
pnlDockingControls.setBorder(MARGIN_BORDER_10_PX_LR);
pnlDockingControls.add(MainGui.createMarginComponent(0, 6));
pnlDockingControls.add(pnlMaxSpeed);
pnlDockingControls.add(pnlSafeDistance);
pnlDockingControls.add(Box.createVerticalGlue());
pnlDockingControls.add(pnlDockingStep);
pnlDockingControls.add(Box.createVerticalGlue());

JPanel pnlButtons = new JPanel();
pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.X_AXIS));
Expand All @@ -89,29 +112,40 @@ public void layoutComponents() {

JPanel pnlMain = new JPanel();
pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.X_AXIS));
pnlRoverControls.setAlignmentY(TOP_ALIGNMENT);
pnlMain.add(pnlRoverControls);
pnlDockingControls.setAlignmentY(TOP_ALIGNMENT);
pnlMain.add(pnlDockingControls);

setLayout(new BorderLayout());
add(pnlMain, BorderLayout.CENTER);
add(pnlButtons, BorderLayout.SOUTH);
}

public static void setDockingStep(String step) {
lblDockingStep.setText(step);
}

private void handleStartDocking(ActionEvent e) {
System.out.println("chamou startdocking");
Map<String, String> commands = new HashMap<>();
commands.put(Modulos.MODULO.get(), Modulos.MODULO_DOCKING.get());
commands.put(Modulos.VELOCIDADE_MAX.get(), txfMaxSpeed.getText());
MechPeste.newInstance().startModule(commands);
if (validateTextFields()) {
Map<String, String> 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());
MechPeste.newInstance().startModule(commands);
}
}

private boolean validateTextFields() {
try {
if (Float.parseFloat(txfMaxSpeed.getText()) > 10) {
throw new NumberFormatException();
StatusJPanel.setStatusMessage("Velocidade de acoplagem muito alta. Tem que ser menor que 10m/s.");
return false;
}
if (Float.parseFloat(txfSafeDistance.getText()) > 200) {
StatusJPanel.setStatusMessage("Distância segura muito alta. Tem que ser menor que 200m.");
return false;
}
} catch (NumberFormatException e) {
StatusJPanel.setStatusMessage(Bundle.getString("pnl_rover_max_speed_above_3"));
StatusJPanel.setStatusMessage(Bundle.getString("pnl_lift_stat_only_numbers"));
return false;
} catch (IllegalArgumentException e) {
StatusJPanel.setStatusMessage(Bundle.getString("pnl_rover_waypoint_name_not_empty"));
Expand Down
16 changes: 12 additions & 4 deletions src/main/resources/MechPesteBundle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
btn_func_create_maneuver = Create Maneuvers
btn_func_docking = Docking
btn_func_landing = Auto Landing
btn_func_liftoff = Orbital Liftoff
btn_func_create_maneuver = Create Maneuvers
btn_func_maneuver = Maneuvers
btn_func_rover = Drive Rover
btn_func_docking = Docking
btn_stat_connect = Connect
installer_dialog_btn_browse = Browse...
installer_dialog_btn_cancel = Cancel
Expand All @@ -19,8 +19,16 @@ main_mntm_about = About
main_mntm_change_vessels = Change vessels
main_mntm_exit = Exit
main_mntm_install_krpc = Install KRPC
pnl_func_title = Functions
pnl_common_lbl_limit_twr = Maximum TWR\:
pnl_docking_current_step = Current docking step:
pnl_docking_step_approach = Approaching...
pnl_docking_step_go_in_front_of_target = Going in front of target...
pnl_docking_step_line_up_with_target = Lining up with target...
pnl_docking_step_stop_relative_speed = Stopping relative speed...
pnl_docking_step_ready = Ready.
pnl_docking_max_speed = Max. Docking Speed:
pnl_docking_safe_distance = Safe Distance to approach:
pnl_func_title = Functions
pnl_land_border = Automatic Landing
pnl_land_btn_back = Back
pnl_land_btn_hover = Hover
Expand Down Expand Up @@ -62,8 +70,8 @@ pnl_mnv_lbl_adj_inc = Adjust inclination\:
pnl_mnv_lbl_exec_mnv = Execute next maneuver\:
pnl_rover_border = Drive Rover\:
pnl_rover_btn_back = Back
pnl_rover_btn_drive = Drive
pnl_rover_btn_docking = Start Docking
pnl_rover_btn_drive = Drive
pnl_rover_default_name = Target
pnl_rover_lbl_max_speed = Max Speed\:
pnl_rover_max_speed_above_3 = Max speed must be over 3m/s\u00B2
Expand Down
Loading
Loading