Challenge

Project 2-Highway Assistant-Lane Changing Assistant

Aim - Designing High-way Assistant Lane changing Assistant feature using Model Based Development in MATLAB - Simulink environment.

Software used - MATLAB R2020a

Objectives -

  • This model must be developed in MATLAB Simulink per MBD guidelines.
  • Code Generation target file 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.

Introduction -

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.

  • The lane-change assistant, like the lane departure warning system, falls within the family of lane-assist systems. While the lane-departure warning system works with a front camera, the lane-change assistant is based on a radar system in the rear of the vehicle.
  • The system is based on two radar sensors at the rear end of the vehicle which continuously monitor the areas alongside and diagonally behind the vehicle. If the system detects vehicles in the blind spot or vehicles approaching rapidly from behind, it warns the driver with an illuminated symbol in the area of the wing mirrors, for example.
  • If the driver actuates the turn signal indicator to change lane, the system can additionally provide an acoustic and/or haptic warning to call the driver’s attention to the potential danger.
  • As an active safety system, the lane-change assistant helps prevent accidents by avoiding hazardous situations when changing lanes as far as possible. In doing so, it makes an important contribution to reducing accident statistics in spite of increasingly dense road traffic.

How does it work?

  • 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.

Now we will design this ADAS feature in MATLAB - simulink environment with concepts of Autosar Software Component Development.

The model would look like this -

  • This is how the model looks like.
  • Name the main subsystem as Highway Assistant Lane changing and now we will design the model as per the given requirements.
  • Before that we will create a simulink data dictionary in order to model the system.

The given signals are-

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

We will create all these signals in the SLDD. Firstly, click on the link to data dictionary option and name the sldd file as per our choice.

  • Here I named it as Highwaylane.sldd and now click on enable model access to base workspace and click on Migrate data option and our sldd file will be created.
  • Enter all the signals as shown below and sldd will look like -

SLDD file - https://drive.google.com/file/d/1wrLjJYtogKK25RDT3muiwO5Z3yKBs8MG/view?usp=sharing

Now we will design the model as per the given requirements.

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

Requirement 1 looks like this -

The chart has a state diagram like this -

And the symbol pane for this stateflow will be -

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

Requirement 2 looks like this -

The chart looks like this -

And the symbol pane for this stateflow will be -

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”.

Requirement 3 looks like this -

After designing all the requirements the subsystem looks like this-

where the Lane_Displayunit(req2) is the enabled subsystem and it is only enabled when it is equal to 6 .

The overall Highway Assistant – Lane Changing Assistant will look like this-

  • Signal resolution will be done as shown below.
  • right click on the signal and click on signal name must resolve to Simulink signal object.
  • First signal resolution is as shown below.

Code Generation Settings-

  • Click on the configuration parameters.
  • Now go to code geneartion option.
  • Click on System target file and browse to autosar.tlc
  • set language to C as shown.

Autosar Port Mapping-

  • In order to map the autosar port mappings we first click on app and click on Autosar Component.
  • Now validate all the signals to autosar dictionary as shown,

  • Click on green check in order to validate.
  • All the inports and outport signals will be validated as shown,

Now successfull validation report window will be pop up as shown,

This is how the model looks after the Autosar Validation and model changed to Autosar compliant model.

Model Advisor Report-

  • The Model advisor check should be done in order to find the simulation errors.
  • If there are any failed conditions the system won't generate code.
  • Click on model advisor configuration settings and click on by product and by tast and selected checks will be run as shown.

  • Now the selected checks will be run and the model advisory report will be genearated.
  • The report has around 115 passed conditions with zero failed conditions and 26 warnings.
  • These warnings can be ignored. Then the model will generate the code.

Model Advisory Report - https://drive.google.com/file/d/1m5IBUKcBEB2qfw3xEI9eTbjdNhK-kSab/view?usp=sharing

Now the model is ready to generate the code.

Steps for code generation-

  • Click on the main subsystem in order to build the model.
  • The code generation target file should be autosar.tlc
  • Then after buliding the subsystem click on generate code option as shown,

The code will be generated as follows-

/*
 * File: HighwayLane_assistant.c
 *
 * Code generated for Simulink model 'HighwayLane_assistant'.
 *
 * Model version                  : 1.29
 * Simulink Coder version         : 9.3 (R2020a) 18-Nov-2019
 * C/C++ source code generated on : Wed Nov 17 18:48:18 2021
 *
 * Target selection: autosar.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "HighwayLane_assistant.h"
#include "HighwayLane_assistant_private.h"

/* Named constants for Chart: '/Chart' */
#define HighwayLane_assi_IN_Condition_1 ((uint8)1U)
#define HighwayLane_assi_IN_Condition_2 ((uint8)2U)

