Challenge

Project 1- Traffic Jam Assistant Feature

Aim:

To create a Simulink Data Dictionary, develop an algorithm for one of the features of the Traffic jam Assistance and generate a C code for it using Simulink.

Objective:

  • Model Development as per the MBD guidelines
  • Creation of Simulink Data Dictionary
  • Code generation using Embedded Coder
  • Generating Model Advisor Report

Overview:

In the Advanced Driver Assistance System, the Traffic Jam Assistance system is one of the most common features of it. Traffic Jam Assistant helps the driver arrive more relaxed at their destination, even in dense traffic. As a partially automated comfort function, the system takes over the longitudinal and lateral guidance of the vehicle. This means that the car can drive off, accelerate and brake automatically, as well as steer the vehicle within certain constraints. The driver has to permanently supervise the system and be ready to take over the complete control of the vehicle at any time.

Traffic jam assistance system helps to avoid rear-end collisions in dense traffic conditions and traffic jams. In traffic jams, the vehicle takes over driving off, acceleration, braking, and steering within the same lane.

Basic Working Principle:

Traffic jam Assistant is based on the sensors and the functionality of the Adaptive Cruise Control (ACC) with stop and go and Lane Keeping Support (LKS). When ACC ‘Stop and Go’ is turned ON, the Traffic Jam Assistant continuously analyses the speed of the surrounding vehicles and compares it with the own driving speed. If the system detects dense traffic at less than 60 kmph, the driver can activate the functionality by the press of a button. The vehicle will now automatically follow the vehicle in front, takes over driving off, acceleration, braking, and steering within the same lane.

Information regarding the Traffic Jam Assistant will be available to be displayed to the driver in the Instrument Panel Cluster (IPC). The algorithm which the students need to implement here in this project is predominantly based on IPC units.

Signals given to us are,

Input Signals:

Name of the Signal

Data Type

Range

Input_Voltage

uint8

0 - 255

Input_Switch

boolean

0 – 1

Enable_Display

uint8

0 - 255

Output Signal:

Name of the Signal

Data Type

Range

Output_Display

uint8

0 - 255

Calibration Signals:

Name of the Signal

Data Type

Range

Initial Value

VOLTAGE_MINIMUM_RANGE

uint8

0 – 255

30

VOLTAGE_MAXIMUM_RANGE

uint8

0 – 255

50

OFF_MODE

uint8

0 – 255

2

ON_MODE

uint8

0 – 255

1

STANDBY_MODE

uint8

0 – 255

3

INTERRUPT_1

boolean

0 – 1

1

INTERRUPT_2

boolean

0 - 1

1

NO_DISPLAY

uint8

0 – 255

0

Local Signal:

Name of the Signal

Data Type

Range

Optimum_Voltage

boolean

0 - 1

Procedure:

The figure below shows the Simulink data dictionary (sldd) file according to the given inputs.

Requirement_1:

  • Input Signal “Input_Voltage” is compared against voltage values “VOLTAGE_MINIMUM_RANGE” & “VOLTAGE_MAXIMUM_RANGE”.
  • Incoming input signal “Input_Voltage” must be greater than – equal to “VOLTAGE_MINIMUM_RANGE” and less than – equal to “VOLTAGE_MAXIMUM_RANGE”.
  • Output signal from here is “Optimum_Voltage” which will be one of the inputs to the subsystem “DisplayUnit”.

Requirement No 2 (DisplayUnit Subsystem):

  • Input Signals are “Optimum_Voltage”, “Input_Switch”,“Enable_Display”. Signal “Enable_Display” must be saturated between the range 0 – 7. Output signal from the subsystem is “Output_Display”.
  • Input Signal “Enable_Display” is compared against pre – defined set of values in a multiport switch. Total data ports in the multiport switch is 5.
  • Multiport switch inputs 1 & 2 is connected to calibration signal “ON_MODE”, Multiport switch inputs 3 & 4 is connected to calibration signal “OFF_MODE” while Multiport switch input 5 is connected to calibration signal “STANDBY_MODE”.
  • The output from Multiport switch is connected to the first input port of the Switch block. The third input port of the Switch block is connected to the calibration signal “NO_DISPLAY”.
  • Meanwhile NOT value of input signal “Input_Switch” is compared in an AND gate against input signal “Optimum_Voltage” and the output from comparing if calibration signals “INTERRUPT_1” & “INTERRUPT_2” are equal. The output of the AND gate is the second input of the switch block.
  • The output from the switch block is “Output_Display”.

The figure below shows the whole model created for the Traffic Jam Assistance feature with all the input and output ports using Simulink

Now, lets carry out the Model Advisor Check,

We can see that there are zero errors thus we can proceed to our next step that is code generation

Code generation,

