Project 2-Highway Assistant-Lane Changing Assistant
Project 2 : Highway Assistant – Lane Changing Assistant
Objective: To develop a model in Matlab environment for Highway Assistant – Lane Changing Assistant algorithm as per MBD guidelines and generate code with AUTOSAR coder.
Introduction to the Feature:
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.
Basic Working Principle:
Highway Assistant is a partially automated driving function for a speed range of up to 180 km/h (112 mph) on highways. It combines the radar-based longitudinal guidance of Adaptive Cruise Control (ACC) with the video-based lateral guidance of lane keeping support in one system. Highway Assistant can be supplemented by an automatic lane change initiated and monitored by the driver in a speed range of 60 – 130 km/h (35 – 80 mph).
The lane Change Assistant works by using two mid-range radar sensors that are concealed in the rear bumper – one on the left, one on the right. These two sensors monitor the area alongside and behind the car. Powerful control software collates the sensor information to create a complete picture of all traffic in the area behind the vehicle. Whenever another vehicle approaches at speed from behind or is already present in the blind spot, a signal such as a warning light in the side mirror alerts the driver to the hazard. Should the driver still activate the turn signal with the intention of changing lanes, the system issues an additional acoustic and/or haptic warning.
Model Development:
After going through the requirement document a model is developed in MATLAB Simulink with MBD guidelines on mind. For the input and output signals a Simulink data dictionary is created and linked , then model advisor check is performed followed by Code Generation using the AUTOSAR Coder.
The final model is shown in the figure below.

The model has total four inputs and four outputs. This figure shows the top layer of the model. Inside the ‘HA_LCA’ subsystem, there are three different subsystems for each requirement. The following figure shows the interconnection of the subsystems.

All the subsystems are discussed one by one below.
- Requirement No 1 [Highway_DisplayUnit] Subsystem:
The requirement for the first system is shared as--
- 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 |
In accordance with the information, the subsystem is build using Stateflow chart, inport and out ports. The finished subsystem looks like the following diagram-

Inside the chart the logic is build such that the default state is the condition 1 and then with proper input, the transition to the second condition. The chart logic is shown as below along with symbols pane configuration.

- Requirement No 2 [Lane_DisplayUnit] Subsystem:
The requirements for the second subsystem is given as follows-
- 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 |
The second subsystem is also built with a Stateflow chart with 3 inports and 4 outports. The block diagram below shows the completed structure of the subsystem.

The chart logic is implemented similarly as in the first subsystem. The condition 1 is made default state. The chart logic along with symbols pane is attached in the figure below.


The signals ‘Enable_Display’ and ‘Input_Switch’ are routed to this subsystem using Goto and From blocks to keep the model neat in the main subsystem(HA_LCA).
- Requirement No 3:
This is the last subsystem in the main algorithm. The requirements for this subsystem are-
- 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”.
Accordingly, switch block operations are performed. The signal “Highway_Input_Signal” is brought to this subsystem using Goto and From blocks, this is done to reduce the connecting lines. The block diagram is shown below-

SLDD Creation :
The Simulink data dictionary is created with the help data provided and linked with the model.
Input Signals:
|
Name of the Signal |
Data Type |
Range |
|
Highway_Input_Signal |
uint8 |
0 – 255 |
|
Enable_Display |
uint8 |
0 – 255 |
|
Input_Switch |
uint8 |
0 – 255 |
|
Lane_Input_Signal |
uint8 |
0 – 255 |
Local Signals:
|
Name of the Signal |
Data Type |
Range |
|
Highway_Display_Mode_1 |
uint8 |
0 – 255 |
|
Highway_Display_Mode_2 |
uint8 |
0 – 255 |
|
Highway_Display_Mode_3 |
uint8 |
0 – 255 |
|
Highway_Display_Mode_4 |
uint8 |
0 – 255 |
|
Lane_Display_Mode_1 |
uint8 |
0 – 255 |
|
Lane_Display_Mode_2 |
uint8 |
0 – 255 |
|
Lane_Display_Mode_3 |
uint8 |
0 – 255 |
|
Lane_Display_Mode_4 |
uint8 |
0 – 255 |
Output Signals:
|
Name of the Signal |
Data Type |
Range |
|
Display_Mode_1 |
uint8 |
0 – 255 |
|
Display_Mode_2 |
uint8 |
0 – 255 |
|
Display_Mode_3 |
uint8 |
0 – 255 |
|
Display_Mode_4 |
uint8 |
0 – 255 |
In general the storage class for input signals it is as ‘ImportedExtern’, for output signals it is ’ExportToFile’ and lastly for local signal ‘Localizable’ class is selected. But, the Autosar Coder cannot able to generate codes when the storage class differs from Auto. Hence, the input and output signals are left in ‘Auto’ storage class. The snapshot of the finished SLDD is shown here.

Signal Traceability:
The signals are resolved where they appear for the first time and then they are propagated forward.

