@@ -47,16 +47,14 @@ public void run() {
4747
4848public void calculateManeuver () {
4949 try {
50- if (naveAtual .getSituation () == VesselSituation .LANDED
51- || naveAtual .getSituation () == VesselSituation .SPLASHED ) {
50+ if (naveAtual .getSituation () == VesselSituation .LANDED || naveAtual .getSituation () == VesselSituation .SPLASHED ) {
5251 throw new InterruptedException ();
5352 }
5453 if (this .function .equals (Modulos .AJUSTAR .get ())) {
5554 this .alignPlanes ();
5655 return ;
5756 }
58- if (this .function .equals (Modulos .EXECUTAR .get ()))
59- return ;
57+ if (this .function .equals (Modulos .EXECUTAR .get ())) return ;
6058 double parametroGravitacional = naveAtual .getOrbit ().getBody ().getGravitationalParameter ();
6159 double altitudeInicial = 0 , tempoAteAltitude = 0 ;
6260 if (this .function .equals (Modulos .APOASTRO .get ())) {
@@ -69,12 +67,10 @@ public void calculateManeuver() {
6967 }
7068
7169 double semiEixoMaior = naveAtual .getOrbit ().getSemiMajorAxis ();
72- double velOrbitalAtual = Math
73- .sqrt (parametroGravitacional * ((2.0 / altitudeInicial ) - (1.0 / semiEixoMaior )));
74- double velOrbitalAlvo = Math
75- .sqrt (parametroGravitacional * ((2.0 / altitudeInicial ) - (1.0 / altitudeInicial )));
70+ double velOrbitalAtual = Math .sqrt (parametroGravitacional * ((2.0 / altitudeInicial ) - (1.0 / semiEixoMaior )));
71+ double velOrbitalAlvo = Math .sqrt (parametroGravitacional * ((2.0 / altitudeInicial ) - (1.0 / altitudeInicial )));
7672 double deltaVdaManobra = velOrbitalAlvo - velOrbitalAtual ;
77- double [] deltaV = {deltaVdaManobra , 0 , 0 };
73+ double [] deltaV = { deltaVdaManobra , 0 , 0 };
7874 createManeuver (tempoAteAltitude , deltaV );
7975 } catch (RPCException | InterruptedException e ) {
8076 disengageAfterException (Bundle .getString ("status_maneuver_not_possible" ));
@@ -85,8 +81,7 @@ public void matchOrbitApoapsis() {
8581 try {
8682 Orbit targetOrbit = getTargetOrbit ();
8783 System .out .println (targetOrbit .getApoapsis () + "-- APO" );
88- Node maneuver = hohmannTransferToOrbit (targetOrbit ,
89- naveAtual .getOrbit ().getTimeToPeriapsis ());
84+ Node maneuver = hohmannTransferToOrbit (targetOrbit , naveAtual .getOrbit ().getTimeToPeriapsis ());
9085 while (true ) {
9186 double currentDeltaApo = compareOrbitParameter (maneuver .getOrbit (), targetOrbit , Compare .AP );
9287 String deltaApoFormatted = String .format ("%.2f" , currentDeltaApo );
@@ -106,15 +101,14 @@ public void matchOrbitApoapsis() {
106101}
107102
108103private Node hohmannTransferToOrbit (Orbit targetOrbit , double timeToStart ) {
109- double [] totalDv = {0 , 0 , 0 };
104+ double [] totalDv = { 0 , 0 , 0 };
110105 try {
111106 double startingRadius = naveAtual .getOrbit ().getPeriapsis ();
112107 double finalRadius = targetOrbit .getApoapsis ();
113108 System .out .println (startingRadius + " --- " + finalRadius );
114109 double gravitationalParameter = naveAtual .getOrbit ().getBody ().getGravitationalParameter ();
115110 // DeltaV used to get to the second Node
116- double firstNodeDv = Math .sqrt (gravitationalParameter
117- * ((2.0 / startingRadius ) - (1.0 / naveAtual .getOrbit ().getSemiMajorAxis ())));
111+ double firstNodeDv = Math .sqrt (gravitationalParameter * ((2.0 / startingRadius ) - (1.0 / naveAtual .getOrbit ().getSemiMajorAxis ())));
118112 // DeltaV used to orbit in the second Node
119113 double secondNodeDv = Math .sqrt (gravitationalParameter * ((2.0 / startingRadius ) - (1.0 / finalRadius )));
120114 // Time taken between the two points
@@ -127,7 +121,7 @@ private Node hohmannTransferToOrbit(Orbit targetOrbit, double timeToStart) {
127121
128122private Node createManeuverAtClosestIncNode (Orbit targetOrbit ) {
129123 double uTatClosestNode = 1 ;
130- double [] dv = {0 , 0 , 0 };
124+ double [] dv = { 0 , 0 , 0 };
131125 try {
132126 double [] incNodesUt = getTimeToIncNodes (targetOrbit );
133127 uTatClosestNode = Math .min (incNodesUt [0 ], incNodesUt [1 ]) - centroEspacial .getUT ();
@@ -137,7 +131,7 @@ private Node createManeuverAtClosestIncNode(Orbit targetOrbit) {
137131}
138132
139133private double [] getTimeToIncNodes (Orbit targetOrbit ) {
140- double [] incNodesUt = {0 , 0 };
134+ double [] incNodesUt = { 0 , 0 };
141135 try {
142136 Orbit vesselOrbit = naveAtual .getOrbit ();
143137 double ascendingNode = vesselOrbit .trueAnomalyAtAN (targetOrbit );
@@ -163,11 +157,11 @@ public void alignPlanes() {
163157 break ;
164158 }
165159 double dvNormal = maneuver .getNormal ();
166- double ctrlOutput = ctrlManeuver .computarPID (currentDeltaInc , 0.0 )
167- * limitPIDOutput (Math .abs (currentDeltaInc ));
168- if ((closestIsAN ? currentDeltaInc : - currentDeltaInc ) > 0.0 ) {
160+ double ctrlOutput = ctrlManeuver .computarPID (currentDeltaInc , 0.0 ) * limitPIDOutput (Math .abs (currentDeltaInc ));
161+ if ((closestIsAN ? currentDeltaInc : -currentDeltaInc ) > 0.0 ) {
169162 maneuver .setNormal (dvNormal + (ctrlOutput ));
170- } else {
163+ }
164+ else {
171165 maneuver .setNormal (dvNormal - (ctrlOutput ));
172166 }
173167 Thread .sleep (25 );
@@ -178,10 +172,8 @@ public void alignPlanes() {
178172}
179173
180174private double limitPIDOutput (double absDeltaInc ) {
181- if (absDeltaInc < 0.05 )
182- return 0.1 ;
183- if (absDeltaInc < 0.5 )
184- return 5 ;
175+ if (absDeltaInc < 0.05 ) return 0.1 ;
176+ if (absDeltaInc < 0.5 ) return 5 ;
185177 return 10 ;
186178}
187179
@@ -229,8 +221,7 @@ private Orbit getTargetOrbit() throws RPCException {
229221private Node createManeuver (double laterTime , double [] deltaV ) {
230222 Node maneuverNode = null ;
231223 try {
232- naveAtual .getControl ().addNode (centroEspacial .getUT () + laterTime , (float ) deltaV [0 ], (float ) deltaV [1 ],
233- (float ) deltaV [2 ]);
224+ naveAtual .getControl ().addNode (centroEspacial .getUT () + laterTime , (float ) deltaV [0 ], (float ) deltaV [1 ], (float ) deltaV [2 ]);
234225 List <Node > currentNodes = naveAtual .getControl ().getNodes ();
235226 maneuverNode = currentNodes .get (currentNodes .size () - 1 );
236227 } catch (UnsupportedOperationException | RPCException e ) {
@@ -260,7 +251,7 @@ public void orientToManeuverNode(Node maneuverNode) {
260251 float roll = ap .getTargetRoll ();
261252 roll = Float .isNaN (roll ) ? 0 : roll ;
262253 ap .setTargetRoll (roll );
263- nav .mirarNaManobra (maneuverNode );
254+ nav .targetManeuver (maneuverNode );
264255 ap .engage ();
265256 while (ap .getError () > 1 ) {
266257 StatusJPanel .setStatus (Bundle .getString ("status_orienting_ship" ));
@@ -275,7 +266,7 @@ public double calculateBurnTime(Node noDeManobra) throws RPCException {
275266
276267 List <Engine > motores = naveAtual .getParts ().getEngines ();
277268 for (Engine motor : motores ) {
278- if (motor .getPart ().getStage () == naveAtual .getControl ().getCurrentStage () && ! motor .getActive ()) {
269+ if (motor .getPart ().getStage () == naveAtual .getControl ().getCurrentStage () && !motor .getActive ()) {
279270 motor .setActive (true );
280271 }
281272 }
@@ -302,26 +293,22 @@ public void executeBurn(Node noDeManobra, double duracaoDaQueima) {
302293 while (inicioDaQueima > 0 ) {
303294 inicioDaQueima = noDeManobra .getTimeTo () - (duracaoDaQueima / 2.0 );
304295 inicioDaQueima = Math .max (inicioDaQueima , 0.0 );
305- nav .mirarNaManobra (noDeManobra );
296+ nav .targetManeuver (noDeManobra );
306297 StatusJPanel .setStatus (String .format (Bundle .getString ("status_maneuver_ignition_in" ), inicioDaQueima ));
307298 Thread .sleep (100 );
308299 }
309300 // Executar a manobra:
310- Stream <Triplet <Double , Double , Double >> queimaRestante = getConexao ().addStream (noDeManobra ,
311- "remainingBurnVector" , noDeManobra .getReferenceFrame ());
301+ Stream <Triplet <Double , Double , Double >> queimaRestante = getConexao ().addStream (noDeManobra , "remainingBurnVector" , noDeManobra .getReferenceFrame ());
312302 StatusJPanel .setStatus (Bundle .getString ("status_maneuver_executing" ));
313- double limiteParaDesacelerar = noDeManobra .getDeltaV () > 1000 ? 0.025
314- : noDeManobra .getDeltaV () > 250 ? 0.10 : 0.25 ;
303+ double limiteParaDesacelerar = noDeManobra .getDeltaV () > 1000 ? 0.025 : noDeManobra .getDeltaV () > 250 ? 0.10 : 0.25 ;
315304
316305 while (noDeManobra != null ) {
317306 if (queimaRestante .get ().getValue1 () < (fineAdjustment ? 3 : 0.5 )) {
318307 break ;
319308 }
320- nav .mirarNaManobra (noDeManobra );
321- throttle (Utilities .remap (noDeManobra .getDeltaV () * limiteParaDesacelerar , 0 , 1 , 0.1 ,
322- queimaRestante .get ().getValue1 ()));
323- MainGui .getParametros ().getComponent (0 ).firePropertyChange ("distancia" , 0 ,
324- queimaRestante .get ().getValue1 ());
309+ nav .targetManeuver (noDeManobra );
310+ throttle (Utilities .remap (noDeManobra .getDeltaV () * limiteParaDesacelerar , 0 , 1 , 0.1 , queimaRestante .get ().getValue1 ()));
311+ MainGui .getParametros ().getComponent (0 ).firePropertyChange ("distancia" , 0 , queimaRestante .get ().getValue1 ());
325312 Thread .sleep (25 );
326313 }
327314 throttle (0.0f );
@@ -342,11 +329,10 @@ public void executeBurn(Node noDeManobra, double duracaoDaQueima) {
342329 }
343330}
344331
345- private void adjustManeuverWithRCS (Stream <Triplet <Double , Double , Double >> queimaRestante )
346- throws RPCException , StreamException , InterruptedException {
332+ private void adjustManeuverWithRCS (Stream <Triplet <Double , Double , Double >> queimaRestante ) throws RPCException , StreamException , InterruptedException {
347333 naveAtual .getControl ().setRCS (true );
348334 while (queimaRestante .get ().getValue1 () >= 0.1 ) {
349- naveAtual .getControl ().setForward ((float ) ctrlRCS .computarPID (- queimaRestante .get ().getValue1 () * 10 , 0 ));
335+ naveAtual .getControl ().setForward ((float ) ctrlRCS .computarPID (-queimaRestante .get ().getValue1 () * 10 , 0 ));
350336 Thread .sleep (25 );
351337 }
352338 naveAtual .getControl ().setForward (0 );
0 commit comments