Exemple #1
0
    def test_elliptical_orbital_parameters(self):
        # Again, see
        # https://www.wolframalpha.com/input/?i=International+Space+Station
        # For these expected values
        physics_state = common.load_savefile(
            common.savefile('tests/gui-test.json'))
        iss = physics_state[0]
        earth = physics_state[1]

        # The semiaxes are relatively close to expected.
        self.assertAlmostEqual(calc.semimajor_axis(iss, earth),
                               6785e3,
                               delta=0.01 * earth.r)

        # The eccentricity is within 1e-6 of the expected.
        self.assertAlmostEqual(calc.fastnorm(calc.eccentricity(iss, earth)),
                               5.893e-4,
                               delta=1e-3)

        # The apoapsis is relatively close to expected.
        self.assertAlmostEqual(calc.apoapsis(iss, earth),
                               418.3e3,
                               delta=0.01 * earth.r)

        # The periapsis is relatively close to expected.
        self.assertAlmostEqual(calc.periapsis(iss, earth),
                               410.3e3,
                               delta=0.01 * earth.r)
Exemple #2
0
    def _create_wtexts(self):
        vpython.canvas.get_selected().caption += "<table>\n"
        self._wtexts: List[TableText] = []

        self._wtexts.append(
            TableText("Simulation time",
                      lambda state: datetime.fromtimestamp(
                          state.timestamp, common.TIMEZONE).strftime('%x %X'),
                      "Current time in simulation",
                      new_section=False))
        self._wtexts.append(
            TableText("Orbit speed",
                      lambda state: common.format_num(
                          calc.orb_speed(state.craft_entity(),
                                         state.reference_entity()), " m/s"),
                      "Speed required for circular orbit at current altitude",
                      new_section=False))

        self._wtexts.append(
            TableText(
                "Periapsis",
                lambda state: common.format_num(calc.periapsis(
                    state.craft_entity(), state.reference_entity()) / 1000,
                                                " km",
                                                decimals=3),
                "Lowest altitude in naïve orbit around reference",
                new_section=False))

        self._wtexts.append(
            TableText(
                "Apoapsis",
                lambda state: common.format_num(calc.apoapsis(
                    state.craft_entity(), state.reference_entity()) / 1000,
                                                " km",
                                                decimals=3),
                "Highest altitude in naïve orbit around reference",
                new_section=False))

        self._wtexts.append(
            TableText(
                # The H in HRT stands for Habitat, even though craft is more
                # general and covers Ayse, but HRT is the familiar triple name and
                # the Hawking III says trans rights.
                "HRT phase θ",
                lambda state: common.format_num(
                    calc.phase_angle(
                        state.craft_entity(), state.reference_entity(),
                        state.target_entity()), "°") or "Same ref and targ",
                "Angle between Habitat, Reference, and Target",
                new_section=False))

        self._wtexts.append(
            TableText(
                "Throttle",
                lambda state: "{:.1%}".format(state.craft_entity().throttle),
                "Percentage of habitat's maximum rated engines",
                new_section=True))

        self._wtexts.append(
            TableText("Engine Acceleration",
                      lambda state: common.format_num(
                          calc.engine_acceleration(state), " m/s/s") +
                      (' [SRB]' if state.srb_time > 0 else ''),
                      "Acceleration due to craft's engine thrust",
                      new_section=False))

        self._wtexts.append(
            TableText("Drag",
                      lambda state: common.format_num(
                          calc.fastnorm(calc.drag(state)), " m/s/s"),
                      "Atmospheric drag acting on the craft",
                      new_section=False))

        self._wtexts.append(
            TableText("Fuel",
                      lambda state: common.format_num(
                          state.craft_entity().fuel, " kg"),
                      "Remaining fuel of craft",
                      new_section=False))

        def rotation_formatter(state: PhysicsState) -> str:
            deg_spin = round(np.degrees(state.craft_entity().spin), ndigits=1)
            if deg_spin < 0:
                return f"{-deg_spin} °/s cw"
            elif deg_spin > 0:
                return f"{deg_spin} °/s ccw"
            else:
                return f"{deg_spin} °/s"

        self._wtexts.append(
            TableText("Rotation",
                      rotation_formatter,
                      "Rotation speed of craft",
                      new_section=False))

        self._wtexts.append(
            TableText(
                "Ref altitude",
                lambda state: common.format_num(calc.altitude(
                    state.craft_entity(), state.reference_entity()) / 1000,
                                                " km",
                                                decimals=3),
                "Altitude of habitat above reference surface",
                new_section=True))

        self._wtexts.append(
            TableText("Ref speed",
                      lambda state: common.format_num(
                          calc.speed(state.craft_entity(),
                                     state.reference_entity()), " m/s"),
                      "Speed of habitat above reference surface",
                      new_section=False))

        self._wtexts.append(
            TableText(
                "Vertical speed",
                lambda state: common.format_num(
                    calc.v_speed(state.craft_entity(), state.reference_entity(
                    )), " m/s "),
                "Vertical speed of habitat towards/away reference surface",
                new_section=False))

        self._wtexts.append(
            TableText("Horizontal speed",
                      lambda state: common.format_num(
                          calc.h_speed(state.craft_entity(),
                                       state.reference_entity()), " m/s "),
                      "Horizontal speed of habitat across reference surface",
                      new_section=False))

        self._wtexts.append(
            TableText("Pitch θ",
                      lambda state: common.format_num(
                          np.degrees(
                              calc.pitch(state.craft_entity(
                              ), state.reference_entity())) % 360, "°"),
                      "Horizontal speed of habitat across reference surface",
                      new_section=False))

        self._wtexts.append(
            TableText("Targ altitude",
                      lambda state: common.format_num(calc.altitude(
                          state.craft_entity(), state.target_entity()) / 1000,
                                                      " km",
                                                      decimals=3),
                      "Altitude of habitat above reference surface",
                      new_section=True))

        self._wtexts.append(
            TableText("Targ speed",
                      lambda state: common.format_num(
                          calc.speed(state.craft_entity(), state.target_entity(
                          )), " m/s"),
                      "Speed of habitat above target surface",
                      new_section=False))

        self._wtexts.append(
            TableText(
                "Landing acc",
                lambda state: common.format_num(
                    calc.landing_acceleration(state.craft_entity(),
                                              state.target_entity()), " m/s/s"
                ) or "no vertical landing",
                "Constant engine acc to land during vertical descent to target",
                new_section=False))

        vpython.canvas.get_selected().caption += "</table>"