Challenge

Project 2-Highway Assistant-Lane Changing Assistant

HIGHWAY ASSISTANT- LANE CHANGING ASSISTANT

AIM:

To develop one specific requirement of Highway Assistant – Lane Changing Assistant algorithm. The whole Highway Assistant – Lane Changing Assistant is a very huge algorithm & only one small part of the logic is implemented here. Idea is to familiarize with concepts of Autosar Software Component Development in MATLAB Environment by following the Model Based Development guidelines.

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

THEORY:

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.

1. According to the specified requirements , the Simulink model is created with the following subsystems.

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

Lane changing assistant Simulink model:

Subsystems for Highway_Display and Requirement No 3

Subsystem for Highway_Display Unit and Lnae_Display_unit

Stateflow logic for Highway_display_unit

The stateflow logic for Highway display unit is implemented as follows as per the given requirement given in the problem statement.

The stateflow logic for Lane display unit

  1. Simulink Data Dictionary is created and stored under the name "highway_LCASLDD.sldd" and is added to the Model Workspace. The various signals along with it's Data Type and Range in sldd is shown below:

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

Simulink Data Dictionary:

3.The input signals are selected and are resolved by enabling "Signal name must resolve into Simulink Signal Object" from the "properties" obtained by right clicking the signal line. Similarly, all other signals are propogated at each stage of the model, and for each sub-system in the model.

4.In the configuration settings, Select Code generation and select System Target File as autosar.tlc and save the changes as shown here:

  1. According to the rules in MBD, the topmost level should contain only a single sub-system and the signal names should be placed in the beginning of the signal, which is done in the Simulink Model created.
  2. Now save the Model and run it once to ensure that there are no errors in it.
  3. To make the model in Autosar environment, go to APPS in the top menu, and select 'Autosar Component Designer'. The matlab model opens with "Code Mappings_AUTOSAR SW Component" shown in the bottom left corner of the page.

8.Select the "Code Mappings_AUTOSAR SW Component" and open the Autosar Dictionary.

  1. In the XML Options, make necessary changes as given below:

10. Add the SRIf ie, Sender Receiver Interface to the AUTOSAR Dictionary.

11. Add the output ports under senderports with a prefix Pp_.

12. Similarly, add all the input signals under ReceiverPorts with a prefix Rp_

13.The runnables are set to "Highway_Lane_Changing_Init" and "Event_Highway_Lane_Changing_50ms".

Now map the signals in the "inports" tab of 'code mapping' to the corresponding port and data element.

Also map the signals in the "outports" tab of 'code mapping' to the corresponding port and data element.

Refresh the model ie, update by clicking the green coloured curved sign and save it. now, click on the green tick under "code mappings " to validate the model.

Here, validation is completed successfully.

14. For generating the model advisor report, Open Model Advisor and run the checks for Modeling standars for MAB and Modeling standars for ISO 26262. The report is generated once the checks are run.

15. The Model Advisor report is generated with zero errors and very less warnings.

16. For Code Generation, click on Quick start and follow the steps by clicking "Next", "Next"... and finally click "finish".

Code generation different stages in Quick Start:

17. C code is generated along with .h and other files.

18. The generated c code is attached below:

/*
 * File: Highway_Lane_Changing.c
 *
 * Code generated for Simulink model 'Highway_Lane_Changing'.
 *
 * Model version                  : 1.2
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Mon Feb  7 18:47:23 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 "Highway_Lane_Changing.h"

/* Named constants for Chart: '/Highway_Display_Unit' */
#define IN_Default                     ((uint8)1U)
#define IN_Display_off                 ((uint8)2U)
#define IN_Display_on                  ((uint8)3U)

/* Block signals and states (default storage) */
DW rtDW;