/* Block signals (default storage) */
B_HighwayLane_assistant_T HighwayLane_assistant_B;

/* Block states (default storage) */
DW_HighwayLane_assistant_T HighwayLane_assistant_DW;

/* Model step function */
void HighwayLane_assistant_Step(void)
{
  sint32 rtb_Highway_Display_Mode_1;
  sint32 rtb_Highway_Display_Mode_3;
  float64 tmp;
  sint32 tmp_0;

  /* Chart: '/Chart' incorporates:
   *  Inport: '/Enable_Display'
   *  Inport: '/Highway_Input_Signal'
   *  Inport: '/Input_Switch'
   */
  if (HighwayLane_assistant_DW.is_active_c3_HighwayLane_assist == 0U) {
    HighwayLane_assistant_DW.is_active_c3_HighwayLane_assist = 1U;
    HighwayLane_assistant_DW.is_c3_HighwayLane_assistant =
      HighwayLane_assi_IN_Condition_1;
    rtb_Highway_Display_Mode_1 = 232;
    rtb_Highway_Display_Mode_3 = 41;
  } else if (HighwayLane_assistant_DW.is_c3_HighwayLane_assistant ==
             HighwayLane_assi_IN_Condition_1) {
    if ((Rte_IRead_HighwayLane_assistant_Step_Highway_Input_Signal_Highway_Input_Signal
         () == 1) &&
        (Rte_IRead_HighwayLane_assistant_Step_Enable_Display_Enable_Display() ==
         1) && (Rte_IRead_HighwayLane_assistant_Step_Input_Switch_Input_Switch()
                == 1)) {
      HighwayLane_assistant_DW.is_c3_HighwayLane_assistant =
        HighwayLane_assi_IN_Condition_2;
      rtb_Highway_Display_Mode_1 = 213;
      rtb_Highway_Display_Mode_3 = 9;
    } else {
      rtb_Highway_Display_Mode_1 = 232;
      rtb_Highway_Display_Mode_3 = 41;
    }
  } else {
    /* case IN_Condition_2: */
    if ((Rte_IRead_HighwayLane_assistant_Step_Highway_Input_Signal_Highway_Input_Signal
         () == 1) &&
        (Rte_IRead_HighwayLane_assistant_Step_Enable_Display_Enable_Display() ==
         0) && (Rte_IRead_HighwayLane_assistant_Step_Input_Switch_Input_Switch()
                == 1)) {
      HighwayLane_assistant_DW.is_c3_HighwayLane_assistant =
        HighwayLane_assi_IN_Condition_1;
      rtb_Highway_Display_Mode_1 = 232;
      rtb_Highway_Display_Mode_3 = 41;
    } else {
      rtb_Highway_Display_Mode_1 = 213;
      rtb_Highway_Display_Mode_3 = 9;
    }
  }

  /* End of Chart: '/Chart' */

  /* Outputs for Enabled SubSystem: '/Enabled Subsystem' incorporates:
   *  EnablePort: '/Enable'
   */
  /* RelationalOperator: '/Compare' incorporates:
   *  Constant: '/Constant'
   *  Inport: '/Lane_Input_Signal'
   */
  if (Rte_IRead_HighwayLane_assistant_Step_Lane_Input_Signal_Lane_Input_Signal()
      == 6) {
    /* Chart: '/Chart' incorporates:
     *  Inport: '/Enable_Display'
     *  Inport: '/Input_Switch'
     */
    if (HighwayLane_assistant_DW.is_active_c1_HighwayLane_assist == 0U) {
      HighwayLane_assistant_DW.is_active_c1_HighwayLane_assist = 1U;
      HighwayLane_assistant_DW.is_c1_HighwayLane_assistant =
        HighwayLane_assi_IN_Condition_1;
      HighwayLane_assistant_B.Lane_Display_Mode_1 = 132.0;
      HighwayLane_assistant_B.Lane_Display_Mode_2 = 185.0;
      HighwayLane_assistant_B.Lane_Display_Mode_3 = 54.0;
      HighwayLane_assistant_B.Lane_Display_Mode_4 = 67.0;
    } else if (HighwayLane_assistant_DW.is_c1_HighwayLane_assistant ==
               HighwayLane_assi_IN_Condition_1) {
      if ((Rte_IRead_HighwayLane_assistant_Step_Enable_Display_Enable_Display() ==
           1) && (Rte_IRead_HighwayLane_assistant_Step_Input_Switch_Input_Switch
                  () == 1)) {
        HighwayLane_assistant_DW.is_c1_HighwayLane_assistant =
          HighwayLane_assi_IN_Condition_2;
        HighwayLane_assistant_B.Lane_Display_Mode_1 = 127.0;
        HighwayLane_assistant_B.Lane_Display_Mode_2 = 248.0;
        HighwayLane_assistant_B.Lane_Display_Mode_3 = 186.0;
        HighwayLane_assistant_B.Lane_Display_Mode_4 = 84.0;
      } else {
        HighwayLane_assistant_B.Lane_Display_Mode_1 = 132.0;
        HighwayLane_assistant_B.Lane_Display_Mode_2 = 185.0;
        HighwayLane_assistant_B.Lane_Display_Mode_3 = 54.0;
        HighwayLane_assistant_B.Lane_Display_Mode_4 = 67.0;
      }
    } else {
      /* case IN_Condition_2: */
      if ((Rte_IRead_HighwayLane_assistant_Step_Enable_Display_Enable_Display() ==
           0) && (Rte_IRead_HighwayLane_assistant_Step_Input_Switch_Input_Switch
                  () == 1)) {
        HighwayLane_assistant_DW.is_c1_HighwayLane_assistant =
          HighwayLane_assi_IN_Condition_1;
        HighwayLane_assistant_B.Lane_Display_Mode_1 = 132.0;
        HighwayLane_assistant_B.Lane_Display_Mode_2 = 185.0;
        HighwayLane_assistant_B.Lane_Display_Mode_3 = 54.0;
        HighwayLane_assistant_B.Lane_Display_Mode_4 = 67.0;
      } else {
        HighwayLane_assistant_B.Lane_Display_Mode_1 = 127.0;
        HighwayLane_assistant_B.Lane_Display_Mode_2 = 248.0;
        HighwayLane_assistant_B.Lane_Display_Mode_3 = 186.0;
        HighwayLane_assistant_B.Lane_Display_Mode_4 = 84.0;
      }
    }

    /* End of Chart: '/Chart' */
  }

  /* End of RelationalOperator: '/Compare' */
  /* End of Outputs for SubSystem: '/Enabled Subsystem' */

  /* Switch: '/Switch' incorporates:
   *  Inport: '/Highway_Input_Signal'
   *  Switch: '/Switch1'
   *  Switch: '/Switch2'
   *  Switch: '/Switch3'
   */
  tmp_0 =
    Rte_IRead_HighwayLane_assistant_Step_Highway_Input_Signal_Highway_Input_Signal
    ();
  if (tmp_0 > 0) {
    tmp = rtb_Highway_Display_Mode_1;
  } else {
    tmp = HighwayLane_assistant_B.Lane_Display_Mode_1;
  }

  /* End of Switch: '/Switch' */

  /* Outport: '/Display_Mode_1' */
  Rte_IWrite_HighwayLane_assistant_Step_Display_Mode_1_Display_Mode_1(tmp);

  /* Switch: '/Switch1' */
  if (tmp_0 > 0) {
    tmp = 183.0;
  } else {
    tmp = HighwayLane_assistant_B.Lane_Display_Mode_2;
  }

  /* Outport: '/Display_Mode_2' */
  Rte_IWrite_HighwayLane_assistant_Step_Display_Mode_2_Display_Mode_2(tmp);

  /* Switch: '/Switch2' */
  if (tmp_0 > 0) {
    tmp = rtb_Highway_Display_Mode_3;
  } else {
    tmp = HighwayLane_assistant_B.Lane_Display_Mode_3;
  }

  /* Outport: '/Display_Mode_3' */
  Rte_IWrite_HighwayLane_assistant_Step_Display_Mode_3_Display_Mode_3(tmp);

  /* Switch: '/Switch3' */
  if (tmp_0 > 0) {
    tmp = 94.0;
  } else {
    tmp = HighwayLane_assistant_B.Lane_Display_Mode_4;
  }

  /* Outport: '/Display_Mode_4' */
  Rte_IWrite_HighwayLane_assistant_Step_Display_Mode_4_Display_Mode_4(tmp);
}

/* Model initialize function */
void HighwayLane_assistant_Init(void)
{
  /* (no initialization code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */

The link for this model is -

https://drive.google.com/file/d/1aUU5fQibIDjyRfyEs2yki60cUV3Eyglx/view?usp=sharing

Conclusion - One of the ADAS features Highway Assistant – Lane Changing Assistant's small algorithm is successfully implemented in the simulink model using MBD. All the supported images have been attached and the successfully Autosar validation is done followed by the successfull model advisor report. After the model advisor check successfully code has been generated in the selected target file. And the code has been attached. And the model is attached in .slx form.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.