\section{interface.c File Reference}
\label{interface_8c}\index{interface.c@{interface.c}}
Implementation of an example interface to a simple robot with two independent axies. 


{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$unistd.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$asm/io.h$>$}\par
{\tt \#include $<$time.h$>$}\par
{\tt \#include $<$sys/wait.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf interface\_\-ymax\_\-time}\ 20000
\begin{CompactList}\small\item\em Time it rakes to drive to robot form y\_\-min to y\_\-max.\item\end{CompactList}\item 
\#define {\bf interface\_\-xmax\_\-time}\ 20000
\begin{CompactList}\small\item\em Time it rakes to drive to robot form x\_\-min to x\_\-max.\item\end{CompactList}\item 
\#define {\bf interface\_\-ymax}\ 100
\begin{CompactList}\small\item\em Maximal Y value (cosidered as 100 percent).\item\end{CompactList}\item 
\#define {\bf interface\_\-xmax}\ 100
\begin{CompactList}\small\item\em Maximal X value (cosidered as 100 percent).\item\end{CompactList}\item 
\#define {\bf interface\_\-ioport}\ 0x378
\begin{CompactList}\small\item\em IO Port to which lowest nible to robot is connected.\item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned char {\bf input} (int addr)
\begin{CompactList}\small\item\em Read a byte from an IO port.\item\end{CompactList}\item 
unsigned char {\bf output} (int addr, unsigned char out)
\begin{CompactList}\small\item\em Write a byte to an IO port.\item\end{CompactList}\item 
void {\bf msleep} (int msec)
\begin{CompactList}\small\item\em Wait a specified number of milliseconds.\item\end{CompactList}\item 
int {\bf getmax} (int a, int b)
\begin{CompactList}\small\item\em Get to highest number out of two input numbers.\item\end{CompactList}\item 
int {\bf getmin} (int a, int b)
\begin{CompactList}\small\item\em Get to lowest number out of two input numbers.\item\end{CompactList}\item 
void {\bf interface\_\-drive} (int h, int v)
\begin{CompactList}\small\item\em Drive the robot in a specified direction.\item\end{CompactList}\item 
void {\bf interface\_\-init} (int mode)
\begin{CompactList}\small\item\em Initialze the interface and drive the robot to the start position.\item\end{CompactList}\item 
void {\bf interface\_\-driveto} (int x, int y)
\begin{CompactList}\small\item\em Drive to robot to absolute coordinates.\item\end{CompactList}\item 
void {\bf interface\_\-stop} ()
\begin{CompactList}\small\item\em Stop the interface, switch all off.\item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
int {\bf interface\_\-x}
\begin{CompactList}\small\item\em current X possition of robot (global).\item\end{CompactList}\item 
int {\bf interface\_\-y}
\begin{CompactList}\small\item\em current X possition of robot (global).\item\end{CompactList}\item 
int {\bf interface\_\-mode}
\begin{CompactList}\small\item\em mode of interface: 0: normal, 1: simulation (do all except to drive the robot), 2: simulation with position-output 3: Blocked: Do nothing.\item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implementation of an example interface to a simple robot with two independent axies.

The robot has four inputs whish are connected to the lower nible on IO port \char`\"{}interface\_\-ioport\char`\"{}. The bits are connected in this way (the signals a high-active):

Bit 0: Drive Up wires: switch to GND: yellow-green; +24V: gray-black

Bit 1: Dirve down wires: switch to GND: red-green; +24V: orange-black

Bit 2: Dirve right wires: switch to GND: green-red; +24V: yellow-black

Bit 3: Dirve left wires: switch to GND: white-red; +24V: red-blue

power wires: GND: blue; +24V: red

This interface assumes a linear dependency betwenn the coverence of distance and moving time. The 0,0 coordinates is left,bottom.

User functions are:

{\bf interface\_\-init}() {\rm (p.\,\pageref{interface_8c_a14})} - Initialze the interface and drive the robot to the start position (X=undefined; Y=0).

{\bf interface\_\-driveto}(int x, int y) {\rm (p.\,\pageref{interface_8c_a15})} - Drive the robot to the absolute coordinates x,y.



\subsection{Define Documentation}
\index{interface.c@{interface.c}!interface_ioport@{interface\_\-ioport}}
\index{interface_ioport@{interface\_\-ioport}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define interface\_\-ioport\ 0x378}\label{interface_8c_a4}


IO Port to which lowest nible to robot is connected.

\index{interface.c@{interface.c}!interface_xmax@{interface\_\-xmax}}
\index{interface_xmax@{interface\_\-xmax}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define interface\_\-xmax\ 100}\label{interface_8c_a3}


Maximal X value (cosidered as 100 percent).

\index{interface.c@{interface.c}!interface_xmax_time@{interface\_\-xmax\_\-time}}
\index{interface_xmax_time@{interface\_\-xmax\_\-time}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define interface\_\-xmax\_\-time\ 20000}\label{interface_8c_a1}


Time it rakes to drive to robot form x\_\-min to x\_\-max.

\index{interface.c@{interface.c}!interface_ymax@{interface\_\-ymax}}
\index{interface_ymax@{interface\_\-ymax}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define interface\_\-ymax\ 100}\label{interface_8c_a2}


Maximal Y value (cosidered as 100 percent).

\index{interface.c@{interface.c}!interface_ymax_time@{interface\_\-ymax\_\-time}}
\index{interface_ymax_time@{interface\_\-ymax\_\-time}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define interface\_\-ymax\_\-time\ 20000}\label{interface_8c_a0}


Time it rakes to drive to robot form y\_\-min to y\_\-max.



\subsection{Function Documentation}
\index{interface.c@{interface.c}!getmax@{getmax}}
\index{getmax@{getmax}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int getmax (int {\em a}, int {\em b})}\label{interface_8c_a11}


Get to highest number out of two input numbers.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
a}](int) first input number \item[{\em 
b}](int) second input number \end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) the highest of the input numbers \end{Desc}
\index{interface.c@{interface.c}!getmin@{getmin}}
\index{getmin@{getmin}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int getmin (int {\em a}, int {\em b})}\label{interface_8c_a12}


