%
% MotionControl.tex
%

\documentclass{beamer}

\usepackage{beamerthemeshadow}
\usepackage{listings}
\usepackage{graphics}
\usepackage{times}
\usepackage{algorithm2e}

\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
% \usepackage{amsmath,amssymb} \usepackage[latin1]{inputenc}
% \usepackage{colortbl}
\usepackage[english]{babel}

\newcommand{\erlang}{
\lstset{language=Prolog, basicstyle=\ttfamily\footnotesize,frame=trBL,
  frameround=fttt}}

\newcommand{\erlangsmall}{
\lstset{language=Prolog, basicstyle=\ttfamily\scriptsize,frame=trBL,
  frameround=fttt}}

\newcommand{\clang}{
\lstset{language=Prolog, basicstyle=\ttfamily\footnotesize,frame=trBL,
  frameround=fttt}}

\newcommand{\clangsmall}{
\lstset{language=Prolog, basicstyle=\ttfamily\scriptsize,frame=trBL,
  frameround=fttt}}

\newcommand{\clangtiny}{
\lstset{language=Prolog, basicstyle=\ttfamily\tiny,frame=trBL,
  frameround=fttt}}

\erlang

\newcommand\blue{\color[rgb]{0,0,1}}
\newcommand\green{\color[rgb]{0,0.5,0}}
\newcommand\red{\color[rgb]{1,0,0}}
\newcommand\black{\color[rgb]{0,0,0}}

