Slotcar Platoon Simulink Integration

Z DCEwiki
Skočit na navigaci Skočit na vyhledávání


Then you have to build nrfsio.c by compile.m (There should be precompiled .mexw32 or .mexw64 files then you can skip this step).




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.

Editing step time of the model

The model communicates in real time and sometimes the PC can't handle it so it is slower and then simulation time is slower than real time. So you have to change step time.

1) Model configuration parameter -> solver -> change fixed step size

2) In nrfsio.c change SAMPLE_TIME

3) In the model there is MASK car1. When you look under mask you can find Real-Time Synchronization1 where you have to set sample time too.

4) you have to recompile nrfsio.c and model


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

Back to slotcar platooning