\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage[legalpaper, margin=1.6in]{geometry}

\title{MS PI controller explanation}
\author{Cassandre Contré, Simon Van Mulders}
\date{October 2024}

\begin{document}

\maketitle

\noindent Quick clarification of the PI controller of the gradient-based (MS) model implemented in RAPTOR, with a little help from \citep{Haugen2010}. 
\\

\noindent We start from eq. 2.7 of \cite{Anna}, generalised to $\mu \in \{\mu_{ne},\mu_{Te}\}$: 
\begin{equation}
    \label{eq:continuous_form}
    \mu = \mu^{\text{ff}}(t_k) + K_p \cdot e(t) + K_i \cdot \int^{\delta t} e(t) dt
\end{equation}

\noindent We discretise eq. \ref{eq:continuous_form} using Euler’s Backward differentiation method, namely: 

\begin{equation}
    \dot{x}(t_k) = \frac{x(t_k) - x(t_{k-1})}{\Delta t}
\end{equation}

\noindent The key thing here (which is also the confusing one) is that we actually want to compute the incremental control value: 

\begin{equation}
    \Delta \mu(t_k) = \mu(t_k) - \mu(t_{k-1}) = \Delta t \cdot \dot{\mu}(t_k),
\end{equation}

\noindent such that one must take the time derivative of eq. \ref{eq:continuous_form}:

\begin{equation}
\begin{split}
    \dot{\mu}(t_k) &= \dot{\mu}^{\text{ff}}(t_k) + K_p \dot{e}(t_k) + K_i e(t_k) \\
    & = \frac{\mu^{\text{ff}}(t_k)-\mu^{\text{ff}}(t_{k-1})}{\Delta t} + K_p \cdot \frac{e(t_k)-e(t_{k-1})}{\Delta t} + K_i \cdot e(t_k). 
\end{split}
\end{equation}
\noindent Hence, by multiplying $\dot{\mu}(t_k)$ with the time step $\Delta t$ we get the $\mu$ increment: 
\begin{equation}
    \Delta \mu = \Delta \mu^{\text{ff}}(t_k) + \Delta \mu^{\text{fb}}(t_k)
\end{equation}
\noindent such that, for each time iteration: 
\begin{equation}
    \mu(t_k) = \mu(t_{k-1}) + \Delta \mu^{\text{ff}}(t_k) + \Delta \mu^{\text{fb}}(t_k)
\end{equation}
\noindent with 
\begin{equation}
    \Delta \mu^{\text{ff}}(t_k) = \mu^{\text{ff}}(t_k)-\mu^{\text{ff}}(t_{k-1})
\end{equation} 

\noindent and: 
\begin{equation}
    \Delta \mu^{\text{fb}}(t_k) = K_p \cdot \left [ e(t_k)-e(t_{k-1})\right ]  + K_i \cdot \Delta t \cdot e(t_k)
\end{equation}

In practice in the code, the errors are computed from the previous state estimate $x(t_{k-1})$ and the $\mu$ value computed at time iteration $k$ is $\mu(t_{k-1})$, using the error $e(t_{k-1})$. In chi\_MS.m and vpdn\_MS.m, the errors are expressed respectively: 
\begin{equation}
\begin{align*} 
    e^{T_e}(t_{k-1}) &= H_e^{\text{ref}}(t_{k-1}) - H_e^{\text{eff}}(t_{k-1})  \\
    e^{n_e}(t_{k-1}) &= n_{e,l}^{\text{ref}}(t_{k-1}) - n_{e,l}^{\text{eff}}(t_{k-1}) 
\end{align*} 
\end{equation}

\noindent Final note: in the code, the $g_{i}$ gain is equivalent to $K_{i}\Delta t$. 
% & \text{in chi_MS.m}
% & \text{in vpdn_MS.m}
\bibliographystyle{abbrvnat}
%\bibliographystyle{ieeetr}
\bibliography{biblio}

\end{document}
