\section{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/pid/pid.c File Reference}
\label{pid_8c}\index{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/pid/pid.c@{aversive\_\-10-03-12/modules/devices/control\_\-system/filters/pid/pid.c}}
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$pid.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf pid\_\-init} (struct {\bf pid\_\-filter} $\ast$p)
\item 
void {\bf pid\_\-reset} (struct {\bf pid\_\-filter} $\ast$p)
\item 
void {\bf pid\_\-set\_\-gains} (struct {\bf pid\_\-filter} $\ast$p, int16\_\-t gp, int16\_\-t gi, int16\_\-t gd)
\item 
void {\bf pid\_\-set\_\-maximums} (struct {\bf pid\_\-filter} $\ast$p, int32\_\-t max\_\-in, int32\_\-t max\_\-I, int32\_\-t max\_\-out)
\item 
void {\bf pid\_\-set\_\-out\_\-shift} (struct {\bf pid\_\-filter} $\ast$p, uint8\_\-t out\_\-shift)
\item 
int8\_\-t {\bf pid\_\-set\_\-derivate\_\-filter} (struct {\bf pid\_\-filter} $\ast$p, uint8\_\-t nb\_\-samples)
\item 
int16\_\-t {\bf pid\_\-get\_\-gain\_\-P} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int16\_\-t {\bf pid\_\-get\_\-gain\_\-I} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int16\_\-t {\bf pid\_\-get\_\-gain\_\-D} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-max\_\-in} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-max\_\-I} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-max\_\-out} (struct {\bf pid\_\-filter} $\ast$p)
\item 
uint8\_\-t {\bf pid\_\-get\_\-out\_\-shift} (struct {\bf pid\_\-filter} $\ast$p)
\item 
uint8\_\-t {\bf pid\_\-get\_\-derivate\_\-filter} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-value\_\-I} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-value\_\-in} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-value\_\-D} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-get\_\-value\_\-out} (struct {\bf pid\_\-filter} $\ast$p)
\item 
int32\_\-t {\bf pid\_\-do\_\-filter} (void $\ast$data, int32\_\-t in)
\end{CompactItemize}


\subsection{Function Documentation}
\index{pid.c@{pid.c}!pid\_\-do\_\-filter@{pid\_\-do\_\-filter}}
\index{pid\_\-do\_\-filter@{pid\_\-do\_\-filter}!pid.c@{pid.c}}
\subsubsection[pid\_\-do\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-do\_\-filter (void $\ast$ {\em p}, \/  int32\_\-t {\em in})}\label{pid_8c_89d06bb1e6c1f4ef47057ff917bb3332}


PID process 

Definition at line 177 of file pid.c.

References pid\_\-filter::derivate\_\-nb\_\-samples, pid\_\-filter::gain\_\-D, pid\_\-filter::gain\_\-I, pid\_\-filter::gain\_\-P, pid\_\-filter::index, pid\_\-filter::integral, pid\_\-filter::max\_\-I, pid\_\-filter::max\_\-in, pid\_\-filter::max\_\-out, pid\_\-filter::out\_\-shift, gen\_\-regs::p, pid\_\-filter::prev\_\-D, pid\_\-filter::prev\_\-out, pid\_\-filter::prev\_\-samples, and S\_\-MAX.\index{pid.c@{pid.c}!pid\_\-get\_\-derivate\_\-filter@{pid\_\-get\_\-derivate\_\-filter}}
\index{pid\_\-get\_\-derivate\_\-filter@{pid\_\-get\_\-derivate\_\-filter}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-derivate\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t pid\_\-get\_\-derivate\_\-filter (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_d792f3dac5e1859cdead7a81f7bcbb82}




Definition at line 131 of file pid.c.

References pid\_\-filter::derivate\_\-nb\_\-samples.\index{pid.c@{pid.c}!pid\_\-get\_\-gain\_\-D@{pid\_\-get\_\-gain\_\-D}}
\index{pid\_\-get\_\-gain\_\-D@{pid\_\-get\_\-gain\_\-D}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-gain\_\-D]{\setlength{\rightskip}{0pt plus 5cm}int16\_\-t pid\_\-get\_\-gain\_\-D (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_4ac4dd1583edac16af970332d45e9cfb}




Definition at line 104 of file pid.c.

References pid\_\-filter::gain\_\-D.\index{pid.c@{pid.c}!pid\_\-get\_\-gain\_\-I@{pid\_\-get\_\-gain\_\-I}}
\index{pid\_\-get\_\-gain\_\-I@{pid\_\-get\_\-gain\_\-I}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-gain\_\-I]{\setlength{\rightskip}{0pt plus 5cm}int16\_\-t pid\_\-get\_\-gain\_\-I (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_8bdf0a373212b9f61879ccd3294713f9}




Definition at line 99 of file pid.c.

References pid\_\-filter::gain\_\-I.\index{pid.c@{pid.c}!pid\_\-get\_\-gain\_\-P@{pid\_\-get\_\-gain\_\-P}}
\index{pid\_\-get\_\-gain\_\-P@{pid\_\-get\_\-gain\_\-P}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-gain\_\-P]{\setlength{\rightskip}{0pt plus 5cm}int16\_\-t pid\_\-get\_\-gain\_\-P (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_2d85410b567f1c0d23846c5c212666ba}




Definition at line 94 of file pid.c.

References pid\_\-filter::gain\_\-P.\index{pid.c@{pid.c}!pid\_\-get\_\-max\_\-I@{pid\_\-get\_\-max\_\-I}}
\index{pid\_\-get\_\-max\_\-I@{pid\_\-get\_\-max\_\-I}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-max\_\-I]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-max\_\-I (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_b82b11e46072bfbe383ca199fa569a25}




Definition at line 115 of file pid.c.

References pid\_\-filter::max\_\-I.\index{pid.c@{pid.c}!pid\_\-get\_\-max\_\-in@{pid\_\-get\_\-max\_\-in}}
\index{pid\_\-get\_\-max\_\-in@{pid\_\-get\_\-max\_\-in}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-max\_\-in]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-max\_\-in (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_df90f71016e3235b409ea17c49fc8e38}




Definition at line 110 of file pid.c.

References pid\_\-filter::max\_\-in.\index{pid.c@{pid.c}!pid\_\-get\_\-max\_\-out@{pid\_\-get\_\-max\_\-out}}
\index{pid\_\-get\_\-max\_\-out@{pid\_\-get\_\-max\_\-out}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-max\_\-out]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-max\_\-out (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_681c6efadb72d0920ec4913feb366ff7}




Definition at line 120 of file pid.c.

References pid\_\-filter::max\_\-out.\index{pid.c@{pid.c}!pid\_\-get\_\-out\_\-shift@{pid\_\-get\_\-out\_\-shift}}
\index{pid\_\-get\_\-out\_\-shift@{pid\_\-get\_\-out\_\-shift}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-out\_\-shift]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t pid\_\-get\_\-out\_\-shift (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_d391c23a8c83829f5b2ba9c220be03b8}




Definition at line 126 of file pid.c.

References pid\_\-filter::out\_\-shift.\index{pid.c@{pid.c}!pid\_\-get\_\-value\_\-D@{pid\_\-get\_\-value\_\-D}}
\index{pid\_\-get\_\-value\_\-D@{pid\_\-get\_\-value\_\-D}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-value\_\-D]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-value\_\-D (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_2868e3e55536e588fd245b5635b8111d}


get previous derivate value (without gain) 

Definition at line 156 of file pid.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, and pid\_\-filter::prev\_\-D.\index{pid.c@{pid.c}!pid\_\-get\_\-value\_\-I@{pid\_\-get\_\-value\_\-I}}
\index{pid\_\-get\_\-value\_\-I@{pid\_\-get\_\-value\_\-I}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-value\_\-I]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-value\_\-I (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_f718d1a1ccbffed796644585f7c5092e}


get the sum of all nput samples since the filter initialisation 

Definition at line 136 of file pid.c.

References pid\_\-filter::integral, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{pid.c@{pid.c}!pid\_\-get\_\-value\_\-in@{pid\_\-get\_\-value\_\-in}}
\index{pid\_\-get\_\-value\_\-in@{pid\_\-get\_\-value\_\-in}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-value\_\-in]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-value\_\-in (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_62708de23da7ba3041c3a93291646d79}


get previous input value 

Definition at line 146 of file pid.c.

References pid\_\-filter::index, IRQ\_\-LOCK, IRQ\_\-UNLOCK, and pid\_\-filter::prev\_\-samples.\index{pid.c@{pid.c}!pid\_\-get\_\-value\_\-out@{pid\_\-get\_\-value\_\-out}}
\index{pid\_\-get\_\-value\_\-out@{pid\_\-get\_\-value\_\-out}!pid.c@{pid.c}}
\subsubsection[pid\_\-get\_\-value\_\-out]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t pid\_\-get\_\-value\_\-out (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_3a707de3774bbc97a7a854f042ae4159}


get previous output value 

Definition at line 166 of file pid.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, and pid\_\-filter::prev\_\-out.\index{pid.c@{pid.c}!pid\_\-init@{pid\_\-init}}
\index{pid\_\-init@{pid\_\-init}!pid.c@{pid.c}}
\subsubsection[pid\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void pid\_\-init (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_fe520a872e38b7694c709a76a0996510}


this function will initialize all fieds of pid structure to 0 

Definition at line 27 of file pid.c.

References pid\_\-filter::derivate\_\-nb\_\-samples, pid\_\-filter::gain\_\-P, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{pid.c@{pid.c}!pid\_\-reset@{pid\_\-reset}}
\index{pid\_\-reset@{pid\_\-reset}!pid.c@{pid.c}}
\subsubsection[pid\_\-reset]{\setlength{\rightskip}{0pt plus 5cm}void pid\_\-reset (struct {\bf pid\_\-filter} $\ast$ {\em p})}\label{pid_8c_5acd0da91d6195aeaad2ddf17d35b746}


this function will initialize all fieds of pid structure to 0, except configuration 

Definition at line 39 of file pid.c.

References pid\_\-filter::integral, IRQ\_\-LOCK, IRQ\_\-UNLOCK, pid\_\-filter::prev\_\-D, pid\_\-filter::prev\_\-out, and pid\_\-filter::prev\_\-samples.\index{pid.c@{pid.c}!pid\_\-set\_\-derivate\_\-filter@{pid\_\-set\_\-derivate\_\-filter}}
\index{pid\_\-set\_\-derivate\_\-filter@{pid\_\-set\_\-derivate\_\-filter}!pid.c@{pid.c}}
\subsubsection[pid\_\-set\_\-derivate\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}int8\_\-t pid\_\-set\_\-derivate\_\-filter (struct {\bf pid\_\-filter} $\ast$ {\em p}, \/  uint8\_\-t {\em nb\_\-samples})}\label{pid_8c_6d6a4e5e33fa48074ae4e0f9a42ef6fc}




Definition at line 78 of file pid.c.

References pid\_\-filter::derivate\_\-nb\_\-samples, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{pid.c@{pid.c}!pid\_\-set\_\-gains@{pid\_\-set\_\-gains}}
\index{pid\_\-set\_\-gains@{pid\_\-set\_\-gains}!pid.c@{pid.c}}
\subsubsection[pid\_\-set\_\-gains]{\setlength{\rightskip}{0pt plus 5cm}void pid\_\-set\_\-gains (struct {\bf pid\_\-filter} $\ast$ {\em p}, \/  int16\_\-t {\em gp}, \/  int16\_\-t {\em gi}, \/  int16\_\-t {\em gd})}\label{pid_8c_3c6b704dbbf2e38765b9813674ab52f5}




Definition at line 50 of file pid.c.

References pid\_\-filter::gain\_\-D, pid\_\-filter::gain\_\-I, pid\_\-filter::gain\_\-P, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{pid.c@{pid.c}!pid\_\-set\_\-maximums@{pid\_\-set\_\-maximums}}
\index{pid\_\-set\_\-maximums@{pid\_\-set\_\-maximums}!pid.c@{pid.c}}
\subsubsection[pid\_\-set\_\-maximums]{\setlength{\rightskip}{0pt plus 5cm}void pid\_\-set\_\-maximums (struct {\bf pid\_\-filter} $\ast$ {\em p}, \/  int32\_\-t {\em max\_\-in}, \/  int32\_\-t {\em max\_\-I}, \/  int32\_\-t {\em max\_\-out})}\label{pid_8c_a5839e74e3f2c8e1d43d095486aec2bb}




Definition at line 60 of file pid.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, pid\_\-filter::max\_\-I, pid\_\-filter::max\_\-in, and pid\_\-filter::max\_\-out.\index{pid.c@{pid.c}!pid\_\-set\_\-out\_\-shift@{pid\_\-set\_\-out\_\-shift}}
\index{pid\_\-set\_\-out\_\-shift@{pid\_\-set\_\-out\_\-shift}!pid.c@{pid.c}}
\subsubsection[pid\_\-set\_\-out\_\-shift]{\setlength{\rightskip}{0pt plus 5cm}void pid\_\-set\_\-out\_\-shift (struct {\bf pid\_\-filter} $\ast$ {\em p}, \/  uint8\_\-t {\em out\_\-shift})}\label{pid_8c_2d77729eb8ffce6e87407702cf829895}




Definition at line 70 of file pid.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, and pid\_\-filter::out\_\-shift.