# 11.6. Low-level interface: Spacecraft Rendezvous¶

## 11.6.1. Introduction¶

This example uses the concepts described in the subsections HOW TO: Implement an MPC Controller with a Time-Varying Dynamics and How to Implement 1-Norm and Infinity-Norm Cost Functions.

The goal is to design a controller to perform a spacecraft rendezvous operation, where a controlled chaser spacecraft is performing rendezvous with a passive target that is orbiting around Mars. Using a time-varying prediction model allows to perform spacecraft maneuvers in elliptical orbits and allows the controller to be updated when the are changes in the system parameters or control objectives. This example is based on the models described in [HarMac14] and the references therein.

## 11.6.2. Model¶

The Yamanaka-Ankersen (Y-A) equations are used to describe the dynamics, where the six states x of the system represent the relative position and velocity of the chaser with respect to the target in the three dimensions. These equations apply in elliptical orbits, but are time-varying in terms of the true anomaly, \(v\), of the target, i.e. the model is given by

and the requirement is that the state at the end of the horizon is at the target. The plant input is modeled as an impulsive change in velocity, such that

You can download a matlab code here with example simulation
`here`

.
The file `YA_A_matrix.m`

computes the time-varying matrices for the prediction horizon given the anomaly \(v\).

## 11.6.3. Constraints¶

The three impulsive control inputs can give a maximum change in velocity of 5 meters per second along each axis. In addition, the chaser spacecraft is required to remain within a cone of vision of 20 degrees from the target and must not go behind the target to facilitate the docking maneuver.

## 11.6.4. Objective¶

The goal of the controller is to balance the following objectives:

the chaser should be always as close as possible to the target,

use as little fuel as possible to get there.

The second objective is more important, hence it is weighed higher. We consider two types of cost functions: one where all the terms are weighed using standard quadratic penalties; and one where the inputs are penalized using the 1-norm, which better reflects the propellant consumption being directly proportional to delivered thrust and also attempts to minimize the use of the actuators. In order to implement the 1-norm cost we need to add slack variables and additional constraints as described in How to Implement 1-Norm and Infinity-Norm Cost Functions.

The following code shows how to generate an MPC controller for the spacecraft rendezvous problem with a time-varying model and a 1-norm penalty on the actuators.

```
%% MPC with Preview
% FORCESPRO multistage form
% assume variable ordering zi = [u{i-1}; x{i}, eu{i-1}] for i=1...N
% Parameters: First Eq. RHS
parameter(1) = newParam('minusA_times_x0’,1,'eq.c’);
stages = MultistageProblem(N);
for i = 1:N
% dimension
stages(i).dims.n = nx+2*nu; % number of stage variables
stages(i).dims.r = nx; % number of equality constraints
stages(i).dims.l = nu; % number of lower bounds
stages(i).dims.u = nu; % number of upper bounds
stages(i).dims.p = 3+2*nu; % number of polytopic constraints
% cost
stages(i).cost.H = blkdiag(zeros(nu),Q,zeros(nu));
stages(i).cost.f = [zeros(nu,1); -Q*xs; ones(nu,1)];
% lower bounds
stages(i).ineq.b.lbidx = 1:nu; % lower bound acts on these indices
stages(i).ineq.b.lb = umin*ones(4,1); % lower bound for the input signal
% upper bounds
stages(i).ineq.b.ubidx = 1:nu; % upper bound acts on these indices
stages(i).ineq.b.ub = umax*ones(4,1); % upper bound for the input signal
% polytopic bounds
stages(i).ineq.p.A = [ zeros(3,nu), Hx, zeros(3,nu); ...
R, zeros(nu,nx), -eye(nu); ...
-R, zeros(nu,nx), -eye(nu)];
stages(i).ineq.p.b = [ hx; R*us; -R*us ];
% equality constraints
if( i < N )
params(end+1) = newParam(['C_',num2str(i)],i,'eq.C');
end
params(end+1) = newParam(['D_',num2str(i)],i,'eq.D');
if( i > 1 )
params(end+1) = newParam(['pre’,num2str(i+1),’_w’],i+1,'eq.c’);
end
end
```

## 11.6.5. Spacecraft Rendezvous Maneuvers with and without 1-Norm Cost¶

The simulation describes a rendezvous maneuver were the chaser starts 15km away from the target spacecraft and the goal is to approach the target to within 1000 meter distance, while respecting the constraints, to start the docking maneuver. The target is modeled as being in a Keplerian orbit around Mars with an orbital radius of 3,600,000 meters. The controller sampling time is 200s but the target and chaser dynamics are simulated in intervals of 1s for illustration purposes. The plots in Figure 11.25 illustrates the behavior of the controlled spacecraft with standard quadratic cost, while the plots in Figure 11.26 shows the behavior of the controller when the quadratic cost on the actuators is swapped with a 1-norm penalty. Notice the sparsity in the actuation commands - the thrusters are only engaged when necessary to keep the spacecraft within the cone of visibility of the target.

Hartley, E. N.; Maciejowski, J. M.: Field programmable gate array based predictive control system for spacecraft rendezvous in elliptical orbits. In Optimal Control Applications and Methods, Mar 2014