Similar procedure is followed for every signal.
Requirement Tagging:
Each subsystem created as per requirement document is linked with the document itself. Tagging is done by right clicking on the subsystem and selecting requirements from the context menu. This operation requires the word file to be kept open. A snapshot is shared after the subsystem is been tagged.

AUTOSAR Dictionary:
To be able to generate code in Autosar coder , various ports and interfaces need to be and configured at the first place. This is done with the help of Autosar Dictionary.
First we select the Autosar Coder from the apps section on the top ribbon. There we select automatic creation of runnables based on the Simulink model. After few seconds we are able to access the Autosar Dictionary. Although Simulink creates inports , outports and the interfaces ; but their names are not according to the Autosar standards. For instance an input signal must have ‘Rp_’ in the beginning of its name, which is found on the automatically created entries.
So all the inports, outports, s-r interfaces and data elements are renamed as per Autosar standards.

fig. Receiver Ports or Inports modifications.

fig. Sender Ports or Outports modifications(must have prefix Pp_ ).

fig. S-R interfaces (must have prefix SRIf_ )

fig. Data elements (must have prefix DE_)
With all the modifications done, an update is performed in the SW component mapping window. It updated the model without any error. A snap shot is added showing the components-

fig. Code mapping (Inports)

fig. Code mapping (Outports)
Model Advisor Report:
After building the model, configuring SLDD and Autosar dictionary; we proceed to MBD guidelines check. In the Model Advisor window Mab guidelines are selected and checks are run.

After few seconds the checks are complete. The model passed all the checks with a very few warning that can be ignored. No fail cases were detected.
AUTOSAR Code Generation:
After success in the model advisor we proceed with the code generation. The target file selected for the code generation is ‘autosar.tlc’ and as usual solver is set to ‘Fixed Step Discrete’.

With the configuration settings out of the way, the code generated using the Autosar Coder app from the top ribbon area. It took few seconds and the code is generated successfully. A snapshot of the code generation report is shared below.

