Include a matlab activity in a model
PRESENTATION
This tutorial can be done from the Start to use Sim4Sys with a simple model (blackbox) model of car.
Prerequisites
- Have done the tutorial Start to use Sim4Sys with a simple model (blackbox),
- Concept on C++.
News skills that you will acquire
On Designer:
- Import a Matlab and use its function,
- Use variable with a multiplicity *,
- Use a periodic flow "when",
- Include external libraries,
- Build Configuration Edition.
On Virtual Bench:
- Use continious triggers,
- Concept on "Clock",
- Create mappings with a list,
- Use a new Context elements: Decorative elements (e.g. a pedestrian crossing), Polysensor.
Duration
4h
INTRODUCTION
In this tutorial we're going to handle an emergency braking. When getting closer to an obstacle such as a pedestrian or another car, we want the car to brake without the user's action. We already have a service called SpeedManagement. This service takes requests into account, and brake or accelerate according to those. In our new implementation, we want to :
- Detect close elements.
- Determine if the speed and the distance to those elements are safe.
- Brake accordingly.
Within these 3 steps, we only request to brake in the last one. Therefore, the idea is to create a new service, called EmergencyBrakeManagement which asks the SpeedManagement to brake when it needs to.
USING MATLAB
In this tutorial, we will be using a matlab file which will determine the braking distance of the vehicle. In order for papyrus to "understand" this matlab file, you will be given a .xml file which describe the inputs and outputs of the matlab function. This is what papyrus will use to map the file into your model. In our case, the file is called calculation_braking_distance.xml (you can find it in the ExtraLibs resource pack : New > Other > Sim4Sys > Extra Libraries), and needs to be placed into the folder of your project (In our case, ".../Tutorial6/") for it to work. It is good practice to create a special folder for activities description like this .xml file. As an example, you can store it in a new folder as "...Tutorial6/activities/". By refreshing the view of your project's folder in papyrus it should look like this:

CREATE A NEW USE CASE
We first need to create the EmergencyBrakeManagement service
- Open the Car Structure diagram, in which all services are displayed.
- Add a new service in the diagram, and name it EmergencyBrakeManagement.
- In the new service, open the Relevant Phases Diagram, and add new Standard Use life phase in the diagram.
We can now add a new use case
- Go into the new UCD diagram.
- Create a New Use Case "Brake automatically in case of emergency"
- Add the needed users

- In this newly created usecase, add two user stories :
- "An_obstacle_is_detected"
- "the_vehicle_brakes_automatically_in_case_of_emergency"
