Remote Execution

Remote execution lets one computer propagate the spacecraft simulation while another computes controller commands. The example keeps the environment and estimators local and sends controller calls to a remote worker.

Start the worker on the remote computer from the repository root:

python -m examples.remote.run_remote_universal_augmented --component controller

Set ADCS_REMOTE_HOST to the worker computer’s reachable address and ADCS_REMOTE_PORT to its listening port (5000 by default), then run python examples/tutorials/advanced_topics/remote_execution_godot.py on the simulation computer. For a same-computer trial, the example defaults to 127.0.0.1:5000.

Godot animation illustrating the remote controller example.

The GIF was rendered with the same controller and spacecraft in a local run; run the example to execute its controller on the worker. The plot shows angular rates, magnetorquer commands, final error, and target tracking.

Remote execution simulation results with angular rates, commands, final error, and tracking.
remote_execution_godot.py
import os

import matplotlib.pyplot as plt
from ADCS.helpers.animations import animate_orbit_godot
import numpy as np

import ADCS

np.random.seed(42)

# Main computer runs environmental dynamics, noise, and propagation locally.
real_sat = ADCS.satellite_factory.create_beavercube2_cubesat(estimated=False)
x_0 = ADCS.State.from_array(np.array([0.0, 0.0, 0.0] + [1, 0, 0, 0] + [0.0]))

controller = ADCS.controller.MTQ_w_RW_LP(
    est_sat=real_sat,
    p_gain=0.00005,
    d_gain=0.002,
    c_gain=0.001,
    h_target=np.array([0.0, 0.0, 0.0]),
)

os0 = ADCS.Orbital_State(
    ephem=ADCS.Ephemeris(),
    J2000=0.22,
    R=7000 * np.array([0, np.sqrt(2) / 2, np.sqrt(2) / 2]),
    V=np.array([8, 0, 0]),
)

goal = ADCS.goals.ECI_Goal(eci_vector=ADCS.helpers.normalize(np.array([1.0, 1.0, 1.0])))

# Set these to the remote worker address and port.
remote_host = os.getenv("ADCS_REMOTE_HOST", "127.0.0.1")
remote_port = int(os.getenv("ADCS_REMOTE_PORT", "5000"))

results = ADCS.simulate_remote(
    x=x_0,
    satellite=real_sat,
    os0=os0,
    controller=controller,
    goal=goal,
    dt=1.0,
    tf=1000.0,
    remote=ADCS.remote.RemoteSimulationConfig(
        controller=ADCS.remote.ComponentLocation.REMOTE,
        estimator=ADCS.remote.ComponentLocation.LOCAL,
        orbit_estimator=ADCS.remote.ComponentLocation.LOCAL,
        host=remote_host,
        port=remote_port,
        timeout_s=0.5,
        retries=2,
    ),
)

ADCS.plot(
    results,
    ADCS.plots.AttitudePlot(sources=["real", "reference"]),
    layout=(1, 1),
    title="Tutorial 08: Remote Controller Execution",
)

ADCS.plot(
    results,
    ADCS.plots.AngularVelocityPlotCombined(sources=["real"]),
    ADCS.plots.ControlPlotCombined(title="Magnetorquer Commands", units="Am²"),
    ADCS.plots.TargetHistogram(bin_width=5.0),
    ADCS.plots.TargetPlot(modes=["real_target"], title="Target Tracking"),
    layout=(2, 2),
    title="Tutorial 08: Remote Controller Execution",
)

animate_orbit_godot(results=results, graphics_quality="high")
plt.show()