Slotcar Platoon Simulink Integration

Z DCEwiki
Verze z 28. 3. 2014, 10:28, kterou vytvořil Hermaiv2 (diskuse | příspěvky) (Založena nová stránka: You should use Matlab R2012 or newer. They should contain every needed toolbox: * Real-Time Windows Target toolboxem * Embedded Coder * MATLAB Coder You have to compile…)
(rozdíl) ← Starší verze | zobrazit aktuální verzi (rozdíl) | Novější verze → (rozdíl)
Skočit na navigaci Skočit na vyhledávání

You should use Matlab R2012 or newer. They should contain every needed toolbox:

  • Real-Time Windows Target toolboxem
  • Embedded Coder
  • MATLAB Coder

You have to compile file \sw\simulink_sfunction.c with prepared script compile.m.

  • Check, that you have the right library in folder \sw\lib\.
    • It has to be compatible with compilator, which will matlab use to compile the simulink_sfunction.c file
    • You can find all libraries in folder Libusb libraries
    • By default, there is msvc_x64, it should work without changes

Setting up the Simulink Coder

Write to Matlab mex -setup. Select yes to find the available compilers. If none is found, you must install Microsoft Visual Studio 2012 or newer to install the compiler. Close matlab and after installation of MS VS2012 setup of mex should work.

Simulink

Car model

Car model is located in \sw\simulink_sfunction\. There is block Car 1, in which you can set some basic setting. It provides communication with one car at the time.

  • Input motor should be <0,1>
  • There could be up to 20 numbers type short coming in data packets from car. Which data you send can be specified in main.c. If you want to change the number of incomming numbers:
    • Set the number in Emux block -> Number of outputs
    • Set the number in raw output -> Signal Atributs -> Port dimensions
  • Communication is done by block nrf base station. There you have to set the right addres of the car in s-function parameters. It uses the nrfsio.c file.
  • Time synchonization is done by Real-Time Synchronization1 block. There you can set the sampling time.


Regulators (and other)

Here is basic instuctions, how to make any model (regulators, filters), that you want to compile in C and use in your code.

  • Create your Simulink model
    • It should have basic Inport and Outport
    • It should be discrete
  • Go to Code -> C/C++ Code -> Code Generation Options...
    • In Code Generation -> System taget file browse for ert.tlc (Embedded Coder).
    • In Hardware Implementation -> Device vendor set ARM Compatible and in Device type set ARM Cortex.
  • Now you can compile it by clicking the Build Model option. It should generate new folder named YOURMODEL_ert_rtw. Move the folder to your app directory
  • Look at the generated files, mainly YOURMODEL.c, YOURMODEL_data.c
    • Here you can find the basic variables (Input, Output, ...), functions (YOURMODEL.step(), ...)
    • Include the libraries to your main.c
    • The basic thought is: Put you input variables in inputs, call YOURMODEL.step() function, read the output variables from outputs
    • Upgrade the Makefile to consist YOURMODEL.c and YOURMODEL_data.c files