]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/commitdiff
doc: Update documentation of external mode and related stuff
authorMichal Sojka <michal.sojka@cvut.cz>
Fri, 18 Oct 2019 11:23:16 +0000 (13:23 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Fri, 18 Oct 2019 11:38:34 +0000 (13:38 +0200)
doc/rpp_simulink.tex

index 90ee0e0784cf519b68482288d229ec8e17178865..2c1f01436fe02b98a2ad388d22d4d40778d023cb 100644 (file)
@@ -199,6 +199,12 @@ Michal \textsc{Sojka}\\[\baselineskip]
                                       Added section \ref{sec:board-init-hydctr}: ``Hydraulics controller
                                       initialization demo''.
            \\\hline
+           0.8 & 2019-10-18 & Nejedlý, Sojka &
+                                               Added sections about
+                                               Ethernet (\ref{sec-configuration-network-interface}),
+                                               Simulink external mode (\ref{sec-external-mode}) and
+                                               description of eth* commands in Section~\ref{sec:commands-description}.
+           \\\hline
 \end{tabularx}
 }
 \tableofcontents
@@ -1708,16 +1714,31 @@ the main function, has to be modified to use proper functions for task
 creation, task timing and semaphores. The template is stored in
 \texttt{\repo/rpp/rpp/rpp\_mrmain.tlc} file.
 
-\section{Configuring network interface}
+\section{Networking support and configuration}
 \label{sec-configuration-network-interface}
