Skip to main content

Learning-Based Adaptive MPC for Magnetorquer-Only Satellite Attitude Control

hero_white_background

Prerequisites

  1. Docker
  2. GPU Access
  3. Moreau (requires license)

Startup

  1. In workstation's bash shell, in desired directory, clone this repo
git clone git@github.com:JHU-ACEL/uranus-mpc.git
  1. In the directory you just cloned, follow the steps in docker/README.md to modify the Dockerfile to include your Moreau License Key and build the docker image.
  2. To verify that the image built properly, run
docker images
  1. To run a container, run
./docker/docker_run.sh <image_repository:tag> <PORT> # example: "./docker/docker_run.sh uranus-mpc:v1 8888"
  1. To start marimo, run
marimo edit --headless --host 0.0.0.0 --port=$PORT
  1. If you are accessing a workstation with a GPU virtually, you will need to port forward to your local machine. In your local command line, run
ssh -L localhost:${PORT}:localhost:${PORT} -N -f ${UID}@{remote} # ex: "ssh -L localhost:8888:localhost:8888 -N -f pschwa24@enceladus.wse.jhu.edu"
  1. On your browser on your local machine you can go to URL given in marimo (e.g. https://0.0.0.0:8888) and copy and paste the access token to access marimo.

Examples

  • Spacecraft_Control.py demonstrates the full functionality of the library and controller with online adaptation.
  • B_field_Learning.py shows the training pipeline for training the magnetic field models offline.

Working with the library

The library is set-up to be fully compatible with JAX, and thus everything is parallelized and JIT-compatible. It makes use of Equinox to make this easy and set-up with Object-Oriented Programming.

Base functions

First, set the dynamics class. The spacecraft attitude dynamics with magnetorquer-attitude control is initialized as follows:

spacecraft_dynamics = SpacecraftDynamics(mag_model=model_s,planet=planet)

Most of the primary functionality is built into the TrajectoryGenerator class, which is initialized by providing it with dynamics and a time-step.

system = TrajectoryGenerator(dynamics=spacecraft_dynamics, dt=dt)

After initializing the class, you can generate a trajectory. If the only thing provided is the initial state, key, and number of steps, the initial states are just propagated according to the dynamics.

trajectory, controls = system.generate_trajectory(initial_state=initial_state, key=key, num_steps=num_steps)

Alternatively, you could provide a fixed control sequence that it will propagate.

trajectory, controls = system.generate_trajectory(initial_state=initial_state, key=key, num_steps=num_steps, control_sequence=control_sequence)

If your dynamics require and external dynamics parameter (e.g. magnetic field values), then those must also be provided to the external_dynamics_params field. Additionally, a random disturbance force/torque is applied at each step if a standard deviation for it is provided.

trajectory, controls = system.generate_trajectory(initial_state=init_state, target_state=target_state, key=key1, external_dynamics_params=b_field_values, control_sequence=control_sequence, num_steps=num_steps, noise_std=noise_std_dyn)

You can also propagate controlled trajectories. First, initialize the controllers

qp_controller = QPController(system, Q_qp, Qf_qp, R_qp, state_limits, control_limits, horizon_qp) # high_level_controller
fb_controller = FeedbackController(system,Q_fb,Qf_fb,R_fb,control_limits) # low_level_controller

and then provide them to the generate_trajectory function along with a target state and how frequently the high_level_controller should replan. The high_level_controller is called every replan_freq timesteps, and the low_level_controller is called every timestep and tracks the nominal trajectory produced by the high_level_controller. If no low_level_controller is provided, the nominal control inputs produced by the high_level_controller are just used at each timestep. If no high_level_controller is provided, then the low_level_controlller just works by itself trying to reach the target state provided.

trajectory, controls = system.generate_trajectory(initial_state=init_state, target_state=target_state, key=key, external_dynamics_params=b_field_values, high_level_controller=qp_controller, low_level_controller=fb_controller, replan_freq=replan_freq_qp, num_steps=num_steps, noise_std=noise_std_dyn)

A full batch of trajectories can just as easily be generated. If an arrays of batch_size are provided, then it will use all of them, but if you only want to change some things for each trajectory (e.g. have the same initial state for all of them, but different target states), that works too. The following example just provides one initial state, but batch_size different target states and b field values. The noise always changes for each trajectory.

traj_batch, cntrl_batch = system.generate_trajectory_batch(initial_states=init_state, target_states=target_states, key=key, batch_size=batch_size, external_dynamics_params=b_batch, external_dynamics_params_est=None, high_level_controller=qp_controller, low_level_controller=fb_controller, replan_freq=replan_freq_qp, chunk_size=None, num_steps=num_steps_batch, noise_std=noise_std_dyn)

Using learned b-field models and online-adaptation

In order to use the learned b-field model in the controller instead of the true values, provide the cartesian coordinates in the PCI frame of the orbit to external_dynamics_params_est Online adaptation is performed if the frequency that adaptation is performed adapt_freq and the size of the history buffer history are provided.

traj_adapt, cntrl_adapt = system_coarse.generate_trajectory(initial_state=init_state, target_state=target_state, key=key, external_dynamics_params=b, external_dynamics_params_est=orbit_xyz, high_level_controller=qp_controller, low_level_controller=fb_controller, replan_freq=replan_freq_qp, num_steps=num_steps, noise_std=noise_std_dyn, adapt_freq=adapt_freq_qp, history=history_qp)

Plotting

The trajectories for all states can be plotted using

system.plot_traj(trajectory, controls)

Multiple trajectories can be plotted for comparison, and you can provide additional arguments to plot the target state as a dotted line and include a legend.

system.plot_traj(jnp.array([traj_true, traj_full, traj_low, traj_adapt]), jnp.array([cntrl_true, cntrl_full, cntrl_low, cntrl_adapt]), target_state=target_state, legend=["Full-order", "Low-order", "Low-order w/ Adaptation"])

You can also plot the costs over time using

system.plot_costs(jnp.array([traj_true, traj_full, traj_low, traj_adapt]), target_state,legend=["True","Full", "Dipole", "Adapt"])

If you want to visualize statistics for a batch of trajectories, you can use

system.plot_costs(traj_batch, target_states, plot_stats=True)

and

system.plot_violin_and_bar(trajs_batch, target_states, angle_threshold=angle_threshold, omega_threshold=omega_threshold, angle_stability_tol=angle_tol, omega_stability_tol=omega_tol, tail_length=tail_length, verbose=True)

Metadata

Release files for raddo 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for raddo 0.1.5
File Size Uploaded Provenance Actions
raddo-0.1.5.tar.gz 46.4 kB Without provenance Details for raddo-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for raddo 0.1.5
File Interpreter ABI Platform Actions
raddo-0.1.5-py3-none-any.whl Python 3 none any Details for raddo-0.1.5-py3-none-any.whl

Total release size: 114.9 kB

Release files / raddo-0.1.5.tar.gz

Download URL raddo-0.1.5.tar.gz
Size 46.4 kB
Tags Source
SHA-256 checksum
How to use checksums
514c0a48447bb2a0b702622588d119d25bf660dc9ae84c51b4b0d78ac1439792
BLAKE2b-256 checksum
How to use checksums
ad2800e58a555a0e6b2bbfc6a6e55c2c476d924ee248d1a50c862dee4b5c4a6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / raddo-0.1.5-py3-none-any.whl

Download URL raddo-0.1.5-py3-none-any.whl
Size 68.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
073e30cecf740a7b7d36fffe86703996323f11ce79772fc1f3b16110ed98c51a
BLAKE2b-256 checksum
How to use checksums
16cbe7bfca09f63a37923bdc7becdcfe513fa1a0ecf38119dc3750fbaeb50966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for raddo 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page