Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Maneuver.lambert sometimes generates negative times of flight and crashes #1397

Closed
astrojuanlu opened this issue Nov 12, 2021 · 3 comments
Closed
Labels
good first issue Easy tasks for beginners triaging:bug

Comments

@astrojuanlu
Copy link
Member

Example:

In [25]: Maneuver.lambert(gto2, geo)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-25-f36ab89d597a> in <module>
----> 1 Maneuver.lambert(gto2, geo)

~/Projects/LSF/poliastro/library/src/poliastro/maneuver.py in lambert(cls, orbit_i, orbit_f, method, short, **kwargs)
    188 
    189         # Compute all possible solutions to the Lambert transfer
--> 190         sols = list(method(k, r_i, r_f, tof, **kwargs))
    191 
    192         # Return short or long solution

~/Projects/LSF/poliastro/library/src/poliastro/iod/izzo.py in lambert(k, r0, r, tof, M, numiter, rtol)
     44     sols = izzo_fast(k_, r0_, r_, tof_, M, numiter, rtol)
     45 
---> 46     for v0, v in sols:
     47         yield v0 << kms, v << kms

~/Projects/LSF/poliastro/library/src/poliastro/core/iod.py in izzo()
    190 
    191     # Check preconditions
--> 192     assert tof > 0
    193     assert k > 0
    194 

AssertionError: 

To reproduce:

import matplotlib.pyplot as plt
from astropy import units as u
from poliastro.bodies import Earth
from poliastro.twobody import Orbit
from poliastro.maneuver import Maneuver
from poliastro.plotting.static import StaticOrbitPlotter
geo = Orbit.circular(Earth, 36_000 * u.km)
man = Maneuver.impulse([0, 1, 0] * u.km / u.s)
gto = Orbit.circular(Earth, 36_000 * u.km, arglat=-180 * u.deg).apply_maneuver(man).propagate_to_anomaly(0 * u.deg)

fr = StaticOrbitPlotter()
fr.plot(geo)
fr.plot(gto)
plt.show()

Maneuver.lambert(gto, geo)

The reason for that is in the epochs of the orbits:

In [5]: gto.epoch.isot
Out[5]: '2000-01-01T18:16:27.067'

In [6]: geo.epoch.isot
Out[6]: '2000-01-01T12:00:00.000'

We should give a better error message rather than failing inside an assertion.

@astrojuanlu astrojuanlu added triaging:bug good first issue Easy tasks for beginners labels Nov 12, 2021
@TheBuffer
Copy link
Contributor

Hello, I am new to this Project so please correct me if I'm wrong.
From my understanding, the error occurs because the epoch of the gto Orbit is raised by the the time of flight required in the propagate_to_anamoly function, and this creates a Negative value when we're subtracting the initial orbit gto.epoch value from the final orbit geo.epoch value to get the Time Of Flight value for the Lambert maneuver?

@astrojuanlu
Copy link
Member Author

Hi @TheBuffer, welcome! Yes, that's correct.

Since the epochs are used to compute the time of flight, which is an input for the Lambert problem, it's important that they have sensible values. The problem here is that the user might not be aware of the epoch evolution of the gto orbit, and therefore raising a better error message is a better solution for now.

@astrojuanlu
Copy link
Member Author

Fixed in #1413!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy tasks for beginners triaging:bug
Projects
None yet
Development

No branches or pull requests

2 participants