\section{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/quadramp\_\-derivate/quadramp\_\-derivate.h File Reference}
\label{quadramp__derivate_8h}\index{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/quadramp\_\-derivate/quadramp\_\-derivate.h@{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/quadramp\_\-derivate/quadramp\_\-derivate.h}}
{\tt \#include $<$aversive.h$>$}\par
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf quadramp\_\-derivate\_\-filter}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf quadramp\_\-derivate\_\-init} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$r)
\item 
void {\bf quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$q, uint16\_\-t gain\_\-anticipation)
\item 
void {\bf quadramp\_\-derivate\_\-set\_\-goal\_\-window} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$q, uint32\_\-t goal\_\-window)
\item 
void {\bf quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$q, uint32\_\-t var\_\-2nd\_\-ord\_\-pos, uint32\_\-t var\_\-2nd\_\-ord\_\-neg)
\item 
void {\bf quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$q, uint32\_\-t var\_\-1st\_\-ord\_\-pos, uint32\_\-t var\_\-1st\_\-ord\_\-neg)
\item 
void {\bf quadramp\_\-derivate\_\-set\_\-divisor} (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$q, uint8\_\-t divisor)
\item 
int32\_\-t {\bf quadramp\_\-derivate\_\-do\_\-filter} (void $\ast$data, int32\_\-t in)
\end{CompactItemize}


\subsection{Function Documentation}
\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-do\_\-filter@{quadramp\_\-derivate\_\-do\_\-filter}}
\index{quadramp\_\-derivate\_\-do\_\-filter@{quadramp\_\-derivate\_\-do\_\-filter}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-do\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t quadramp\_\-derivate\_\-do\_\-filter (void $\ast$ {\em data}, \/  int32\_\-t {\em in\_\-position})}\label{quadramp__derivate_8h_dbd33dfb0272182848af64ce05547eb2}


Process the ramp

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em data}]should be a (struct \doxyref{quadramp\_\-filter}{p.}{structquadramp__filter} $\ast$) pointer \item[{\em in}]is the input of the filter\end{description}
\end{Desc}
the input is a position (relative to goal) The output of the function is a speed, which is typically fed as consign to a speed PID. Beware !! the speed unit at the output must absolutely be the same that the derivate of the input, which means that the frequency of the quadramp\_\-derivate\_\-do\_\-filter must be the same than that of the speed PID.

Process the ramp

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em data}]should be a (struct \doxyref{quadramp\_\-derivate\_\-filter}{p.}{structquadramp__derivate__filter} $\ast$) pointer \item[{\em in}]is the input of the filter \end{description}
\end{Desc}


sampling divisor this is a state machine who executes the algorithm only one time out of \char`\"{}divisor\char`\"{}

compensation of the inversion before the input (inversion of the control system where \doxyref{error}{p.}{structerror} = consign - feedback)

limitation of this speed, due to overflows, and calculations based on theoretical max value and also the peak created when the position\_\-consign changes

calculation of the pivot position. when this position is atteined, it is just the right time to begin to deccelerate. The length to this position is given by a linear decceleration to 0 : x = speed�/ (2 $\ast$ acceleration)

this is the heart of the \doxyref{trajectory}{p.}{structtrajectory} generation. Pretty simple but indeed unstable, because of this corresponds to an infinite gain, in the following equation : acceleration\_\-consign = ( position\_\-pivot - in\_\-position ) $\ast$ gain

In fact this unstability is erased by the fact that the acc value is nearly always limited

integration and limitation of the acceleration to obtain a speed consign

creation of an end arrival window. This is done to stop the oscillations when the goal is achieved.

refresh the memories 

Definition at line 106 of file quadramp\_\-derivate.c.

References ABS, quadramp\_\-derivate\_\-filter::divisor, quadramp\_\-derivate\_\-filter::divisor\_\-counter, quadramp\_\-derivate\_\-filter::gain\_\-anticipation, quadramp\_\-derivate\_\-filter::goal\_\-window, MAX, MIN, quadramp\_\-derivate\_\-filter::pivot, quadramp\_\-derivate\_\-filter::previous\_\-in\_\-position, quadramp\_\-derivate\_\-filter::previous\_\-out\_\-speed, quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-neg, quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-pos, quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-neg, and quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-pos.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-init@{quadramp\_\-derivate\_\-init}}
\index{quadramp\_\-derivate\_\-init@{quadramp\_\-derivate\_\-init}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-init (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em r})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_97df00d69d9ea521f526a85e31a25c23}


