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

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

@astrojuanlu

Description

@astrojuanlu

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions