\section{aversive\_\-10-03-12/modules/devices/robot/robot\_\-system/robot\_\-system.h File Reference}
\label{robot__system_8h}\index{aversive\_\-10-03-12/modules/devices/robot/robot\_\-system/robot\_\-system.h@{aversive\_\-10-03-12/modules/devices/robot/robot\_\-system/robot\_\-system.h}}
{\tt \#include $<$aversive.h$>$}\par
{\tt \#include $<$f64.h$>$}\par
{\tt \#include \char`\"{}angle\_\-distance.h\char`\"{}}\par
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf robot\_\-system}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf RS\_\-USE\_\-EXT}~1
\item 
\#define {\bf RS\_\-IGNORE\_\-EXT\_\-GAIN}~2
\item 
\#define {\bf RS\_\-IGNORE\_\-MOT\_\-GAIN}~4
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf rs\_\-init} (struct {\bf robot\_\-system} $\ast$)
\item 
void {\bf rs\_\-set\_\-left\_\-pwm} (struct {\bf robot\_\-system} $\ast$rs, void($\ast$left\_\-pwm)(void $\ast$, int32\_\-t), void $\ast$left\_\-pwm\_\-param)
\item 
void {\bf rs\_\-set\_\-right\_\-pwm} (struct {\bf robot\_\-system} $\ast$rs, void($\ast$right\_\-pwm)(void $\ast$, int32\_\-t), void $\ast$right\_\-pwm\_\-param)
\item 
void {\bf rs\_\-set\_\-left\_\-ext\_\-encoder} (struct {\bf robot\_\-system} $\ast$rs, int32\_\-t($\ast$left\_\-ext\_\-encoder)(void $\ast$), void $\ast$left\_\-ext\_\-encoder\_\-param, double gain)
\item 
void {\bf rs\_\-set\_\-right\_\-ext\_\-encoder} (struct {\bf robot\_\-system} $\ast$rs, int32\_\-t($\ast$right\_\-ext\_\-encoder)(void $\ast$), void $\ast$right\_\-ext\_\-encoder\_\-param, double gain)
\item 
void {\bf rs\_\-set\_\-angle} (void $\ast$rs, int32\_\-t angle)
\item 
void {\bf rs\_\-set\_\-distance} (void $\ast$rs, int32\_\-t distance)
\item 
int32\_\-t {\bf rs\_\-get\_\-angle} (void $\ast$rs)
\item 
int32\_\-t {\bf rs\_\-get\_\-distance} (void $\ast$rs)
\item 
int32\_\-t {\bf rs\_\-get\_\-ext\_\-angle} (void $\ast$rs)
\item 
int32\_\-t {\bf rs\_\-get\_\-ext\_\-distance} (void $\ast$rs)
\item 
int32\_\-t {\bf rs\_\-get\_\-ext\_\-left} (void $\ast$rs)
\item 
int32\_\-t {\bf rs\_\-get\_\-ext\_\-right} (void $\ast$rs)
\item 
void {\bf rs\_\-update} (void $\ast$rs)
\item 
void {\bf rs\_\-set\_\-flags} (struct {\bf robot\_\-system} $\ast$rs, uint8\_\-t flags)
\end{CompactItemize}


\subsection{Define Documentation}
\index{robot\_\-system.h@{robot\_\-system.h}!RS\_\-IGNORE\_\-EXT\_\-GAIN@{RS\_\-IGNORE\_\-EXT\_\-GAIN}}
\index{RS\_\-IGNORE\_\-EXT\_\-GAIN@{RS\_\-IGNORE\_\-EXT\_\-GAIN}!robot_system.h@{robot\_\-system.h}}
\subsubsection[RS\_\-IGNORE\_\-EXT\_\-GAIN]{\setlength{\rightskip}{0pt plus 5cm}\#define RS\_\-IGNORE\_\-EXT\_\-GAIN~2}\label{robot__system_8h_7f28f3eed68472b1defb359c7ba2dec9}




Definition at line 39 of file robot\_\-system.h.

Referenced by rs\_\-update().\index{robot\_\-system.h@{robot\_\-system.h}!RS\_\-IGNORE\_\-MOT\_\-GAIN@{RS\_\-IGNORE\_\-MOT\_\-GAIN}}
\index{RS\_\-IGNORE\_\-MOT\_\-GAIN@{RS\_\-IGNORE\_\-MOT\_\-GAIN}!robot_system.h@{robot\_\-system.h}}
\subsubsection[RS\_\-IGNORE\_\-MOT\_\-GAIN]{\setlength{\rightskip}{0pt plus 5cm}\#define RS\_\-IGNORE\_\-MOT\_\-GAIN~4}\label{robot__system_8h_b3687ffab185ec15ef95ba37d86fe702}




Definition at line 40 of file robot\_\-system.h.

Referenced by rs\_\-update().\index{robot\_\-system.h@{robot\_\-system.h}!RS\_\-USE\_\-EXT@{RS\_\-USE\_\-EXT}}
\index{RS\_\-USE\_\-EXT@{RS\_\-USE\_\-EXT}!robot_system.h@{robot\_\-system.h}}
\subsubsection[RS\_\-USE\_\-EXT]{\setlength{\rightskip}{0pt plus 5cm}\#define RS\_\-USE\_\-EXT~1}\label{robot__system_8h_1c302541ee135c7b98c3c36c4b8149c1}


The goal of this module is to provide an interface to motor and encoders of the robot. This module provide a function that returns the value of virtual encoders containing distance and angle. It also allow the user to command virtual angle and distance PWMs. 

Definition at line 38 of file robot\_\-system.h.

Referenced by rs\_\-update().

\subsection{Function Documentation}
\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-angle@{rs\_\-get\_\-angle}}
\index{rs\_\-get\_\-angle@{rs\_\-get\_\-angle}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-angle]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-angle (void $\ast$ {\em data})}\label{robot__system_8h_ef14118c3f758d94d21260e2aeba991b}


get the virtual angle according to real encoders value. 

Definition at line 238 of file robot\_\-system.c.

References rs\_\-polar::angle, IRQ\_\-LOCK, IRQ\_\-UNLOCK, and robot\_\-system::virtual\_\-encoders.

Referenced by \_\-\_\-trajectory\_\-goto\_\-d\_\-a\_\-rel(), and trajectory\_\-hardstop().\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-distance@{rs\_\-get\_\-distance}}
\index{rs\_\-get\_\-distance@{rs\_\-get\_\-distance}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-distance]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-distance (void $\ast$ {\em data})}\label{robot__system_8h_c3b6b429631c6a36ee36ff6349f3f39f}


get the virtual distance according to real encoders value. 

Definition at line 253 of file robot\_\-system.c.

References rs\_\-polar::distance, IRQ\_\-LOCK, IRQ\_\-UNLOCK, and robot\_\-system::virtual\_\-encoders.

Referenced by \_\-\_\-trajectory\_\-goto\_\-d\_\-a\_\-rel(), and trajectory\_\-hardstop().\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-ext\_\-angle@{rs\_\-get\_\-ext\_\-angle}}
\index{rs\_\-get\_\-ext\_\-angle@{rs\_\-get\_\-ext\_\-angle}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-ext\_\-angle]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-ext\_\-angle (void $\ast$ {\em rs})}\label{robot__system_8h_65527a9b723727047cf2c64914a49725}


get the angle according to ext encoders value. 

Definition at line 265 of file robot\_\-system.c.

References rs\_\-polar::angle, IRQ\_\-LOCK, IRQ\_\-UNLOCK, and robot\_\-system::pext\_\-prev.

Referenced by position\_\-manage(), and position\_\-use\_\-ext().\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-ext\_\-distance@{rs\_\-get\_\-ext\_\-distance}}
\index{rs\_\-get\_\-ext\_\-distance@{rs\_\-get\_\-ext\_\-distance}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-ext\_\-distance]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-ext\_\-distance (void $\ast$ {\em rs})}\label{robot__system_8h_101bba271445e40ece16079cf423ff2b}


get the distance according to ext encoders value. 

Definition at line 277 of file robot\_\-system.c.

References rs\_\-polar::distance, IRQ\_\-LOCK, IRQ\_\-UNLOCK, and robot\_\-system::pext\_\-prev.

Referenced by position\_\-manage(), and position\_\-use\_\-ext().\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-ext\_\-left@{rs\_\-get\_\-ext\_\-left}}
\index{rs\_\-get\_\-ext\_\-left@{rs\_\-get\_\-ext\_\-left}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-ext\_\-left]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-ext\_\-left (void $\ast$ {\em rs})}\label{robot__system_8h_657ab7cf0647ae3736be39ac7a2340d4}




Definition at line 315 of file robot\_\-system.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, rs\_\-wheels::left, and robot\_\-system::wext\_\-prev.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-get\_\-ext\_\-right@{rs\_\-get\_\-ext\_\-right}}
\index{rs\_\-get\_\-ext\_\-right@{rs\_\-get\_\-ext\_\-right}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-get\_\-ext\_\-right]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t rs\_\-get\_\-ext\_\-right (void $\ast$ {\em rs})}\label{robot__system_8h_76850c9999a475e9ca0a1d104147a181}




Definition at line 327 of file robot\_\-system.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, rs\_\-wheels::right, and robot\_\-system::wext\_\-prev.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-init@{rs\_\-init}}
\index{rs\_\-init@{rs\_\-init}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-init (struct {\bf robot\_\-system} $\ast$ {\em rs})}\label{robot__system_8h_17e8c203380e88c08bdedeed2fb1d1d0}


Set the structure to 0 

Definition at line 87 of file robot\_\-system.c.

References IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-angle@{rs\_\-set\_\-angle}}
\index{rs\_\-set\_\-angle@{rs\_\-set\_\-angle}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-angle]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-angle (void $\ast$ {\em data}, \/  int32\_\-t {\em angle})}\label{robot__system_8h_48c8a0fae757561e1d897edbb64d7e3b}


set the real pwms according to the specified angle (it also depends on the last distance command sent) 

Definition at line 193 of file robot\_\-system.c.

References rs\_\-polar::angle, rs\_\-polar::distance, IRQ\_\-LOCK, IRQ\_\-UNLOCK, rs\_\-wheels::left, robot\_\-system::left\_\-pwm, robot\_\-system::left\_\-pwm\_\-param, rs\_\-wheels::right, robot\_\-system::right\_\-pwm, robot\_\-system::right\_\-pwm\_\-param, rs\_\-get\_\-wheels\_\-from\_\-polar(), and robot\_\-system::virtual\_\-pwm.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-distance@{rs\_\-set\_\-distance}}
\index{rs\_\-set\_\-distance@{rs\_\-set\_\-distance}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-distance]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-distance (void $\ast$ {\em data}, \/  int32\_\-t {\em distance})}\label{robot__system_8h_fdd8636f5f15b2bc46c6e3a584b07880}


set the real pwms according to the specified distance (it also depends on the last angle command sent) 

Definition at line 216 of file robot\_\-system.c.

References rs\_\-polar::angle, rs\_\-polar::distance, IRQ\_\-LOCK, IRQ\_\-UNLOCK, rs\_\-wheels::left, robot\_\-system::left\_\-pwm, robot\_\-system::left\_\-pwm\_\-param, rs\_\-wheels::right, robot\_\-system::right\_\-pwm, robot\_\-system::right\_\-pwm\_\-param, rs\_\-get\_\-wheels\_\-from\_\-polar(), and robot\_\-system::virtual\_\-pwm.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-flags@{rs\_\-set\_\-flags}}
\index{rs\_\-set\_\-flags@{rs\_\-set\_\-flags}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-flags]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-flags (struct {\bf robot\_\-system} $\ast$ {\em rs}, \/  uint8\_\-t {\em flags})}\label{robot__system_8h_6d14c1ce2eb4f198bfae59645c8a33a2}




Definition at line 365 of file robot\_\-system.c.

References robot\_\-system::flags, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-left\_\-ext\_\-encoder@{rs\_\-set\_\-left\_\-ext\_\-encoder}}
\index{rs\_\-set\_\-left\_\-ext\_\-encoder@{rs\_\-set\_\-left\_\-ext\_\-encoder}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-left\_\-ext\_\-encoder]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-left\_\-ext\_\-encoder (struct {\bf robot\_\-system} $\ast$ {\em rs}, \/  int32\_\-t($\ast$)(void $\ast$) {\em left\_\-ext\_\-encoder}, \/  void $\ast$ {\em left\_\-ext\_\-encoder\_\-param}, \/  double {\em gain})}\label{robot__system_8h_23227b9839b6a37feff26ebf6afcd91a}


define left external encoder function and param 

Definition at line 162 of file robot\_\-system.c.

References f64\_\-from\_\-double(), IRQ\_\-LOCK, IRQ\_\-UNLOCK, robot\_\-system::left\_\-ext\_\-encoder, robot\_\-system::left\_\-ext\_\-encoder\_\-param, and robot\_\-system::left\_\-ext\_\-gain.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-left\_\-pwm@{rs\_\-set\_\-left\_\-pwm}}
\index{rs\_\-set\_\-left\_\-pwm@{rs\_\-set\_\-left\_\-pwm}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-left\_\-pwm]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-left\_\-pwm (struct {\bf robot\_\-system} $\ast$ {\em rs}, \/  void($\ast$)(void $\ast$, int32\_\-t) {\em left\_\-pwm}, \/  void $\ast$ {\em left\_\-pwm\_\-param})}\label{robot__system_8h_43c7d80efc22c50da3aeceb77ed3b14d}


