Air conditioning and interior lighting in a car
Now is the time to take the plunge and to practice with the concept of parallel states.
DURATION
You should be able to complete this exercise in 2 hours.
GOAL
The objective of this project is to model some features of the car (air conditioning and interior lighting). Keep in mind that the model is valid for all cars with different options.
CONTEXT
This service is dedicated to control interior light and air conditioning of a vehicle. The manipulation of the system is done directly by the driver :
- The Driver switchs ON/OFF/Automatic the interior lighting.
- The Driver selects the speed of air conditioning / the temperature.
ASSUMPTIONS
We assume that:
- The interior lighting and air conditioning are two separate features.
- The User can modify the state of the interior lighting at any time (switchs ON/OFF/Automatic).
- The User can modify the state of the air conditioning (ON/OFF), increase or decrease the temperature.
- The internal lighting switch implemented in this model is similar to this one (see the screenshot below).

- In its initial state, the light is off.
- From the initial state, the user can switch directly to ON/Automatic Mode.
- Once the ON mode is activated, it must be switched back to the initial state (OFF) before switching to automatic mode. For Air conditioning feature, the ventillation is available only when the engine is running.
START MODELING ON Designer
- Create a new service.
- Drag & Drop the life phase “Standard Use” to the Life Phase diagram.
- Create a User actor named "User".
- Create the following use cases of the life phase “Standard Use” and associations between them and User (AirConditioner, InternalLighting).

- Create the following user stories for the use cases you have already created.

- Create the following flows and interfaces.

To accomplish this step successfully, you will need to create these enumerations.

- Create Feedback flows and interfaces.

State Machine Creation
- Drag & Drop a new state in MySpecStateMachine , name it "System_Available".
- Define the state already created as initial State.
- In order to create parallel states : you need to divide the area of the already created state using the button "Region" in the Palette part.

- After completing the previous steps, you should have a state machine similar to this one.

- Drag & drop an initial state named "InternalLightingState" in the first region and an other one named "AirConditioningState" in the second region.

- Now you can continue the modeling by creating the states of each system in the dedicated region.
Papyrus doesn't allow us to have transitions directly inside the regions created, that's why we have to create intermediate states "AirConditionningState" & "InternalLightingState" to avoid compilations problems related to this problem.
- The region of "InternalLightingState" should contain three under states : Light_OFF, Light_ON, Light_Automatic_Mode.
- The region of "AirConditioningState" should contain two under states : Ventillation_Unavailable, Ventillation_Available. When the ventillation is available there are four possible cases : Speed_OFF, Speed1, Speed2, Speed3.
User Stories Creation For Control_cabin_ventillation
- Create a user story "Ventillation_is_available_when_Engine_is_running": This sequence diagram is used to transition the system from the Ventilation Unavailable state to the Ventilation Available state. N.B : The car's ventilation system is always linked to the engine state.

- Create a user story "Ventillation_is_no_more_available_when_Engine_is_not_running": This sequence diagram is used to transition the system from the Ventilation Available state to the Ventilation Unavailable state when the engine is not running.

- Create a user story "User_Increases_Ventillation_Speed_When_It_Is_Off": This sequence diagram is used to pass the ventillation from speed off to speed 1.

- Create a user story "User_Increases_Ventillation_Speed_When_It_Is_In_Speed1": This sequence diagram is used to Increas the ventillation from speed 1 to speed 2.

- Create a user story "User_Increases_Ventillation_Speed_When_It_Is_In_Speed2": This sequence diagram is used to Increas the ventillation from speed 2 to speed 3.

- Create a user story "User_Decreases_Ventillation_Speed_When_It_Is_In_Speed3": This sequence diagram is used to Decreas the ventillation from speed 3 to speed 2.

- Create a user story "User_Decreases_Ventillation_Speed_When_It_Is_In_Speed2": This sequence diagram is used to Decreas the ventillation from speed 2 to speed 1.

- Create a user story "User_Decreases_Ventillation_Speed_When_It_Is_In_Speed1": This sequence diagram is used to pass the ventillation from speed 1 to speed OFF.

User Stories Creation For Control_interior_lighting
- Create a user story "User_Requests_Automatic_Mode": This sequence diagram is used to switch the interior lighting from OFF to Automatic Mode.

- Create a user story "User_Requests_ON_Mode": This sequence diagram is used to switch ON the interior lighting when it is initially OFF.

- Create a user story "User_Requests_OFF_Mode_When_It_Is_Switched_ON": This sequence diagram is used to switch OFF the interior lighting when it is already switched ON.

- Create a user story "User_Requests_OFF_Mode_When_It_Is_Automatic_Mode": This sequence diagram is used to switch OFF the interior lighting when it is already in automatic mode.

State Machine Generation
Once you have generated the state machine for all sequences diagrams, you should have the StateMachine diagram for the service as follows:

- You can generate the state chart of all sequence diagrams of a Use Case by selecting the Use Case in the Overview tab then cliquing on "Generate State Machines"

Code Compilation
-
To compile code you need to click on "[code] Generate and build";

-
Select "MyProject" then click on OK.

-
Choose "Cygwin GCC" ten click on Finish.

When the code generation is finished successfully, you will have this pop up :

Export XML file
Simply you need to click on the project in the Overview tab then click on "Export File XML"

Simulation with Virtual Bench
- Go on the Sim4Sys Virtual Bench: https://sim4sys.com/.
- Identify with your login and password.
- In the Projects tab choose your sandbox project.
- Add Executable & Import Types and Flows : In the Project tab, open the Executables folder, in which you can add a new executable.

-
You can name it as you want, choose the path to the executable, otherwise, click the red cross to remove the path, then press Save:

-
A pop-up opens to ask if you want to import types and flows from the model to the virtual bench:

-
If you click on Ok, the below pop-up ask you to add the .xml file:

-
Then, check that the types and flows are correct and click on Ok :

-
Create Scenario contexts by clicking on the New Scenario sign.

-
Create a new scenario.

-
Name it as you wish, and press "Save". The new scenario should now be opened if you selected Open the new scenario option.

-
Before creating new mappings, in your scenario tab, Add a new WebSockets, related to the Executable that you added earlier.

-
Configure the web socket creation and click on "Save".

-
Mapping : Establish mappings between the types and flows defined in the model and their representation in Virtual Bench.
- Switch to VB Edit Mode if you are in Run Mode, by clicking on the button:

- In Edit mode, in the context menu below, select the timeline context (don't forget to add a timeline context before that).

- Create an element by double clicking on the timeline events axis.
tipDouble-click somewhere in the timeline events axis to add a timeline action element. Then select it, and go to the Parameter tab and change the Event type from "continuous" to "trigger" (in order to send the associatied mapping only one time), and click on Save on the TimelineAction popup to save the modifications

- Right-click on the action and select Send flow.

- Virtual Bench will ask you if you want to Create a new mapping, or Reuse an existing one, select "Create":

- Configure your websoket and Select the flow that you want to send then click on save.

- Select the correct enumeration to send then click on Save.

You can add the other flows (simu to model) with the same method.
- In the context menu , select the HMI context to open it.
- In the HMI context menu, Drag & Drop the Text element.

- Right-click on the Text element and select Receive flow:

- Virtual Bench will ask you once again if you want to Create or Reuse a mapping, select "Create".

- Select the flow "Ventillation_Speed_Feedback" then click on save.

- Edit model to simulation mapping then click on save.

You can add the other flows (model to simu) with the same method.
Run scenario
Now you can run the configured simulation scenario and analyze the results to evaluate the system’s behaviour.
- Switch to VB Edit Mode if you are in Run Mode, by clicking on the button: