Challenge

Project 2-Highway Assistant-Lane Changing Assistant

Highway Assistant-Lane Changing Assistant

Aim:- Develop a model as per the given requirements and generate autosar software compile code.

OBJECTIVE:-

  • This Model must be developed in MATLAB Simulink as per the MBD guidelines.
  • Code generation profile must be AUTOSAr coader.
  • Simulink Data Dictionary must be created for the model & must be linked to the model.
  • All the input and output signals must be mapped into the AUTOSAr editor
  • Model Advisor report is mandatory and this will be followed by Code Generation.

THEORY:-

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.

Simulink Model:-

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

We took two states Condition 1 and condition 2 and added the given state action to both states as per the given requirements.

Then gave the transition condition from state 1 to state 2 as.

[(Highway_Input_Signal = =1&&

(Enable_Display ==1)&&

(Input_Switch==1)].

Then gave transition condition from state 2 to state 1 as

[(Highway_Input_Signal = =1&&

(Enable_Display ==0)&&

(Input_Switch==1)].

Now we validate the signals in the signal pane

Here we create an inports and outports of subsystem for further use.

  • 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

  1. We took two states Condition 1 and condition 2 and added the given state action to both states as per the given requirements.
  2. Then gave the transition condition from state 1 to state 2 as

    [(Lane_Input_Signal==6)&&

    (Enable_Display ==1)&&

    (Input_Switch ==1)].

  3. Then gave transition condition from state 2 to state 1 as

    [(Lane_Input_Signal==6)&&

    (Enable_Display ==0)&&

    (Input_Switch ==1)].

Now we validate the signals in the signal pane.

Here we create an inports and outports of subsystem for further use.

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

Here we used Switch blocks to swlwct the display mode and the control port of switch block is control with

“Highway_Display_Mode_1” & “Lane_Display_Mode_1” are given as inputs to a switch block.Now did this step to all the remaining display modes and lane display modes.

Main Model:-

Here we create a subsystem for the created model to create one single subsystem to operate.Created inports and outports for simulation purpose.

SLDD file Creation:-

  • 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

1.To create SLDD file under Modelling Tab in the design section there is one option link data dictionary.Click on that Tab.

2. The new window will open in that window click on new to create a new file and ceate a new file save this file in the same directory.

3. Now open this model and add all given signals and constants with all parameters.

4. If you see it here,we can edit and all parameters under one file.

5. No need to change parameter every time you open the model next time.

6. Once you save all parameters for variable in SLDD it will be saved until you use the file for model.

7. Also you can use one SLDD file for more than one model.

Signal Resolve and Propogation:-

1. In signal properties you can resolve and propogate the signals.

2. If the signal is the first type to appear in system you have resolve it otherwise propogate it.

3. Signal resolve and propgation is most important for code generation.

4. You ca propogate the signal directly on double click on signal and type (<>) only.Signals will propogate directly.

Requirement Tagging:-

1. Requirement TAgging is nothing but link your requirement document to the model subsystem which is related to that requirement.

2.It is given advantage to understand the model when someone new is handling this file.

3. We done requirement tagging by right clicking on subsystem under requirement parameters you can tag the requirement.

4.First you have to select the reuirement in the requirement document to tag with related subsystem.Also the file has to be saved in the same directory.

Model Configuration for AUTOSAR Code Generation:-

Code Generation Settings:-

1. There are mainly two settings we have to do which are solver settings and code generation settings.

2. For code ganeration we can only use a Fixed Step Solver.

3. As per requirement we can change the solver settting to Fix step discrete and Fix step size as Auto.

4. For AUTOSAR code ganeration in system Target file we always chose autosar.tlc,which is autosar component designer coder.Which generates AUTOSAR compile code.

Here we select AUTOSAR system target file to generate Autosar code.

To Map Simulink model elements to AUTOSAR software component elements:

  1. Open a model for which AUTOSAR system Target file autosar.tlc is selected.
  2. Create or open a MApped view of the AUTOSAR model.In the model window,do one of the following.
  • From the Apps tab,Open the AUTOSAR component designer app.

  • Click the prespective control in the lower-right corner and select code.

The following code mapping AUTOSAR software component window will open at the bottom left corner.

AUTOSAR Dictionary:-

Here we add XML options,server reciever interface,sender ports,reciever ports,and runnable one by one.

XML Options:-

Here we edit the XML options to create a data file for code gaeneration.

S-R Interface:-

Here before creating 'inports' and 'outports'. The interface were created in order to map the inports and outports,Interfaces were Prefix SIRF_ & there corresponding Data elements were prefix DE_.

Reciever Ports:-

Here inports were created and input Runnables were prefix Rp_ .

Sender Ports:-

Here outports were created and output Runnables were prefix Pp_ .

Runnables:-

Here runnables were created,one of the initializing and other for time event,event was also created as init event and TimingEvent.

Port Mapping:-

The Code Mapping editor provides incanvas access to AUTOSAR mapping information,with batch editing,element filtering,easy navigation to model elements and AUTOSAR properties,and model element traceability.

  • Navigate the code Mappings editor tabs to perform these actions:
  • Map a Simulink entry-point function to an AUTOSAR runnable.
  • Map a Simulink inport or outport to an AUTOSAR reciever or sender port and a sender-reciever data element,with a specific data access mode.
  • Map a Simulnk model workspace parameters to an AUTOSAR component parameters.
  • Map a Simulink data store to an AUTOSAR variable.
  • Map a Simulink block signal or state to an AUTOSAR variable.
  • Map a Simulink data transfer line to an AUTOSAR inter-Runnable variable (IRV).
  • Map a Simulink function caller to an AUTOSAR client port and a client-server operation.
  • Use the Filter contents field (Where available) to selectively display some elements, while omiting others,in the current view.
  • After mapping model elements,click the validate button to validate the AUTOSAR component configuration.If errors are reported,address them and retry validation.

Here we select Runnables for initializing and time events.

Here mapping of Inports was done with the corresponding data element.

Here mapping of outports was done eith the corresponding data elements.

Here we check our mapping to see if there are any bugs. If mapping has bugs,we can solve them immediately.

MAAB guideline check:- (Model Advisor):-

1. Under modeling Tab there is model advisor tab to check model with standard guidelines.

2. Tab on that tab this window will open to select model.

3. After selecting the model,the model advisor checked for the model first.

4. Then in the task option we have to select modelling standard for MAB. Then we have to select which guidelines we have to check.

5. Then run advisor check for selected checked guidelines.

6. If any error occour you can check for that under the MAB tab.

7. There are also some warnings.If it's greater that the requirement solves the warning and check again for that warning.

8. You can check for for individual error and warning also.

9. If you are searching for a particular block in a system.You can click on report on any block it will take you to that block.

10. After checking all models with standard guidelines,you can generate a model advisor report.

11. If you click on any lable highlighted in the report it will go directly to that particular model or signal.

Quick Start:-

If we missed out the configuration properties and also we have to take care of all updating the signal name appropriately for that we aill do AUTOSAR quick start over here so it will list out and show any mistake apart from that this is an automated procedure to convert your model into a generated code to bypass the mannual mapping.

Here we got our AUTOSAR compile code for AUTOSAR software component.

Generated Code:-

/*
 * File: Lane_Change_Assistance.c
 *
 * Code generated for Simulink model 'Lane_Change_Assistance'.
 *
 * Model version                  : 1.41
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Sun Jun 19 15:29:21 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: '<S2>/Chart' */
#define IN_Condition_1                 ((uint8)1U)
#define IN_Condition_2                 ((uint8)2U)

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

/* Model step function */
void Lane_Change_Assistance_Timing(void)
{
  sint32 tmp;
  uint8 rtb_Highway_Display_Mode_1;
  uint8 rtb_Highway_Display_Mode_3;
  uint8 rtb_Lane_Display_Mode_1;
  uint8 rtb_Lane_Display_Mode_2;
  uint8 rtb_Lane_Display_Mode_3;
  uint8 rtb_Lane_Display_Mode_4;

  /* Chart: '<S2>/Chart' incorporates:
   *  Inport: '<Root>/Enable_Display'
   *  Inport: '<Root>/Highway_Input_Signal'
   *  Inport: '<Root>/Input_Switch'
   */
  if (rtDW.is_active_c3_Lane_Change_Assistance == 0U) {
    rtDW.is_active_c3_Lane_Change_Assistance = 1U;
    rtDW.is_c3_Lane_Change_Assistance = IN_Condition_1;
    rtb_Highway_Display_Mode_1 = 232U;
    rtb_Highway_Display_Mode_3 = 41U;
  } else if (rtDW.is_c3_Lane_Change_Assistance == IN_Condition_1) {
    rtb_Highway_Display_Mode_1 = 232U;
    rtb_Highway_Display_Mode_3 = 41U;
    if ((Rte_IRead_Lane_Change_Assistance_Timing_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
         () == 1) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Enable_Display_DE_Enable_Display
         () == 1) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Input_Switch_DE_Input_Switch
         () == 1)) {
      rtDW.is_c3_Lane_Change_Assistance = IN_Condition_2;
      rtb_Highway_Display_Mode_1 = 213U;
      rtb_Highway_Display_Mode_3 = 9U;
    }
  } else {
    /* case IN_Condition_2: */
    rtb_Highway_Display_Mode_1 = 213U;
    rtb_Highway_Display_Mode_3 = 9U;
    if ((Rte_IRead_Lane_Change_Assistance_Timing_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
         () == 1) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Enable_Display_DE_Enable_Display
         () == 0) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Input_Switch_DE_Input_Switch
         () == 1)) {
      rtDW.is_c3_Lane_Change_Assistance = IN_Condition_1;
      rtb_Highway_Display_Mode_1 = 232U;
      rtb_Highway_Display_Mode_3 = 41U;
    }
  }

  /* End of Chart: '<S2>/Chart' */

  /* Chart: '<S3>/Chart' incorporates:
   *  Inport: '<Root>/Enable_Display'
   *  Inport: '<Root>/Input_Switch'
   *  Inport: '<Root>/Lane_Input_Signal'
   */
  if (rtDW.is_active_c1_Lane_Change_Assistance == 0U) {
    rtDW.is_active_c1_Lane_Change_Assistance = 1U;
    rtDW.is_c1_Lane_Change_Assistance = IN_Condition_1;
    rtb_Lane_Display_Mode_1 = 132U;
    rtb_Lane_Display_Mode_2 = 185U;
    rtb_Lane_Display_Mode_3 = 54U;
    rtb_Lane_Display_Mode_4 = 67U;
  } else if (rtDW.is_c1_Lane_Change_Assistance == IN_Condition_1) {
    rtb_Lane_Display_Mode_1 = 132U;
    rtb_Lane_Display_Mode_2 = 185U;
    rtb_Lane_Display_Mode_3 = 54U;
    rtb_Lane_Display_Mode_4 = 67U;
    if ((Rte_IRead_Lane_Change_Assistance_Timing_Rp_Lane_Input_Signal_DE_Lane_Input_Signal
         () == 6) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Enable_Display_DE_Enable_Display
         () == 1) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Input_Switch_DE_Input_Switch
         () == 1)) {
      rtDW.is_c1_Lane_Change_Assistance = IN_Condition_2;
      rtb_Lane_Display_Mode_1 = 127U;
      rtb_Lane_Display_Mode_2 = 248U;
      rtb_Lane_Display_Mode_3 = 186U;
      rtb_Lane_Display_Mode_4 = 84U;
    }
  } else {
    /* case IN_Condition_2: */
    rtb_Lane_Display_Mode_1 = 127U;
    rtb_Lane_Display_Mode_2 = 248U;
    rtb_Lane_Display_Mode_3 = 186U;
    rtb_Lane_Display_Mode_4 = 84U;
    if ((Rte_IRead_Lane_Change_Assistance_Timing_Rp_Lane_Input_Signal_DE_Lane_Input_Signal
         () == 6) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Enable_Display_DE_Enable_Display
         () == 0) &&
        (Rte_IRead_Lane_Change_Assistance_Timing_Rp_Input_Switch_DE_Input_Switch
         () == 1)) {
      rtDW.is_c1_Lane_Change_Assistance = IN_Condition_1;
      rtb_Lane_Display_Mode_1 = 132U;
      rtb_Lane_Display_Mode_2 = 185U;
      rtb_Lane_Display_Mode_3 = 54U;
      rtb_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'
   */
  tmp =
    Rte_IRead_Lane_Change_Assistance_Timing_Rp_Highway_Input_Signal_DE_Highway_Input_Signal
    ();
  if (tmp != 0) {
    /* Outport: '<Root>/Display_Mode_1' */
    Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_1_DE_Display_Mode_1
      (rtb_Highway_Display_Mode_1);
    rtb_Lane_Display_Mode_2 = 183U;
  } else {
    /* Outport: '<Root>/Display_Mode_1' */
    Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_1_DE_Display_Mode_1
      (rtb_Lane_Display_Mode_1);
  }

  /* End of Switch: '<S4>/Switch' */

  /* Outport: '<Root>/Display_Mode_2' */
  Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_2_DE_Display_Mode_2
    (rtb_Lane_Display_Mode_2);

  /* Switch: '<S4>/Switch2' incorporates:
   *  Switch: '<S4>/Switch3'
   */
  if (tmp != 0) {
    /* Outport: '<Root>/Display_Mode_3' */
    Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_3_DE_Display_Mode_3
      (rtb_Highway_Display_Mode_3);
    rtb_Lane_Display_Mode_4 = 94U;
  } else {
    /* Outport: '<Root>/Display_Mode_3' */
    Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_3_DE_Display_Mode_3
      (rtb_Lane_Display_Mode_3);
  }

  /* Outport: '<Root>/Display_Mode_4' */
  Rte_IWrite_Lane_Change_Assistance_Timing_Pp_Display_Mode_4_DE_Display_Modde_4
    (rtb_Lane_Display_Mode_4);
}

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

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

Conclusion:-

The code generation for model-based development is very easy compare to writing millions of codes.It will possible with right solver and code generation setting and maily due to Model Advisor check for standard MAb guidelines.

Hence,we can conclude that with proper settings and standard guidelines it will be very easy to build a code for the model.It will be cost efficient and a time saving method of design and development of model.It will be possible due to MATLAB.There is a lot of software for the same in the modelling environment but for better understanding and ease of use we can always prefer MATLAB.

Model Files:-

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

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.