\newcommand\tape[9]{
\framebox{#1}
\framebox{#2}
\framebox{#3}
\framebox{#4}
\framebox{#5}
\framebox{#6}
\framebox{#7}
\framebox{#8}
\framebox{#9}}

\newcommand\two[2]{
\framebox{#1}
\framebox{#2}}

\newcommand\six[6]{
\framebox{#1}
\framebox{#2}
\framebox{#3}
\framebox{#4}
\framebox{#5}
\framebox{#6}}

\newcommand\three[3]{
\framebox{#1}
\framebox{#2}
\framebox{#3}}

\title[Motion Control: Task Periodici]{Architettura Software del Motion
  Control\\
Gestione dei Task Periodici}
%%

\author[Corrado Santoro]
       {Corrado Santoro}

\date{ }

\institute[University of Catania]
  {
    \begin{center}
      \textbf{\red{}ARSLAB - Autonomous and Robotic Systems Laboratory}\\
      Dipartimento di Matematica e Informatica - Universit\`{a} di Catania, Italy\\
      \texttt{santoro@dmi.unict.it}\\
      \includegraphics[width=60pt]{robotEscher_Eura_blur.eps}\\%%~~~~\includegraphics[width=80pt]{logo_dmi.png}
      Programmazione Sistemi Robotici\\
    \end{center}
  }



\begin{document}


%%
\frame{\titlepage}
%%


%%
\begin{frame}[fragile]
%%
  \frametitle{Class Diagram}
%%
\begin{center}
\includegraphics[scale=0.2]{motion_class_diagram.eps}
\end{center}
%%
\begin{itemize}
\item\footnotesize{}Il software del motion control \`{e} basato su un
  insieme di \textbf{task periodici} ognuno dei quali effettua le
  attivit\`{a} di gestione e controllo della movimentazione.
\item In pi\`{u} sono presenti alcune classi che rappresentano informazioni
  aggiuntive sullo stato del robot
\end{itemize}
%%
\end{frame}


%%
\begin{frame}[fragile]
%%
  \frametitle{Task Periodici}
%%
\begin{itemize}
%%
\item\footnotesize{}Il Motion Control possiede un sistema di scheduling per
  i task periodici
%%
\item Ogni task periodico \`{e} rappresentato da una sottoclasse di
  \texttt{\textbf{PeriodicTask}} ed \`{e} caratterizzato dal
  \textbf{periodo di esecuzione} dove \`{e} stato ridefinito il metodo
    \texttt{\textbf{run()}}
%%
\item Il sistema di scheduling si occupa di eseguire il metodo
  \texttt{\textbf{run()}} di ogni PeriodicTask allo scadere del periodo
  relativo
%%
\item Il sistema si basa su un \textbf{quanto di tempo} prefissato
  $T_{sched}$: \textbf{il periodo di ogni task deve essere un
  {\red{}multiplo intero} di $T_{sched}$}
%%
\item Nel motion control   $T_{sched}$ \`{e} fissato a $5 ms$
%%
\item Lo scheduling \`{e} \textbf{non-preemptive}, il metodo
  \texttt{\textbf{run()}} viene eseguito fino alla fine e non pu\`{o}
  essere interrotto
%%
\item Il metodo  \texttt{\textbf{run()}} dovr\`{a} pertanto eseguire un
  singolo ``step'' del task periodico specifico
%%
\end{itemize}
%%
\end{frame}
%%


%%
\begin{frame}[fragile]
%%
  \frametitle{Classe PeriodicTask}
%%
%%
\black\clangtiny%%
\begin{lstlisting}
class PeriodicTask {
 public:
    PeriodicTask(const char * name,
                 int period, float time_unit, int jitter,
                 bool insert_as_last = false);
    virtual void run() = 0;
    virtual void on() { m_on = true; };
    virtual void off() { m_on = false; };
    virtual bool on_status() { return m_on; };
    virtual void set_period(int v) { m_period = v; };
 private:
    void execute();
    const char * m_name;
    int m_ticks;
    int m_period;
    int m_jitter;
    bool m_on;
    PeriodicTask * m_task_next;
 protected:
    float m_real_time_period;
    float m_time_unit;
};
\end{lstlisting}
%%
\end{frame}
%%

%%
\begin{frame}[fragile]
%%
  \frametitle{Classe PeriodicTask}
%%
%%
\black\clangtiny%%
\begin{lstlisting}
class PeriodicTask {
 public:
    PeriodicTask(const char * name,
                 int period, float time_unit, int jitter,
                 bool insert_as_last = false);
...
};
\end{lstlisting}
%%
Parametri del costruttore:
\begin{itemize}
%%
\item\footnotesize{}\texttt{\textbf{name}}, nome del task
%%
\item\footnotesize{}\texttt{\textbf{period}}, periodo, in multipli di $T_{sched}$
%%
\item\footnotesize{}\texttt{\textbf{time\_unit}}, valore di $T_{sched}$ in
  millisecondi
%%
\item\footnotesize{}\texttt{\textbf{jitter}}, latenza di esecuzione
  rispetto al periodo, in multipli di $T_{sched}$
%%
\end{itemize}
%%
\end{frame}
%%





%%
\begin{frame}[fragile]
%%
  \frametitle{Periodo e Jitter}
%%
\begin{itemize}
%%
\item\footnotesize{}Supponiamo di avere due task periodici, con periodi
  rispettivamente, $T_{sched}$ e $2T_{sched}$ e $jitter = 0$
%%
\item L'esecuzione avverr\`{a} secondo quanto riportato in figura:
%%
\end{itemize}
%%
\begin{center}
\includegraphics[scale=0.35]{scheduling.eps}
\end{center}
%%
\end{frame}
%%
%%



%%
\begin{frame}[fragile]
%%
  \frametitle{Periodo e Jitter}
%%
\begin{itemize}
%%
\item\footnotesize{}Il \emph{Jitter} specifica la \textbf{traslazione nel
  tempo} (in termini di numero di quanti $T_{sched}$) dell'esecuzione del
  task.
%%
\item Esempio:
%%
\end{itemize}
%%
\begin{center}
\includegraphics[scale=0.35]{scheduling_j1.eps}
\end{center}
%%
\end{frame}
%%
%%

%%
\begin{frame}[fragile]
%%
  \frametitle{Jitter}
%%
\begin{itemize}
%%
%%
\item\footnotesize{}Esempio 2:
%%
\end{itemize}
%%
\begin{center}
\includegraphics[scale=0.3]{scheduling_j2.eps}\\
~\\
\includegraphics[scale=0.3]{scheduling_j3.eps}
\end{center}
%%
\end{frame}
%%
%%



%%
\begin{frame}[fragile]
%%
  \frametitle{Classe PeriodicTask}
%%
%%
\black\clangtiny%%
\begin{lstlisting}
class PeriodicTask {
 public:
    PeriodicTask(const char * name,
                 int period, float time_unit, int jitter,
                 bool insert_as_last = false);
    virtual void on() { m_on = true; };
    virtual void off() { m_on = false; };
    virtual bool on_status() { return m_on; };
};
\end{lstlisting}
%%
\footnotesize{}Altri metodi:
\begin{itemize}
%%
\item\footnotesize{}\texttt{\textbf{on}}, rende il task ``schedulabile''
  (di default un task \`{e} sempre in off)
%%
\item\footnotesize{}\texttt{\textbf{off}}, rende il task ``non-schedulabile''
%%
\item\footnotesize{}\texttt{\textbf{on\_status}}, restituisce il flag on/off
%%
\end{itemize}
%%
\end{frame}
%%



%%
\begin{frame}[fragile]
%%
  \frametitle{Fattibilit\`{a} dei task periodici}
%%
\begin{itemize}
%%
\item\footnotesize{}Sia $\red{}tr_i$ il \textbf{\red{}massimo tempo di esecuzione} del metodo
  \texttt{\textbf{run()}} per il task i-esimo.
%%
\item Siano $\red{}tr_1, tr_2, \dots, tr_m$ i tempi massimi di esecuzione di
  \textbf{\red{}tutti i task in ``ON''}
%%
\item Allora la seguente disuguaglianza \`{e} una \textbf{condizione
  sufficiente} per la corretta esecuzione dei task:
\begin{eqnarray*}
\red\sum_{i=1}^m{tr_i} \le T_{sched}
\end{eqnarray*}
%%
\end{itemize}
%%
\end{frame}



%%
\begin{frame}[fragile]
%%
  \frametitle{Periodi di esecuzione dei task del MotionControl}
%%
\begin{itemize}
%%
\item\footnotesize{}Tutte le definizioni dei periodi sono riportate nel
  file \texttt{``time\_defines.h'}
%%
\item Kinematics: 5 ms ($1 T_{sched}$)
%%
\item SpeedControl: 10 ms ($2 T_{sched}$)
%%
\item Telemetria velocit\`{a}: 40 ms ($8 T_{sched}$)
%%
\item Telemetria posizione: 250 ms ($50 T_{sched}$)
%%
\item Controllo in posizione (da implementare): 40 ms ($8 T_{sched}$)
%%
\end{itemize}
%%
\end{frame}



%%
\frame{\titlepage}
%%

%%
%%
\end{document}
%%
%%