The generated code is saved in a new folder with a name ending with '_autosar_rtw' in the same working path.
C-Code:
/*
* File: P_hw_lca.c
*
* Code generated for Simulink model 'P_hw_lca'.
*
* Model version : 1.17
* Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
* C/C++ source code generated on : Mon Feb 7 01:13:06 2022
*
* Target selection: autosar.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "P_hw_lca.h"
#include "P_hw_lca_private.h"
/* Named constants for Chart: '<S2>/Chart' */
#define P_hw_lca_IN_Condition_1 ((uint8)1U)
#define P_hw_lca_IN_Condition_2 ((uint8)2U)
/* Block states (default storage) */
DW_P_hw_lca_T P_hw_lca_DW;
/* Model step function */
void P_hw_lca_Step(void)
{
/* local block i/o variables */
uint8 Lane_Display_Mode_1;
uint8 Lane_Display_Mode_2;
uint8 Lane_Display_Mode_3;
uint8 Lane_Display_Mode_4;
uint8 Highway_Display_Mode_1;
uint8 Highway_Display_Mode_2;
uint8 Highway_Display_Mode_3;
uint8 Highway_Display_Mode_4;
/* Chart: '<S2>/Chart' incorporates:
* Inport: '<Root>/Enable_Display'
* Inport: '<Root>/Highway_Input_Signal'
* Inport: '<Root>/Input_Switch'
*/
if (P_hw_lca_DW.is_active_c3_P_hw_lca == 0U) {
P_hw_lca_DW.is_active_c3_P_hw_lca = 1U;
P_hw_lca_DW.is_c3_P_hw_lca = P_hw_lca_IN_Condition_1;
Highway_Display_Mode_1 = 232U;
Highway_Display_Mode_2 = 183U;
Highway_Display_Mode_3 = 41U;
Highway_Display_Mode_4 = 94U;
} else if (P_hw_lca_DW.is_c3_P_hw_lca == P_hw_lca_IN_Condition_1) {
Highway_Display_Mode_1 = 232U;
Highway_Display_Mode_2 = 183U;
Highway_Display_Mode_3 = 41U;
Highway_Display_Mode_4 = 94U;
if ((Rte_IRead_P_hw_lca_Step_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
() == 1) &&
(Rte_IRead_P_hw_lca_Step_Rp_Enable_Display_DE_Enable_Display() == 1) &&
(Rte_IRead_P_hw_lca_Step_Rp_Input_Switch_DE_Input_Switch() == 1)) {
P_hw_lca_DW.is_c3_P_hw_lca = P_hw_lca_IN_Condition_2;
Highway_Display_Mode_1 = 213U;
Highway_Display_Mode_2 = 183U;
Highway_Display_Mode_3 = 9U;
Highway_Display_Mode_4 = 94U;
}
} else {
/* case IN_Condition_2: */
Highway_Display_Mode_1 = 213U;
Highway_Display_Mode_2 = 183U;
Highway_Display_Mode_3 = 9U;
Highway_Display_Mode_4 = 94U;
if ((Rte_IRead_P_hw_lca_Step_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
() == 1) &&
(Rte_IRead_P_hw_lca_Step_Rp_Enable_Display_DE_Enable_Display() == 0) &&
(Rte_IRead_P_hw_lca_Step_Rp_Input_Switch_DE_Input_Switch() == 1)) {
P_hw_lca_DW.is_c3_P_hw_lca = P_hw_lca_IN_Condition_1;
Highway_Display_Mode_1 = 232U;
Highway_Display_Mode_2 = 183U;
Highway_Display_Mode_3 = 41U;
Highway_Display_Mode_4 = 94U;
}
}
/* End of Chart: '<S2>/Chart' */
/* Chart: '<S3>/Chart' incorporates:
* Inport: '<Root>/Enable_Display'
* Inport: '<Root>/Input_Switch'
* Inport: '<Root>/Lane_Input_Signal'
*/
if (P_hw_lca_DW.is_active_c1_P_hw_lca == 0U) {
P_hw_lca_DW.is_active_c1_P_hw_lca = 1U;
P_hw_lca_DW.is_c1_P_hw_lca = P_hw_lca_IN_Condition_1;
Lane_Display_Mode_1 = 132U;
Lane_Display_Mode_2 = 185U;
Lane_Display_Mode_3 = 54U;
Lane_Display_Mode_4 = 67U;
} else if (P_hw_lca_DW.is_c1_P_hw_lca == P_hw_lca_IN_Condition_1) {
Lane_Display_Mode_1 = 132U;
Lane_Display_Mode_2 = 185U;
Lane_Display_Mode_3 = 54U;
Lane_Display_Mode_4 = 67U;
if ((Rte_IRead_P_hw_lca_Step_Rp_Lane_Input_Signal_DE_Lane_Input_Signal() ==
6) && (Rte_IRead_P_hw_lca_Step_Rp_Enable_Display_DE_Enable_Display() ==
1) && (Rte_IRead_P_hw_lca_Step_Rp_Input_Switch_DE_Input_Switch()
== 1)) {
P_hw_lca_DW.is_c1_P_hw_lca = P_hw_lca_IN_Condition_2;
Lane_Display_Mode_1 = 127U;
Lane_Display_Mode_2 = 248U;
Lane_Display_Mode_3 = 186U;
Lane_Display_Mode_4 = 84U;
}
} else {
/* case IN_Condition_2: */
Lane_Display_Mode_1 = 127U;
Lane_Display_Mode_2 = 248U;
Lane_Display_Mode_3 = 186U;
Lane_Display_Mode_4 = 84U;
if ((Rte_IRead_P_hw_lca_Step_Rp_Lane_Input_Signal_DE_Lane_Input_Signal() ==
6) && (Rte_IRead_P_hw_lca_Step_Rp_Enable_Display_DE_Enable_Display() ==
0) && (Rte_IRead_P_hw_lca_Step_Rp_Input_Switch_DE_Input_Switch()
== 1)) {
P_hw_lca_DW.is_c1_P_hw_lca = P_hw_lca_IN_Condition_1;
Lane_Display_Mode_1 = 132U;
Lane_Display_Mode_2 = 185U;
Lane_Display_Mode_3 = 54U;
Lane_Display_Mode_4 = 67U;
}
}
/* End of Chart: '<S3>/Chart' */
/* Switch: '<S4>/Switch' incorporates:
* Inport: '<Root>/Highway_Input_Signal'
* Switch: '<S4>/Switch1'
* Switch: '<S4>/Switch2'
* Switch: '<S4>/Switch3'
*/
if (Rte_IRead_P_hw_lca_Step_Rp_Highway_Input_Signal_DE_Highway_Input_Signal()
!= 0) {
/* Outport: '<Root>/Display_Mode_1' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_1_DE_Display_Mode_1
(Highway_Display_Mode_1);
/* Outport: '<Root>/Display_Mode_2' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_2_DE_Display_Mode_2
(Highway_Display_Mode_2);
/* Outport: '<Root>/Display_Mode_3' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_3_DE_Display_Mode_3
(Highway_Display_Mode_3);
/* Outport: '<Root>/Display_Mode_4' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_4_DE_Display_Mode_4
(Highway_Display_Mode_4);
} else {
/* Outport: '<Root>/Display_Mode_1' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_1_DE_Display_Mode_1
(Lane_Display_Mode_1);
/* Outport: '<Root>/Display_Mode_2' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_2_DE_Display_Mode_2
(Lane_Display_Mode_2);
/* Outport: '<Root>/Display_Mode_3' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_3_DE_Display_Mode_3
(Lane_Display_Mode_3);
/* Outport: '<Root>/Display_Mode_4' */
Rte_IWrite_P_hw_lca_Step_Pp_Display_Mode_4_DE_Display_Mode_4
(Lane_Display_Mode_4);
}
/* End of Switch: '<S4>/Switch' */
}
/* Model initialize function */
void P_hw_lca_Init(void)
{
/* (no initialization code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/