PDM4ARocket Explorer
This exercise tackles a complex problem in space exploration - navigating and landing a spacecraft through challenging space environments. The goal is to reach a predefined target location using only the two functional lateral thrusters of the spaceship.
Task
Your task is to write the planning stack for a simulated “spaceship agent”. To this end, the agent is coupled with a simulator in closed-loop. At each simulation step, the agent receives observations (about its state and other obstacles’ state) and it is expected to return control commands.
You have the freedom to implement any planning algorithm you deem appropriate.
However, based on experience, we suggest to solve the problem adopting a sequential convexification approach.
In case you choose to use this method, you are provided with a template of the algorithm.
In case you choose a different approach, make sure to preserve the Agent
interface (or it won’t work with the
simulator).
Scenarios
Your agent will be tested in three different scenarios:
- Scenario 1: Dodging Planets with a Static Goal
- In this scenario, the spacecraft needs to avoid planets while reaching a fixed final goal, $X_1$.
- Scenario 2: Dodging a Planet and Its Satellites with a Static Goal
- The spacecraft must navigate around a planet with multiple moving satellites to reach a fixed final goal, $X_1$.
- Scenario 3: Dodging a Planet and Its Satellites with a Time Varying Goal
- Similar to Scenario 2, but the final goal is linked with one of the satellites.
Rocket dynamics
Your planner is specifically designed to cope with the unfortunate event of losing the main thruster. The goal is to still navigate the rocket past obstacles while reaching a predefined target location, using only the two functional lateral thrusters. The rocket’s dynamics are represented by the following equations:
- Position Dynamics:
- $\frac{dx}{dt} = v_x$
- $\frac{dy}{dt} = v_y$
- Orientation Dynamics:
- $\frac{d\psi}{dt} = \dot{\psi}$
- Fuel Dynamics:
- $\frac{dm}{dt} = -C_T(F_l + F_r)$
- Velocity Dynamics:
- $\frac{dv_x}{dt} = \frac{1}{m}(sin(\phi+\psi)F_l + sin(\phi-\psi)F_r)$
- $\frac{dv_y}{dt} = \frac{1}{m}(-cos(\phi+\psi)F_l + cos(\phi-\psi)F_r)$
- Angular Velocity Dynamics:
- $\frac{d\dot{\psi}}{dt} = \frac{l_m}{I}cos(\phi)(F_r - F_l)$
- $\frac{d\phi}{dt} = \dot{\phi}$
If the spacecraft’s state is represented by $X = [x, y, \psi, v_x, v_y, \dot{\psi}, \phi, m]’$, and the control inputs are $U = [F_l, F_r, \dot{\phi}]$, we obtain the following dynamics equations:
- Dynamics:
- $\frac{dX(t)}{dt} = f(X(t), U(t))$
The rocket you have the control over has two side thrusters where you are able to control the amount of thrust to produce $F_l$ and $F_r$ and the coupled angle of the thrusters $\phi$. The thrusters are mounted centrally on the rocket with an offset of $l_m$ to the CoG of the rocket. The velocity $v_x$ and $v_y$ are the velocities in the x and y direction of the world frame respectively. The angle $\psi$ is the angle of the rocket with respect to the x-axis. The angle $\phi$ is the angle of the thrusters with respect to the rocket. The length of the rocket is $l$.
Constraints
There are several constraints that need to be satisfied, [$x_0, y_0$] is the starting location and [$x_1, y_1$] is the goal location:
- The initial and final inputs needs to be zero: $U(t_0) = U(t_f) = 0$
- The spacecraft needs to arrive close to the goal
- $\left\lVert \begin{bmatrix} x(t_f) \ y(t_f) \end{bmatrix} - \begin{bmatrix} x_{\text{1}} \ y_{\text{1}} \end{bmatrix} \right\rVert _{2} < \text{pos_tol}$
- with a specified orientation.
- $\left\lVert \psi(t_f) - \psi_{\text{1}} \right\rVert _{1} < \text{dir_tol}$
- The spacecraft needs to arrive with a specified velocity.
- $\left\lVert \begin{bmatrix} v_x(t_f) \ v_y(t_f) \end{bmatrix} - \begin{bmatrix} v_{x,1} \ v_{y,1} \end{bmatrix} \right\rVert _{2} < \text{vel_tol}$
- The spacecraft needs to dodge every obstacle in its path: $(x, y) \bigoplus \mathcal{X}_{Rocket}(\psi) \notin Obstacle \quad \forall Obstacle \in Obstacles$
- The spacecraft’s mass should be greater than or equal to the mass of the spacecraft without fuel: $m(t) \geq m_ {spacecraft} \quad \forall t$
- Control inputs, $F_l$ and $F_r$, are limited: $F_l, F_r \in [0, F_{\text{max}}]$.
- The thrust angle is limited and coupled between the two lateral thrusters: $\phi_l=\phi_r=\phi \in [-\phi_{\text{max}}, \phi_{\text{max}}]$.
- You have a maximum time to reach the goal position: $t_f \leq t_f^{max}$
- The rate of change of $\phi$ is limited: $v_\phi \in [-v^{max}_ϕ ,v^{max}_ϕ ]$
Evaluation Metrics
The quality of the spacecraft’s trajectory is evaluated based on several key factors:
-
Mission Accomplishment You safely reach the goal region.
-
Planning Efficiency: We consider the average time spent in the “get_commands” method as a proxy for efficiency and quality of the planner.
-
Time Taken To Reach the Goal: The time taken to reach the goal.
-
Mass Consumption: The amount of fuel used to reach the final goal.
You can verify more precisely the function computing the final score in src/pdm4ar/exercises_def/ex09/perf_metrics.py
Data Structures
The various data structures needed for the development of the exercise can be inspected in the following files:
- RocketState & RocketCommands:
dg_commons/sim/models/rocket.py
- RocketGeometry & RocketParameters:
dg_commons/sim/models/rocket_structures.py
- SatelliteParams & PlanetParams:
src/pdm4ar/exercises_def/ex09/utils_params.py
Code Structure
The various data structures needed for the development of the exercise can be inspected in the following files:
- agent.py: Interface with the simulator.
- planner.py: SCvx skeleton.
- rocket.py: Helper file for transfer of dynamics between the planner and discretization.
- discretization.py: ZeroOrderHold and FirstOrderHold Implementation for convexification.
Hints
We developed the exercises based on the following paper (Convex Optimisation for Trajectory Generation) on SCvx, the planning method used in 2021 by spaceX to land their rocket on a moving platform in the middle of the ocean. We recommend to use such a method to solve the problem but you are free to come up with your own solution. We made available some basic skeleton structure to implement the SCvx pipeline in the planner.py. The discretization.py file provides an implementation of the ZeroOrderHold and FirstOrderHold that is used in the convexification step of the SCvx pipeline to linearize and discretize around a reference trajectory (Discretization Performance and Accuracy Analysis for the Powered Descent Guidance Problem and A Real-Time Algorithm for Non-Convex Powered Descent Guidance).
As a general and final advice try to understand the method before starting to code.
Available Optimization Tools
If your solution needs to solve an optimization problem, we have added powerful libraries in the container to solve optimization problems. For instance, scipy.optimize, PuLP, cvxpy and cvxopt. We tested cvxpy with “ECOS” and “MOSEK” as solvers for our SCvx pipeline. If you want to use other optimizers or you are not using SCvx to solve the problem, please consider that we have not tested it.