Traffic_Jam_Assistance.c
/*

 * Trial License - for use to evaluate programs for possible purchase as

 * an end-user only.

 *

 * File: Traffic_Jam_Assistance.c

 *

 * Code generated for Simulink model 'Traffic_Jam_Assistance'.

 *

 * Model version                  : 1.1

 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020

 * C/C++ source code generated on : Wed Oct 13 16:32:00 2021

 *

 * Target selection: ert.tlc

 * Embedded hardware selection: Intel->x86-64 (Windows64)

 * Code generation objectives: Unspecified

 * Validation result: Not run

 */



#include "Traffic_Jam_Assistance.h"

#include "Traffic_Jam_Assistance_private.h"



/* Exported block signals */

uint8_T Output_Display;                /* '/Switch' */



/* Exported data definition */



/* ConstVolatile memory section */

/* Definition for custom storage class: ConstVolatile */

const volatile boolean_T Interrupt_1 = 1;/* Referenced by: '/Constant' */

const volatile boolean_T Interrupt_2 = 1;/* Referenced by: '/Constant1' */

const volatile uint8_T No_Display = 0U;/* Referenced by: '/Constant2' */

const volatile uint8_T Off_Mode = 2U;  /* Referenced by: '/Off_Mode' */

const volatile uint8_T On_Mode = 1U;   /* Referenced by: '/On_Mode' */

const volatile uint8_T Standby_Mode = 3U;/* Referenced by: '/Standby_Mode' */

const volatile uint8_T Voltage_Maximum_Range = 50U;/* Referenced by: '/Constant' */

const volatile uint8_T Voltage_Minimum_Range = 30U;/* Referenced by: '/Constant' */



/* Real-time model */

static RT_MODEL_Traffic_Jam_Assistan_T Traffic_Jam_Assistance_M_;

RT_MODEL_Traffic_Jam_Assistan_T *const Traffic_Jam_Assistance_M =

  &Traffic_Jam_Assistance_M_;



/* Model step function */

void Traffic_Jam_Assistance_step(void)

{

  /* local block i/o variables */

  boolean_T Optimum_Voltage;

  uint8_T tmp;



  /* Logic: '/Logical Operator' incorporates:

   *  Constant: '/Constant'

   *  Constant: '/Constant'

   *  Inport: '/Input_Voltage'

   *  RelationalOperator: '/Compare'

   *  RelationalOperator: '/Compare'

   */

  Optimum_Voltage = ((Input_Voltage >= Voltage_Minimum_Range) || (Input_Voltage <=

    Voltage_Maximum_Range));



  /* Switch: '/Switch' incorporates:

   *  Constant: '/Constant'

   *  Constant: '/Constant1'

   *  Inport: '/Input_Switch'

   *  Logic: '/Logical Operator'

   *  Logic: '/Logical Operator1'

   *  RelationalOperator: '/Relational Operator'

   */

  if (Optimum_Voltage && (!Input_Switch) && (Interrupt_1 == Interrupt_2)) {

    /* Saturate: '/Saturation' incorporates:

     *  Inport: '/Enable_Display'

     */

    if (Enable_Display < 7) {

      tmp = Enable_Display;

    } else {

      tmp = 7U;

    }



    /* End of Saturate: '/Saturation' */



    /* MultiPortSwitch: '/Multiport Switch' */

    switch (tmp) {

     case 1:

      /* Switch: '/Switch' incorporates:

       *  Constant: '/On_Mode'

       */

      Output_Display = On_Mode;

      break;



     case 2:

      /* Switch: '/Switch' incorporates:

       *  Constant: '/On_Mode'

       */

      Output_Display = On_Mode;

      break;



     case 3:

      /* Switch: '/Switch' incorporates:

       *  Constant: '/Off_Mode'

       */

      Output_Display = Off_Mode;

      break;



     case 4:

      /* Switch: '/Switch' incorporates:

       *  Constant: '/Off_Mode'

       */

      Output_Display = Off_Mode;

      break;



     default:

      /* Switch: '/Switch' incorporates:

       *  Constant: '/Standby_Mode'

       */

      Output_Display = Standby_Mode;

      break;

    }



    /* End of MultiPortSwitch: '/Multiport Switch' */

  } else {

    /* Switch: '/Switch' incorporates:

     *  Constant: '/Constant2'

     */

    Output_Display = No_Display;

  }



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

}



/* Model initialize function */

void Traffic_Jam_Assistance_initialize(void)

{

  /* (no initialization code required) */

}



/* Model terminate function */

void Traffic_Jam_Assistance_terminate(void)

{

  /* (no terminate code required) */

}



/*

 * File trailer for generated code.

 *

 * [EOF]

 */

Software in Loop verification for the generated code using Simulation Data inspector,

From the above graph we can see that the output is 3 and the tolerance is 0, thus the generated code has successfully passed the Software-in-Loop test.

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.