Project 2-Highway Assistant-Lane Changing Assistant
SOLUTION : To develop one specific requirement of Highway Assistant – Lane Changing Assistant algorithm. This is actually a very large algorithm , but here we are developing only a small part of it . We are asked to do all these things :
- This model must be developed in MATLAB Simulink per MBD guidelines.
- Code Generation Profile must be Autosar Coder.
- Simulink Data Dictionary must be created for the model & must be linked to the model.
- All the input & output signals must be mapped into the Autosar Editor.
- Model Advisor Report is mandatory & this will be followed by Code Generation.
The Highway Assistant supports the driver and takes over the longitudinal and lateral guidance of the vehicle in monotonous driving situations on highways. The partially automated function can automatically start, accelerate, brake as well as steer the vehicle to a certain extent. The driver has to permanently supervise the system and be ready to take over the complete control of the vehicle at any time.
Drivers are taught to assess surrounding traffic before changing lanes by checking their rearview and side mirrors and looking over each shoulder. However, even for those who follow this sequence of checks, the vehicle's blind spot – the area alongside and just behind the vehicle – is a constant source of danger and often the cause of serious accidents. Even vehicles approaching quickly from behind can pose a risk. To make changing lanes safer, this feature has been developed.
Now we look into the Requirements required :
Requirement No 1 [Highway_DisplayUnit]:
Inputs to this particular subsystem are “Highway_Input_Signal”, “Enable_Display”, “Input_Switch”. These three input signals, when assigned to a particular value will give output signals of specific value. The output signals are “Highway_Display_Mode_1”, “Highway_Display_Mode_2”, “Highway_Display_Mode_3”, “Highway_Display_Mode_4”. The requirement must be implemented in the form of a Stateflow logic.
|
Condition |
Action |
|
Highway_Input_Signal = 1 Enable_Display = off Input_Switch = on |
Highway_Display_Mode_1 = 232 Highway_Display_Mode_2 = 183 Highway_Display_Mode_3 = 41 Highway_Display_Mode_4 = 94 |
|
Highway_Input_Signal = 1 Enable_Display = on Input_Switch = on |
Highway_Display_Mode_1 = 213 Highway_Display_Mode_2 = 183 Highway_Display_Mode_3 = 9 Highway_Display_Mode_4 = 94 |
So the model is created according to the above given details. A Stateflow is implemented as per the given conditions .

Looking inside the Chart , the logic will be as shown in the following diagram :

Requirement No 2 [Lane_DisplayUnit]:
Inputs to this particular subsystem are “Enable_Display”, “Input_Switch”, “Lane_Input_Signal”. These three input signals, when assigned to a particular value will give output signals of specific value. The output signals are “Lane_Display_Mode_1”, “Lane_Display_Mode_2”, “Lane_Display_Mode_3”, “Lane_Display_Mode_4”. The requirement must be implemented in the form of Stateflow logic.
|
Condition |
Action |
|
Lane_Input_Signal= 6 Enable_Display = off Input_Switch = on |
Lane_Display_Mode_1 = 132 Lane_Display_Mode_2 = 185 Lane_Display_Mode_3 = 54 Lane_Display_Mode_4 = 67 |
|
Lane_Input_Signal= 6 Enable_Display = on Input_Switch = on |
Lane_Display_Mode_1 = 127 Lane_Display_Mode_2 = 248 Lane_Display_Mode_3 = 186 Lane_Display_Mode_4 = 84 |
Now when we are looking into this requirement here we have inputs such as :
“Enable_Display”, “Input_Switch”, “Lane_Input_Signal”
Outputs are :
“Lane_Display_Mode_1”, “Lane_Display_Mode_2”, “Lane_Display_Mode_3”, “Lane_Display_Mode_4”.

A Stateflow is used to implement this requirement as per the given table .

Requirement No 3:
Signals coming from both subsystems “Highway_Display_Mode_1” & “Lane_Display_Mode_1” are given as inputs to a switch block which will have input signal “Highway_Input_Signal” given as 2nd input to the switch block. Corresponding output from this particular switch block is output signal “Display_Mode_1”.
Signals coming from both subsystems “Highway_Display_Mode_2” & “Lane_Display_Mode_2” are given as inputs to a switch block which will have input signal “Highway_Input_Signal” given as 2nd input to the switch block. Corresponding output from this particular switch block is output signal “Display_Mode_2”.
Signals coming from both subsystems “Highway_Display_Mode_3” & “Lane_Display_Mode_3” are given as inputs to a switch block which will have input signal “Highway_Input_Signal” given as 2nd input to the switch block. Corresponding output from this particular switch block is output signal “Display_Mode_3”.
Signals coming from both subsystems “Highway_Display_Mode_4” & “Lane_Display_Mode_4” are given as inputs to a switch block which will have input signal “Highway_Input_Signal” given as 2nd input to the switch block. Corresponding output from this particular switch block is output signal “Display_Mode_4”.
We use a From and GoTo block to take the input signal 'Highway_Input_Signal'

According to the requirement 3 , the model is created for this also .
THe final model developed will look as shown in the figure below :

Combining this into a subsystem we get :

Now we are given various signals in the objective . So we create an SLDD File for all the signals which is as shown in the figure below :

Storage class for all the signals are set into Auto for AUTOSAR Environment .
All the signals are resolved and propagated accordingly at the proper locations .
After Developing the Model now we are asked to map this into the AUTOSAR Environment . For that , to do the AUTOSAR Compliant Code, we goto the Model Settings, where in Code generation we change the Target File from the default 'grt.tlc' to 'autosar.tlc'.


The solver settings is changed from default variable to the Fixed type and then discrete states .

The next step isto Configure the AUTOSAR Components in the AUTOSAR Dictionary and then to generate the required AUTOSAR Compliant Code . To do this we go to the APP Section of the SIMULINK ,under that we choose AUTOSAR COMPONENT DESIGNER .

After doing this we can access the AUTOSAR under the Code Mappings - AUTOSAR SW Component
On clicking that we get a window like :

Here inside this we click on the Orange button which takes us to a new window :

We initially start on by changing the XML parameters.

After the XML configuration, then the Sender-Receiver Interface (SRIf) Configuration is done . Since we have 4 inputs and 4 outputs in the main model , we have totallly 8 SRIf created here .

In each SRIf , we add Data Element corresponding to each of these SRIf .

The next step is to configure the Runnables . We normally create two runnables :
1. For initialization

2. For Timing Event

Then we update the Receiver and Sender Ports .
For sender ports we use a prefix Pp_

and for the Receiver ports we use a Prefix Rp_ .

Upon configuring all these above parameters into the AUTOSAR Dictionary , next we go onto mapping the ports into their corresponding AUTOSAR server receiver and sender ports and their respective data elements .



After this step, the validation is done after making sure that the Ports are mapped correctly .

Now we gofor Model Advisor check , by going into the Modelling > Model Advisor > Check for MAB guidelines