define left PWM function and param 

Definition at line 112 of file robot\_\-system.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, robot\_\-system::left\_\-pwm, and robot\_\-system::left\_\-pwm\_\-param.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-right\_\-ext\_\-encoder@{rs\_\-set\_\-right\_\-ext\_\-encoder}}
\index{rs\_\-set\_\-right\_\-ext\_\-encoder@{rs\_\-set\_\-right\_\-ext\_\-encoder}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-right\_\-ext\_\-encoder]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-right\_\-ext\_\-encoder (struct {\bf robot\_\-system} $\ast$ {\em rs}, \/  int32\_\-t($\ast$)(void $\ast$) {\em right\_\-ext\_\-encoder}, \/  void $\ast$ {\em right\_\-ext\_\-encoder\_\-param}, \/  double {\em gain})}\label{robot__system_8h_128cb1856febb1088b7681e914474946}


define right external encoder function and param 

Definition at line 175 of file robot\_\-system.c.

References f64\_\-from\_\-double(), IRQ\_\-LOCK, IRQ\_\-UNLOCK, robot\_\-system::right\_\-ext\_\-encoder, robot\_\-system::right\_\-ext\_\-encoder\_\-param, and robot\_\-system::right\_\-ext\_\-gain.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-set\_\-right\_\-pwm@{rs\_\-set\_\-right\_\-pwm}}
\index{rs\_\-set\_\-right\_\-pwm@{rs\_\-set\_\-right\_\-pwm}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-set\_\-right\_\-pwm]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-set\_\-right\_\-pwm (struct {\bf robot\_\-system} $\ast$ {\em rs}, \/  void($\ast$)(void $\ast$, int32\_\-t) {\em right\_\-pwm}, \/  void $\ast$ {\em right\_\-pwm\_\-param})}\label{robot__system_8h_f888556ca3099a4f7f17ab211a4d743b}


define right PWM function and param 

Definition at line 123 of file robot\_\-system.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, robot\_\-system::right\_\-pwm, and robot\_\-system::right\_\-pwm\_\-param.\index{robot\_\-system.h@{robot\_\-system.h}!rs\_\-update@{rs\_\-update}}
\index{rs\_\-update@{rs\_\-update}!robot_system.h@{robot\_\-system.h}}
\subsubsection[rs\_\-update]{\setlength{\rightskip}{0pt plus 5cm}void rs\_\-update (void $\ast$ {\em data})}\label{robot__system_8h_249ef2551ae1055fed9c1db52ef9e423}


Read the encoders, and update internal virtual counters. Call this function is needed before reading the virtual encoders. The program will decide if it the external encoders or the motor encoders are taken in account (depending on flags, but not yet)

Read the encoders, and update internal virtual counters. Call this function is needed before reading the virtual encoders.The program will decide if it the external encoders or the motor encoders are taken in account (depending on flags, but not yet) 

Definition at line 380 of file robot\_\-system.c.

References rs\_\-polar::angle, rs\_\-polar::distance, f64\_\-from\_\-lsb(), f64\_\-msb\_\-mul(), robot\_\-system::flags, IRQ\_\-LOCK, IRQ\_\-UNLOCK, rs\_\-wheels::left, robot\_\-system::left\_\-ext\_\-encoder, robot\_\-system::left\_\-ext\_\-encoder\_\-param, robot\_\-system::left\_\-ext\_\-gain, robot\_\-system::pext\_\-prev, rs\_\-wheels::right, robot\_\-system::right\_\-ext\_\-encoder, robot\_\-system::right\_\-ext\_\-encoder\_\-param, robot\_\-system::right\_\-ext\_\-gain, rs\_\-get\_\-polar\_\-from\_\-wheels(), rs\_\-get\_\-wheels\_\-from\_\-polar(), RS\_\-IGNORE\_\-EXT\_\-GAIN, RS\_\-IGNORE\_\-MOT\_\-GAIN, RS\_\-USE\_\-EXT, robot\_\-system::virtual\_\-encoders, and robot\_\-system::wext\_\-prev.