Learning-Based Adaptive MPC for Magnetorquer-Only Satellite Attitude Control
Prerequisites
Startup
- In workstation's bash shell, in desired directory, clone this repo
git clone git@github.com:JHU-ACEL/uranus-mpc.git
- In the directory you just cloned, follow the steps in
docker/README.mdto modify theDockerfileto include your Moreau License Key and build the docker image. - To verify that the image built properly, run
docker images
- To run a container, run
./docker/docker_run.sh <image_repository:tag> <PORT> # example: "./docker/docker_run.sh uranus-mpc:v1 8888"
- To start marimo, run
marimo edit --headless --host 0.0.0.0 --port=$PORT
- 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"
- 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.pydemonstrates the full functionality of the library and controller with online adaptation.B_field_Learning.pyshows 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.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| raddo-0.1.4.tar.gz | 45.5 kB | Without provenance | Details for raddo-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| raddo-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for raddo-0.1.4-py3-none-any.whl |
Total release size: 113.4 kB
Release files / raddo-0.1.4.tar.gz
| Download URL | raddo-0.1.4.tar.gz |
|---|---|
| Size | 45.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab64468c2aa147241f14feacfedc23d0173e2a4bacb6ba2f3d43ef70965f8e0c
|
|
BLAKE2b-256 checksum How to use checksums |
6a6fca3ecccf70c1db4cb4249bb2e1678b5e1436c2dd86f40ec886c64c6b79a4
|
| 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.4-py3-none-any.whl
| Download URL | raddo-0.1.4-py3-none-any.whl |
|---|---|
| Size | 67.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf39d21ef82c93e55272ba60d2dac2b318c1f2874c9a6dd5db42ad91b0939330
|
|
BLAKE2b-256 checksum How to use checksums |
6022fd6230deb1dc8979c45dc7fc75dd4172c8214e2ecf09c2d1a9e326636153
|
| 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.4
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.