Get to lowest number out of two input numbers.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
a}](int) first input number \item[{\em 
b}](int) second input number \end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) the lowest of the input numbers \end{Desc}
\index{interface.c@{interface.c}!input@{input}}
\index{input@{input}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned char input (int {\em addr})}\label{interface_8c_a8}


Read a byte from an IO port.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
addr}](int): address of port to read \end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(unsigned char) read byte \end{Desc}
\index{interface.c@{interface.c}!interface_drive@{interface\_\-drive}}
\index{interface_drive@{interface\_\-drive}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void interface\_\-drive (int {\em h}, int {\em v})}\label{interface_8c_a13}


Drive the robot in a specified direction.

Any axies can be zero, greater than zero or less than zero, in this cases the robot will not driven, driven to increase to position (up[v,y] or right[h,x]) and decrease the position (down[-v,-y] or left[-h,-x]).\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
h}](int) horizontal or X axias. \item[{\em 
v}](int) vertical or Y axias. \end{description}
\end{Desc}
\index{interface.c@{interface.c}!interface_driveto@{interface\_\-driveto}}
\index{interface_driveto@{interface\_\-driveto}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void interface\_\-driveto (int {\em x}, int {\em y})}\label{interface_8c_a15}


Drive to robot to absolute coordinates.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
x}](int): absolute x coordinate \item[{\em 
y}](int): absolute y coordinate \end{description}
\end{Desc}
\index{interface.c@{interface.c}!interface_init@{interface\_\-init}}
\index{interface_init@{interface\_\-init}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void interface\_\-init (int {\em mode})}\label{interface_8c_a14}


Initialze the interface and drive the robot to the start position.

\index{interface.c@{interface.c}!interface_stop@{interface\_\-stop}}
\index{interface_stop@{interface\_\-stop}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void interface\_\-stop ()}\label{interface_8c_a16}


Stop the interface, switch all off.

\index{interface.c@{interface.c}!msleep@{msleep}}
\index{msleep@{msleep}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void msleep (int {\em msec})}\label{interface_8c_a10}


Wait a specified number of milliseconds.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
msec}](int): milliseconds to wait \end{description}
\end{Desc}
\index{interface.c@{interface.c}!output@{output}}
\index{output@{output}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned char output (int {\em addr}, unsigned char {\em out})}\label{interface_8c_a9}


Write a byte to an IO port.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
addr}](int): address of port to write onto \item[{\em 
out}](unsigned char): byte to write \end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(unsigned char) written byte \end{Desc}


\subsection{Variable Documentation}
\index{interface.c@{interface.c}!interface_mode@{interface\_\-mode}}
\index{interface_mode@{interface\_\-mode}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int interface\_\-mode}\label{interface_8c_a7}


mode of interface: 0: normal, 1: simulation (do all except to drive the robot), 2: simulation with position-output 3: Blocked: Do nothing.

\index{interface.c@{interface.c}!interface_x@{interface\_\-x}}
\index{interface_x@{interface\_\-x}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int interface\_\-x}\label{interface_8c_a5}


current X possition of robot (global).

\index{interface.c@{interface.c}!interface_y@{interface\_\-y}}
\index{interface_y@{interface\_\-y}!interface.c@{interface.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int interface\_\-y}\label{interface_8c_a6}


current X possition of robot (global).