Initialization of the filter as this filter has always an infinite gain, it is initilized with an integrative infinite gain limited by 1 

Definition at line 28 of file quadramp\_\-derivate.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, quadramp\_\-derivate\_\-filter::previous\_\-in\_\-position, quadramp\_\-derivate\_\-filter::previous\_\-out\_\-speed, quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-neg, quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-pos, quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-neg, and quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-pos.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars@{quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars}}
\index{quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars@{quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-set\_\-1st\_\-order\_\-vars (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em q}, \/  uint32\_\-t {\em var\_\-1st\_\-ord\_\-pos}, \/  uint32\_\-t {\em var\_\-1st\_\-ord\_\-neg})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_7add017b6e3cd98ead724ae064877460}




Definition at line 77 of file quadramp\_\-derivate.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-neg, and quadramp\_\-derivate\_\-filter::var\_\-1st\_\-ord\_\-pos.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars@{quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars}}
\index{quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars@{quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-set\_\-2nd\_\-order\_\-vars (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em q}, \/  uint32\_\-t {\em var\_\-2nd\_\-ord\_\-pos}, \/  uint32\_\-t {\em var\_\-2nd\_\-ord\_\-neg})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_0f9035ebad20ebf69979be8a300e0ed8}


as in the quadramp, we can set here the maximum speed (1st order) and maximum acceleration (2nd order) and this in both directions, positive, and negative. 

Definition at line 68 of file quadramp\_\-derivate.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-neg, and quadramp\_\-derivate\_\-filter::var\_\-2nd\_\-ord\_\-pos.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-set\_\-divisor@{quadramp\_\-derivate\_\-set\_\-divisor}}
\index{quadramp\_\-derivate\_\-set\_\-divisor@{quadramp\_\-derivate\_\-set\_\-divisor}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-set\_\-divisor]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-set\_\-divisor (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em q}, \/  uint8\_\-t {\em divisor})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_a9bed278fc6a6048eeb3d0d031ec6171}


this sets a divisor. (executing only 1 time of n) this permits to make a bigger resolution on the speed and acceleration consign.

default is 1. When using n$>$1, the new acceleration (2nd order) unit is divided by n (increasing precision) The speed remains at the same unit.

The drawback is that the speed will have the forma of a stair, so do not abuse of it ! 

Definition at line 87 of file quadramp\_\-derivate.c.

References quadramp\_\-derivate\_\-filter::divisor, quadramp\_\-derivate\_\-filter::divisor\_\-counter, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation@{quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation}}
\index{quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation@{quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-set\_\-gain\_\-anticipation (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em q}, \/  uint16\_\-t {\em gain\_\-anticipation})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_68857d0203db9cdc270fad4fa8e7f122}


set the anticipation value. This gain is a fixed point value that will be divided by 256. set this gain to have enough anticipation, so the goal is not atteined with too much speed. too much, and the goal will be overlooked, and the system will oscillate. Too less, and the goal will be atteined with speed, and the goal window will eventually cutoff brutally 

Definition at line 52 of file quadramp\_\-derivate.c.

References quadramp\_\-derivate\_\-filter::gain\_\-anticipation, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{quadramp\_\-derivate.h@{quadramp\_\-derivate.h}!quadramp\_\-derivate\_\-set\_\-goal\_\-window@{quadramp\_\-derivate\_\-set\_\-goal\_\-window}}
\index{quadramp\_\-derivate\_\-set\_\-goal\_\-window@{quadramp\_\-derivate\_\-set\_\-goal\_\-window}!quadramp_derivate.h@{quadramp\_\-derivate.h}}
\subsubsection[quadramp\_\-derivate\_\-set\_\-goal\_\-window]{\setlength{\rightskip}{0pt plus 5cm}void quadramp\_\-derivate\_\-set\_\-goal\_\-window (struct {\bf quadramp\_\-derivate\_\-filter} $\ast$ {\em q}, \/  uint32\_\-t {\em goal\_\-window})\hspace{0.3cm}{\tt  [inline]}}\label{quadramp__derivate_8h_d8f8fad9cff7dc5c402b15bb82a1027a}


goal window is a shutdown of the integration when the goal is atteined. this aims to get rid of the very little oscillations when immobile 

Definition at line 60 of file quadramp\_\-derivate.c.

References quadramp\_\-derivate\_\-filter::goal\_\-window, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.