-To configure the network, it is currently necessary to set the parameters in the eth.h file. The current implementation does not allow automatic IP address retrieval through the DHCP server. The target has a configurable MAC address. It is not usually necessary to change the settings for a network connection. Only if the address could collide with other devices on the network. To configure the third-layer parameters, it is necessary to set a static IP address, network mask, and default gateway. The parameters must correspond to the network to which the device is connected.
+
+The RPP C support library includes lwIP networking
+stack\footnote{\url{https://savannah.nongnu.org/projects/lwip/}} to
+implement TCP/IP networking. The lwIP stack is integrated with the
+Ethernet driver and the rest of the RPP library.
+
+To use TCP/IP networking (either in developed C applications or for Simulink external mode -- see Section~\ref{sec-external-mode}), it is currently necessary to set a few parameters (MAC and IP addresses) in the \texttt{eth.h} file. The current implementation does not support automatic IP address configuration through the DHCP server.
+
+The MAC address of the Ethernet interface is not fixed in hardware, it must be set by software. The settings shown below works fine, unless multiple target boards are connected to the same network. In that case, the MAC address has to be changed so that each board has a distinct MAC address.
+
+To configure TCP/IP networking, the following parameters has to be set: board's IP address and network mask, and the default gateway. Their values must correspond to the network to which the board is connected.
+
+The parameters and their default values (as stored in \texttt{rpp/lib/rpp/include/rpp/eth.h}) are shown below:
+
 \begin{lstlisting}[language=c]
-#define RPP_MAC_ADDR             { 0x12 /* Unicast, Locally administered */, 0x34, 0x56, 0x78, 0x9A, 0xBC }
-#define RPP_IP_ADDR               0x0A235F19 
-#define RPP_NETMASK               0xFFFFFF00 
-#define RPP_GW                    0x0A235F01 
+#define RPP_MAC_ADDR { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC }
+#define RPP_IP_ADDR  0x0A235F19 // 10.35.95.25
+#define RPP_NETMASK  0xFFFFFF00 // 255.255.255.0
+#define RPP_GW       0x0A235F01 // 10.35.95.1
 \end{lstlisting}
 
+
+
 \chapter{Simulink Coder Target}
 \label{chap-simulink-coder-target}
 
@@ -1749,7 +1770,7 @@ board.
 \item Multi-rate models can be executed in a single or multiple OS
   tasks. Multi-tasking mode allows high-rate tasks to preempt low-rate
   tasks. See Section \ref{sec-singlet-multit-modes} for more details.
-\item Support of external mode included over TCPIP with some limitations. See Section \ref{sec-external-mode} for more details.
+\item Support of external mode over TCP/IP with some limitations. See Section~\ref{sec-external-mode} for more details.
 \item Custom compiler options, available via OPTS variable in
   \emph{Make command} at \emph{Code Generation} tab (see Figure
   \ref{fig-code-gen-settings}). For example \texttt{make\_rtw
@@ -2117,45 +2138,40 @@ cd <rpp-simulink>\rpp\demos
 Both commands will create a directory for each compiled demo, which will contain the generated C code and binary file with the firmware. To download the firmware to the board and run it, see Section \ref{sec-running-software-on-hw}.
 \end{enumerate}
 
- \section{External mode}
+\section{External mode}
 \label{sec-external-mode}
-The external mode allows communication with the simulation running on the target device. It is possible to monitor the internal signals of the simulation and change the parameters of the amplifiers in the wiring. Communication is performed using the network connection of the target device. For correct operation of the external mode, it is necessary to configure the static IP address, mask, and basic gateway correctly.\\
-\\
-\textbf{External Mode Communication Channel Setup.} External mode is a very
-useful environment for rapid prototyping. Procedure to set external mode up is consisting of four parts,
-each of which depends on completion of the preceding ones, in order. The four
-parts correspond to the steps that you follow in simulating, building, running,
-and tuning an actual real-time application.
+Simulink external mode allows real-time communication between Simulink and the generated code running on the target device. With it, one can monitor the values of Simulink signals and change values of some Simulink block parameters, e.g., gains. Simulink communicates with the device via a TCP connection. For correct operation of the external mode, it is necessary to configure the static IP address, mask, and default gateway, as described in Section~\ref{sec-configuration-network-interface}.
+
+Using the external mode involves the following activities:
 \begin{enumerate}
-\item Set up the model.
-\item Build the target executable.
-\item Run the External mode target program.
-\item Tune parameters and watch signals.
+\item Setting up the model,
+\item building the target executable,
+\item running the external mode target program, and finally
+\item tuning parameters and watching signals in real-time.
 \end{enumerate}
+These activities are described in greater detail in the following sections.
 
-\subsection{Set up the model}
-When creating a model, before compiling it is necessary to add scope elements to the signals, that the user will need to follow while debugging the simulation.
-An example of an external mode simulation is shown below.
+\subsection{Setting up the model}
 
-\begin{figure}[!h]\begin{center}
+If one wants to watch signals in the model, when it is running on the target board, scope blocks should be added to the model. An example of an external mode model with scope blocks is shown in Fig.~\ref{fig:extmode-model}.
+
+\begin{figure}\begin{center}
 \noindent
 \includegraphics[scale=.45]{images/extmod_scheme.png}
-\caption{The example scheme for external mode}
+\caption{Example model for external mode}
+\label{fig:extmode-model}
 \end{center}\end{figure}
 
-
-It is necessary to set the following parameters for the simulation. The description of the path to the individual parameters is based on their position in version 2018a.
+The model has to be configured in a specific way for the external model to work. All the necessary configuration is described below. The description and the path to the individual parameters is based on Simulink version 2018a.
 
 \begin{enumerate}
-\item Open the Configuration Parameters dialog box by selecting Simulation -$>$ Model Configuration Parameters.
-\item Select the Solver pane.
-\item In the Solver options subpane:
+\item Open the Configuration Parameters dialog box by selecting \textsc{Simulation → Model Configuration Parameters}.
+\item Select the \textsc{Solver} pane.
+\item In the \textsc{Solver options} subpane:
   \begin{enumerate}
-  \item In the Type field, select Fixed-step .
-  \item In the Solver field, select discrete (no continuous states) .
-  \item In the Fixed-step size field, specify 0.1 . (Otherwise, when you generate
-  code, the Simulink Coder build process posts a warning and supplies a
-  value.)
+  \item In the \textsc{Type} field, select \emph{Fixed-step}.
+  \item In the \textsc{Solver} field, select \emph{discrete (no continuous states)}.
+  \item In the \textsc{Fixed-step size} field, specify the sampling period of your model. External mode communication was tested with the value of \emph{0.1}.
   \end{enumerate}
 
   \begin{figure}[!h]\begin{center}
@@ -2164,30 +2180,29 @@ It is necessary to set the following parameters for the simulation. The descript
   \caption{Solver setup}
   \end{center}\end{figure}
 
-\item Select the Hardware Implementation
+\item Select the \textsc{Hardware Implementation} pane.
   \begin{enumerate}
   \item In the Device vendor field, select proper vendor (example Texas Instruments)
   \item In the Device type field, select proper target (example TSM570).
   \end{enumerate}
-\item Select the Code Generation pane. And control that rpp target is selected.
-\item Select the Code Generation -$>$ Optimalization. Set field Default parameter behavior to Tunable
+\item Select the \textsc{Code Generation} pane and check that \emph{rpp.tlc} is selected as target.
+\item Select the \textsc{Code Generation → Optimization}. Set field \textsc{Default parameter behavior} to \emph{Tunable}
 \begin{figure}[!h]\begin{center}
   \noindent
   \includegraphics[scale=.45]{images/exmod_parameters.png}
   \caption{Set parameters tuneble for external mode}
 \end{center}\end{figure}
 
-\item Select the Code Generation -$>$ Interface pane.
+\item Select the \textsc{Code Generation → Interface} pane.
   \begin{enumerate}
-  \item In section Software environment, subsection Support. Set positive floating-point numbers, absolute and continuous time.
-  \item In section Data exchange interface, set C api generation for parameters and signals. Also set External mode on and configure subsection External mode configuration. There select transport layer to tcpip and MEX-file argument to this format. The Ip address is static IP of target. This address is set in file eth.h. Default value of port si 17725. To change port number is nessesary tu redefine parameter in tcpip interface. 
-    \begin{lstlisting}[language=Matlab]
-"ip address" 1 port
-    \end{lstlisting}
-example:
-    \begin{lstlisting}[language=Matlab]
-"10.35.95.25" 1 17725
-    \end{lstlisting}
+  \item In section \textsc{Software environment → Software environment
+      → Support}. Enable \emph{floating-point numbers}, \emph{absolute
+    time} and \emph{continuous time}.
+\item In section \textsc{Data exchange interface → Generate C API for}
+  check \emph{parameters} and \emph{signals}. 
+\item Enable \textsc{Data exchange interface → External mode} and configure subsection \emph{External mode configuration}: select transport layer to \emph{tcpip} and \textsc{MEX-file arguments} to \emph{$\langle$IP address$\rangle$ 1 $\langle$port$\rangle$}. \emph{IP address} is the IP address of the board, e.g., the one set in \texttt{eth.h}. \emph{Port} is the port where the board listens for Simulink connection. Its value should be 17725, which is also the default so the number can be omitted here.
+
+Example value of \textsc{MEX-file arguments} is: \texttt{"10.35.95.25" 1 17725}
   \end{enumerate}
 
   \begin{figure}[!h]\begin{center}
@@ -2196,28 +2211,28 @@ example:
     \caption{External mode interface setup}
   \end{center}\end{figure}
 
-  \item In the RPP, increase C system heap size to 65536. External mode uses this heap to allocate outgoing buffer. And control if is set Download compiled binary to RPP to positive.
-  \item Open Code -$>$ External mode control panel. And click on Signals \& trigging. 
+  \item In the \textsc{RPP Options} pane, increase \textsc{C system heap size} to \emph{65536}. External mode uses this heap to allocate networking buffers. Check that \emph{Download compiled binary to RPP} is enabled.
+  \item Close \textsc{Configuration Parameters} dialog box by pressing \textsc{Ok}.
+  \item Open \textsc{Code → External Mode Control Panel} menu and press \textsc{Signals \& Triggering…} button. 
     \begin{enumerate}
-    \item In main part of panel select scopes using external modes.
-    \item In subsection, Trigger options set the Duration to 500. This option describes the length of the outgoing buffer on the target platform. As the frequency of the model increases, the buffer becomes full between data sending to the external modem. This leads to periodic data outages. These failures can be partially reduced by increasing the Duration value to a sufficiently high value. Due to limited memory, it may be necessary to increase the C system heap size on the RPP panel to increase the Duration value further. This value must not be greater than the remaining free space on the target.
+    \item In \textsc{Signal section} part of opened dialog box select all scopes.
+    \item In the \textsc{Trigger options} part set the \textsc{Duration} to \emph{500}.
+
+      This value configures the length of the outgoing buffer on the target board. As the frequency of the model increases, the buffer may become full before the data is sent to Simulink, which leads to periodic data outages. These outages can be partially reduced by increasing the \textsc{Duration} value to a sufficiently high value. Due to limited memory, it may be necessary to increase the \textsc{C system heap size} on the \textsc{RPP Options} pane to increase the \textsc{Duration} value further. This value must not be greater than the remaining free heap memory on the target.
     \end{enumerate}
 \end{enumerate}
 
 \subsection{Build the target executable}
-For correct model compilation, it is necessary to switch the running mode from normal to external. It is also advisable to select the simulation time, for example, to value inf.
-After making the previous settings, the model can be compiled and uploaded to the device using the Build model button in the Simulink header.
+For correct model compilation, it is necessary to switch the simulation mode from \emph{normal} to \emph{external} via \textsc{Simulation → Mode} menu. It is also advisable to select the \emph{Simulation stop time}, to value \emph{inf}.
+Then, the model can be compiled and downloaded to the device using the \textsc{Build Model} button in the Simulink model window toolbar.
 
 \subsection{Run the External mode target program}
-Once the model has been successfully uploaded to the target, communication must be initiated.\\
-This is possible using the Connect to target button or the Connect button in the External mode control panel.
-The simulation program on the target device starts the calculation as soon as the binary file is uploaded. \\
-Waiting simulation on user connection is not currently implemented.
+Once the model has been successfully uploaded to the target, communication must be initiated. This is possible by using the \textsc{Simulation → Connect To Target} menu or the \textsc{Connect} button in the \textsc{External Mode Control Panel}. The program on the target device starts running as soon as the binary file is uploaded, waiting for connection from the Simulink before starting the program is currently not implemented.
 
 \subsection{Tune parameters and watch signals}
-After a successful connection to the device, it is possible to configure the amplifier parameters and view the scopes in the standard way as during local machine simulation.
+After a successful connection to the device, it is possible to configure the gain parameters and view the signal values in scopes blocks in the standard way as during normal Simulink simulation.
 
-\section{Adding new functionality}
+ \section{Adding new functionality}
 \label{sec:adding-new-funct}
 This section describes how to create new Simulink blocks and how to add them to the RPP
 blocks library. The new block creation process consists of several steps:
@@ -2757,6 +2772,7 @@ On Windows \texttt{gmake.exe} supplied with CCS is used instead of
 \end{enumerate}
 
 \section{Commands description}
+\label{sec:commands-description}
 
 This section contains the description of the available commands. The
 same description is also available in the program itself via the