/* Model step function */
void Highway_Lane_Changing_Step(void)
{
  sint32 tmp_0;
  sint32 tmp_1;
  sint32 tmp_2;
  uint8 tmp;

  /* Chart: '/Highway_Display_Unit' incorporates:
   *  Inport: '/Enable_Display'
   *  Inport: '/Highway_Input_Signal'
   *  Inport: '/Input_Switch'
   */
  if (rtDW.is_active_c3_Highway_Lane_Chang == 0U) {
    rtDW.is_active_c3_Highway_Lane_Chang = 1U;
    rtDW.is_c3_Highway_Lane_Changing = IN_Default;
  } else {
    switch (rtDW.is_c3_Highway_Lane_Changing) {
     case IN_Default:
      tmp_0 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
        ();
      tmp_1 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Enable_Display_DE_Enable_Display
        ();
      tmp_2 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Input_Switch_DE_Input_Switch();
      if ((tmp_0 == 1) && (tmp_1 == 0) && (tmp_2 == 1)) {
        rtDW.is_c3_Highway_Lane_Changing = IN_Display_off;
        rtDW.Highway_Display_Mode_1 = 232.0;
        rtDW.Highway_Display_Mode_2 = 183.0;
        rtDW.Highway_Display_Mode_3 = 41.0;
        rtDW.Highway_Display_Mode_4 = 94.0;
      } else if ((tmp_0 == 1) && (tmp_1 == 1) && (tmp_2 == 1)) {
        rtDW.is_c3_Highway_Lane_Changing = IN_Display_on;
        rtDW.Highway_Display_Mode_1 = 213.0;
        rtDW.Highway_Display_Mode_2 = 183.0;
        rtDW.Highway_Display_Mode_3 = 9.0;
        rtDW.Highway_Display_Mode_4 = 94.0;
      }
      break;

     case IN_Display_off:
      rtDW.Highway_Display_Mode_1 = 232.0;
      rtDW.Highway_Display_Mode_2 = 183.0;
      rtDW.Highway_Display_Mode_3 = 41.0;
      rtDW.Highway_Display_Mode_4 = 94.0;
      break;

     default:
      /* case IN_Display_on: */
      rtDW.Highway_Display_Mode_1 = 213.0;
      rtDW.Highway_Display_Mode_2 = 183.0;
      rtDW.Highway_Display_Mode_3 = 9.0;
      rtDW.Highway_Display_Mode_4 = 94.0;
      break;
    }
  }

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

  /* Chart: '/Lane_Display_Unit' incorporates:
   *  Inport: '/Enable_Display'
   *  Inport: '/Input_Switch'
   *  Inport: '/Lane_Input_Signal'
   */
  if (rtDW.is_active_c1_Highway_Lane_Chang == 0U) {
    rtDW.is_active_c1_Highway_Lane_Chang = 1U;
    rtDW.is_c1_Highway_Lane_Changing = IN_Default;
  } else {
    switch (rtDW.is_c1_Highway_Lane_Changing) {
     case IN_Default:
      tmp_0 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Lane_Input_Signal_DE_Lane_Input_Signal
        ();
      tmp_1 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Enable_Display_DE_Enable_Display
        ();
      tmp_2 =
        Rte_IRead_Highway_Lane_Changing_Step_Rp_Input_Switch_DE_Input_Switch();
      if ((tmp_0 == 6) && (tmp_1 == 0) && (tmp_2 == 1)) {
        rtDW.is_c1_Highway_Lane_Changing = IN_Display_off;
        rtDW.Lane_Display_Mode_1 = 132.0;
        rtDW.Lane_Display_Mode_2 = 185.0;
        rtDW.Lane_Display_Mode_3 = 54.0;
        rtDW.Lane_Display_Mode_4 = 67.0;
      } else if ((tmp_0 == 6) && (tmp_1 == 1) && (tmp_2 == 1)) {
        rtDW.is_c1_Highway_Lane_Changing = IN_Display_on;
        rtDW.Lane_Display_Mode_1 = 127.0;
        rtDW.Lane_Display_Mode_2 = 248.0;
        rtDW.Lane_Display_Mode_3 = 186.0;
        rtDW.Lane_Display_Mode_4 = 84.0;
      }
      break;

     case IN_Display_off:
      rtDW.Lane_Display_Mode_1 = 132.0;
      rtDW.Lane_Display_Mode_2 = 185.0;
      rtDW.Lane_Display_Mode_3 = 54.0;
      rtDW.Lane_Display_Mode_4 = 67.0;
      break;

     default:
      /* case IN_Display_on: */
      rtDW.Lane_Display_Mode_1 = 127.0;
      rtDW.Lane_Display_Mode_2 = 248.0;
      rtDW.Lane_Display_Mode_3 = 186.0;
      rtDW.Lane_Display_Mode_4 = 84.0;
      break;
    }
  }

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

  /* Switch: '/Switch' incorporates:
   *  Inport: '/Highway_Input_Signal'
   *  Switch: '/Switch1'
   *  Switch: '/Switch2'
   *  Switch: '/Switch3'
   */
  tmp_0 =
    Rte_IRead_Highway_Lane_Changing_Step_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
    ();
  if (tmp_0 > 0) {
    tmp = (uint8)rtDW.Highway_Display_Mode_1;
  } else {
    tmp = (uint8)rtDW.Lane_Display_Mode_1;
  }

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

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

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

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

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

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

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

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

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

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

Link: https://drive.google.com/drive/folders/1t__yxNQ6X0slgEv16aVH1kJFrPEfnAni?usp=sharing

RESULT:

The Highway Assistant Lane Changing Assistant model is developed in MATLAB Simulink per MBD guidelines and Simulink Data Dictionary is created for the model & is linked to the model. All the input & output signals is mapped into the Autosar Editor and the Model Advisor Report is generated & followed by Code Generation in Autosar Coder.

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.