Source code for test_antennaProducerScheduling

# ISC License
#
# Copyright (c) 2026, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

"""Exercise antenna initialization through the simulation scheduler.

Real spacecraft, ground, antenna, link-budget, downlink and storage modules run
on ordered tasks. Delaying either the ground or antenna task exercises the
waiting state over multiple timestamps. Reinitializing the same simulation
after an altitude change exercises previously written producer messages.
"""

import numpy as np
import pytest

from Basilisk.architecture import messaging
from Basilisk.simulation import (
    downlinkHandling,
    groundLocation,
    linkBudget,
    simpleAntenna,
    simpleStorageUnit,
    spacecraft,
)
from Basilisk.utilities import RigidBodyKinematics as rbk
from Basilisk.utilities import SimulationBaseClass, macros, orbitalMotion


TASK_PERIOD = 1.0  # [s]
FREQUENCY = 20.0e9  # [Hz]
BANDWIDTH = 8.0e6  # [Hz]
INITIAL_ALTITUDE = 1624.0  # [m]
ALTITUDE_CHANGE = 2000.0  # [m]
LINK_DISTANCE = 2000.0e3  # [m]
INITIAL_DATA = 10000000  # [bit]


[docs] def configure_antenna(antenna, name, state): """Configure an antenna without sky-map or ephemeris dependencies. :param antenna: Antenna module to configure. :param name: Published antenna identifier. :param state: Transmit or receive antenna state. """ antenna.ModelTag = name antenna.setAntennaName(name) antenna.setAntennaState(state) antenna.setAntennaFrequency(FREQUENCY) antenna.setAntennaBandwidth(BANDWIDTH) antenna.setAntennaDirectivity_dB(30.0) # [dBi] antenna.setAntennaHpbwRatio(1.0) # [-] antenna.setAntennaP_Tx(5.0) # [W] antenna.setAntennaP_Rx(5.0) # [W] antenna.setAntennaEquivalentNoiseTemp(120.0) # [K] antenna.setAntennaRadEfficiency(0.65) # [-] antenna.setAntennaEnvironmentTemperature(150.0) # [K]
[docs] @pytest.mark.parametrize("ground_first", [False, True], ids=["ground-second", "ground-first"]) @pytest.mark.parametrize( "delayed_task", [None, "antennas", "ground"], ids=["ordered", "delayed-antennas", "delayed-ground"], ) def test_scheduled_antenna_initialization(ground_first, delayed_task): """Validate initialization, waiting, downstream service and reset scheduling. Validation Test Description --------------------------- Delayed tasks remain disabled for two ticks while consumers keep running, then resume in producer order. A full simulation reset must subsequently rebuild the atmosphere at the changed altitude on its first scheduled tick. Test Parameter Discussion ------------------------- Both link input orders are exercised with normal startup, delayed antenna publication, and antennas publishing before the ground position is ready. Description of Variables Being Tested ------------------------------------- Check CNR, atmospheric and pointing loss, ground normal and position, message timestamps, downlink service and integrated storage removal. :param ground_first: Whether the ground antenna uses link input one. :param delayed_task: Producer task to delay, or ``None`` for normal startup. """ chain = ScheduledLink(ground_first) chain.sim.InitializeSimulation() assert not chain.budget.antennaInPayload_1.isWritten() assert not chain.budget.antennaInPayload_2.isWritten() chain.assert_reset_output() if delayed_task is not None: chain.sim.disableTask(delayed_task) chain.run_until(TASK_PERIOD) if delayed_task is not None: for values in ( chain.link_log.CNR1, chain.link_log.CNR2, chain.link_log.bandwidth, chain.loss_log.L_atm, chain.downlink_log.linkActive, chain.downlink_log.deliveredDataRate, chain.downlink_log.cumulativeRemovedBits, chain.node_log.baudRate, ): np.testing.assert_array_equal(values, 0.0) np.testing.assert_array_equal(chain.storage_log.storageLevel, INITIAL_DATA) chain.sim.enableTask(delayed_task) chain.run_until(3*TASK_PERIOD) expected_times = np.arange(4)*macros.sec2nano(TASK_PERIOD) # [ns] np.testing.assert_array_equal(chain.link_log.times(), expected_times) first_loss = chain.assert_ready(0 if delayed_task is None else 2, ground_first) previous_position = chain.ground_position.copy() chain.set_geometry(INITIAL_ALTITUDE + ALTITUDE_CHANGE) chain.sim.InitializeSimulation() chain.assert_reset_output() # The old antenna publication survives reset; the next ordered tick must replace it. np.testing.assert_allclose(chain.receiver.antennaOutMsg.read().r_AP_N, previous_position) chain.run_until(2*TASK_PERIOD) np.testing.assert_array_equal(chain.link_log.times(), expected_times[:3]) assert chain.assert_ready(0, ground_first) < first_loss
if __name__ == "__main__": raise SystemExit(pytest.main([__file__]))