From this we can see that there are no errors in the model .
After this we move to the AUTOSAR Code generation .
For this again we go to AUTOSAR > QUICK START > FINISH
And we get the AUTOSAR COMPLIANT CODE :
/*
* File: Lane_Change_Assistance.c
*
* Code generated for Simulink model 'Lane_Change_Assistance'.
*
* Model version : 1.19
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Mon Apr 18 17:10:46 2022
*
* Target selection: autosar.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives:
* 1. Execution efficiency
* 2. RAM efficiency
* Validation result: Not run
*/
#include "Lane_Change_Assistance.h"
/* Named constants for Chart: '/Chart' */
#define IN_Condition1 ((uint8)1U)
#define IN_Condition2 ((uint8)2U)
/* Block signals and states (default storage) */
DW rtDW;
/* Model step function */
void Lane_Change_Assistance_Timing10ms(void)
{
sint32 rtb_Highway_Display_Mode_1;
sint32 rtb_Highway_Display_Mode_3;
sint32 rtb_Lane_Display_Mode_1;
sint32 rtb_Lane_Display_Mode_2;
sint32 rtb_Lane_Display_Mode_3;
sint32 rtb_Lane_Display_Mode_4;
sint32 tmp_0;
uint8 tmp;
/* Chart: '/Chart' incorporates:
* Inport: '/Enable_Display'
* Inport: '/Highway_Input_Signal'
* Inport: '/Input_Switch'
*/
if (rtDW.is_active_c3_Lane_Change_Assist == 0U) {
rtDW.is_active_c3_Lane_Change_Assist = 1U;
rtDW.is_c3_Lane_Change_Assistance = IN_Condition1;
rtb_Highway_Display_Mode_1 = 232;
rtb_Highway_Display_Mode_3 = 41;
} else if (rtDW.is_c3_Lane_Change_Assistance == IN_Condition1) {
rtb_Highway_Display_Mode_1 = 232;
rtb_Highway_Display_Mode_3 = 41;
if ((Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
() == 1) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Enable_Display_DE_Enable_Display
() == 1) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Input_Switch_DE_Input_Switch
() == 1)) {
rtDW.is_c3_Lane_Change_Assistance = IN_Condition2;
rtb_Highway_Display_Mode_1 = 213;
rtb_Highway_Display_Mode_3 = 9;
}
} else {
/* case IN_Condition2: */
rtb_Highway_Display_Mode_1 = 213;
rtb_Highway_Display_Mode_3 = 9;
if ((Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
() == 1) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Enable_Display_DE_Enable_Display
() == 0) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Input_Switch_DE_Input_Switch
() == 1)) {
rtDW.is_c3_Lane_Change_Assistance = IN_Condition1;
rtb_Highway_Display_Mode_1 = 232;
rtb_Highway_Display_Mode_3 = 41;
}
}
/* End of Chart: '/Chart' */
/* Chart: '/Chart1' incorporates:
* Inport: '/Enable_Display'
* Inport: '/Input_Switch'
* Inport: '/Lane_Input_Signal'
*/
if (rtDW.is_active_c1_Lane_Change_Assist == 0U) {
rtDW.is_active_c1_Lane_Change_Assist = 1U;
rtDW.is_c1_Lane_Change_Assistance = IN_Condition1;
rtb_Lane_Display_Mode_1 = 132;
rtb_Lane_Display_Mode_2 = 185;
rtb_Lane_Display_Mode_3 = 54;
rtb_Lane_Display_Mode_4 = 67;
} else if (rtDW.is_c1_Lane_Change_Assistance == IN_Condition1) {
rtb_Lane_Display_Mode_1 = 132;
rtb_Lane_Display_Mode_2 = 185;
rtb_Lane_Display_Mode_3 = 54;
rtb_Lane_Display_Mode_4 = 67;
if ((Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Lane_Input_Signal_DE_Lane_Input_Signal
() == 6) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Enable_Display_DE_Enable_Display
() == 1) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Input_Switch_DE_Input_Switch
() == 1)) {
rtDW.is_c1_Lane_Change_Assistance = IN_Condition2;
rtb_Lane_Display_Mode_1 = 127;
rtb_Lane_Display_Mode_2 = 248;
rtb_Lane_Display_Mode_3 = 186;
rtb_Lane_Display_Mode_4 = 84;
}
} else {
/* case IN_Condition2: */
rtb_Lane_Display_Mode_1 = 127;
rtb_Lane_Display_Mode_2 = 248;
rtb_Lane_Display_Mode_3 = 186;
rtb_Lane_Display_Mode_4 = 84;
if ((Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Lane_Input_Signal_DE_Lane_Input_Signal
() == 6) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Enable_Display_DE_Enable_Display
() == 0) &&
(Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Input_Switch_DE_Input_Switch
() == 1)) {
rtDW.is_c1_Lane_Change_Assistance = IN_Condition1;
rtb_Lane_Display_Mode_1 = 132;
rtb_Lane_Display_Mode_2 = 185;
rtb_Lane_Display_Mode_3 = 54;
rtb_Lane_Display_Mode_4 = 67;
}
}
/* End of Chart: '/Chart1' */
/* Switch: '/Switch3' incorporates:
* Inport: '/Highway_Input_Signal'
* Switch: '/Switch'
* Switch: '/Switch1'
* Switch: '/Switch2'
*/
tmp_0 =
Rte_IRead_Lane_Change_Assistance_Timing10ms_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
();
if (tmp_0 != 0) {
tmp = (uint8)rtb_Highway_Display_Mode_1;
} else {
tmp = (uint8)rtb_Lane_Display_Mode_1;
}
/* End of Switch: '/Switch3' */
/* Outport: '/Display_Mode_1' */
Rte_IWrite_Lane_Change_Assistance_Timing10ms_Pp_Display_Mode_1_DE_Display_Mode_1
(tmp);
/* Switch: '/Switch' */
if (tmp_0 != 0) {
tmp = 183U;
} else {
tmp = (uint8)rtb_Lane_Display_Mode_2;
}
/* Outport: '/Display_Mode_2' */
Rte_IWrite_Lane_Change_Assistance_Timing10ms_Pp_Display_Mode_2_DE_Display_Mode_2
(tmp);
/* Switch: '/Switch2' */
if (tmp_0 != 0) {
tmp = (uint8)rtb_Highway_Display_Mode_3;
} else {
tmp = (uint8)rtb_Lane_Display_Mode_3;
}
/* Outport: '/Display_Mode_3' */
Rte_IWrite_Lane_Change_Assistance_Timing10ms_Pp_Display_Mode_3_DE_Display_Mode_3
(tmp);
/* Switch: '/Switch1' */
if (tmp_0 != 0) {
tmp = 94U;
} else {
tmp = (uint8)rtb_Lane_Display_Mode_4;
}
/* Outport: '/Display_Mode_4' */
Rte_IWrite_Lane_Change_Assistance_Timing10ms_Pp_Display_Mode_4_DE_Display_Mode_4
(tmp);
}
/* Model initialize function */
void Lane_Change_Assistance_Init(void)
{
/* (no initialization code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
Code generation report is received which is as follows :

Requirement files are tagged accordingly by right clicking the subsystems and adding the files :

CONCLUSION :
* Model according to the given requirements is developed .
* AUTOSAR Mapping is done .
* MODEL Advisory check is done and the Model report is attached as an HTML File .
* SLDD File is created and it is attached with the model
* AUTOSAR Code is generated and is attached .