Challenge

Project 1- Traffic Jam Assistant Feature

Aim:

To develop a model that represents Traffic Jam Assistant Feature.

Abstract:

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

Objective:

  • This model must be developed in MATLAB Simulink as per MBD guidelines.
  • Code Generation Profile must be in Embedded Coder.
  • Simulink Data Dictionary must be created for the model & must be linked to the model.
  • Model Advisor Report is mandatory & this will be followed by Code Generation.

Report:

Traffic Jam Assist:

Traffic Jam Assist combines a full speed range Adaptive Cruise Control system with Auto-Go capability, together with a full speed Lane Keeping Assist system. The driving path may also be defined by the trajectory of the preceding vehicle under certain circumstances such as low-speed, dense traffic situations and missing lane markers. The extended variant of the system will also be able to assist the driver in construction sites with reduced lateral space.

Basic Working Principle:

Traffic Jam Assistant is based on the sensors and the functionality of the Adaptive Cruise Control (ACC) with stop & go and Lane Keeping Support (LKS). When ACC ‘Stop & 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 or a traffic jam at speeds less than 60 kmph, the driver can activate the functionality by press of a button. The vehicle will now automatically follow the vehicle in front, takes over driving off, acceleration, braking and steering within 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.

Requirements:

Requirement1:

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

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.

SLDD creation:

Configuration Parameter:

Solver configuration can be editted in Modelling → Model settings → solver

Model Advisor check:

The Model Advisor checks your model or subsystem for modeling conditions and configuration settings that cause inaccurate or inefficient simulation of the system that the model represents.

Final Model:

Embedded Code Generation:

/*
 * File: ert_main.c
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include <stddef.h>
#include <stdio.h>              /* This ert_main.c example uses printf/fflush */
#include "Traffic_Jam_Assist.h"        /* Model's header file */
#include "rtwtypes.h"

/*
 * Associating rt_OneStep with a real-time clock or interrupt service routine
 * is what makes the generated code "real-time".  The function rt_OneStep is
 * always associated with the base rate of the model.  Subrates are managed
 * by the base rate from inside the generated code.  Enabling/disabling
 * interrupts and floating point context switches are target specific.  This
 * example code indicates where these should take place relative to executing
 * the generated code step function.  Overrun behavior should be tailored to
 * your application needs.  This example simply sets an error status in the
 * real-time model and returns from rt_OneStep.
 */
void rt_OneStep(void);
void rt_OneStep(void)
{
  static boolean_T OverrunFlag = false;

  /* Disable interrupts here */

  /* Check for overrun */
  if (OverrunFlag) {
    rtmSetErrorStatus(Traffic_Jam_Assist_M, "Overrun");
    return;
  }

  OverrunFlag = true;

  /* Save FPU context here (if necessary) */
  /* Re-enable timer or interrupt here */
  /* Set model inputs here */

  /* Step the model */
  Traffic_Jam_Assist_step();

  /* Get model outputs here */

  /* Indicate task complete */
  OverrunFlag = false;

  /* Disable interrupts here */
  /* Restore FPU context here (if necessary) */
  /* Enable interrupts here */
}

/*
 * The example "main" function illustrates what is required by your
 * application code to initialize, execute, and terminate the generated code.
 * Attaching rt_OneStep to a real-time clock is target specific.  This example
 * illustrates how you do this relative to initializing the model.
 */
int_T main(int_T argc, const char *argv[])
{
  /* Unused arguments */
  (void)(argc);
  (void)(argv);

  /* Initialize model */
  Traffic_Jam_Assist_initialize();

  /* Attach rt_OneStep to a timer or interrupt service routine with
   * period 0.01 seconds (the model's base sample time) here.  The
   * call syntax for rt_OneStep is
   *
   *  rt_OneStep();
   */
  printf("Warning: The simulation will run forever. "
         "Generated ERT main won't simulate model step behavior. "
         "To change this behavior select the 'MAT-file logging' option.\n");
  fflush((NULL));
  while (rtmGetErrorStatus(Traffic_Jam_Assist_M) == (NULL)) {
    /*  Perform other application tasks here */
  }

  /* Disable rt_OneStep() here */

  /* Terminate model */
  Traffic_Jam_Assist_terminate();
  return 0;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: rtwtypes.h
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTWTYPES_H
#define RTWTYPES_H

/* Logical type definitions */
#if (!defined(__cplusplus))
#ifndef false
#define false                          (0U)
#endif

#ifndef true
#define true                           (1U)
#endif
#endif

/*=======================================================================*
 * Target hardware information
 *   Device type: Intel->x86-64 (Windows64)
 *   Number of bits:     char:   8    short:   16    int:  32
 *                       long:  32
 *                       native word size:  64
 *   Byte ordering: LittleEndian
 *   Signed integer division rounds to: Zero
 *   Shift right on a signed integer as arithmetic shift: on
 *=======================================================================*/

/*=======================================================================*
 * Fixed width word size data types:                                     *
 *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
 *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
 *   real32_T, real64_T           - 32 and 64 bit floating point numbers *
 *=======================================================================*/
typedef signed char int8_T;
typedef unsigned char uint8_T;
typedef short int16_T;
typedef unsigned short uint16_T;
typedef int int32_T;
typedef unsigned int uint32_T;
typedef float real32_T;
typedef double real64_T;

/*===========================================================================*
 * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T,       *
 *                           real_T, time_T, ulong_T.                        *
 *===========================================================================*/
typedef double real_T;
typedef double time_T;
typedef unsigned char boolean_T;
typedef int int_T;
typedef unsigned int uint_T;
typedef unsigned long ulong_T;
typedef char char_T;
typedef unsigned char uchar_T;
typedef char_T byte_T;

/*===========================================================================*
 * Complex number type definitions                                           *
 *===========================================================================*/
#define CREAL_T

typedef struct {
  real32_T re;
  real32_T im;
} creal32_T;

typedef struct {
  real64_T re;
  real64_T im;
} creal64_T;

typedef struct {
  real_T re;
  real_T im;
} creal_T;

#define CINT8_T

typedef struct {
  int8_T re;
  int8_T im;
} cint8_T;

#define CUINT8_T

typedef struct {
  uint8_T re;
  uint8_T im;
} cuint8_T;

#define CINT16_T

typedef struct {
  int16_T re;
  int16_T im;
} cint16_T;

#define CUINT16_T

typedef struct {
  uint16_T re;
  uint16_T im;
} cuint16_T;

#define CINT32_T

typedef struct {
  int32_T re;
  int32_T im;
} cint32_T;

#define CUINT32_T

typedef struct {
  uint32_T re;
  uint32_T im;
} cuint32_T;

/*=======================================================================*
 * Min and Max:                                                          *
 *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
 *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
 *=======================================================================*/
#define MAX_int8_T                     ((int8_T)(127))
#define MIN_int8_T                     ((int8_T)(-128))
#define MAX_uint8_T                    ((uint8_T)(255U))
#define MAX_int16_T                    ((int16_T)(32767))
#define MIN_int16_T                    ((int16_T)(-32768))
#define MAX_uint16_T                   ((uint16_T)(65535U))
#define MAX_int32_T                    ((int32_T)(2147483647))
#define MIN_int32_T                    ((int32_T)(-2147483647-1))
#define MAX_uint32_T                   ((uint32_T)(0xFFFFFFFFU))

/* Block D-Work pointer type */
typedef void * pointer_T;

#endif                                 /* RTWTYPES_H */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: TJA_def.c
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "rtwtypes.h"
#include "Traffic_Jam_Assist_types.h"

/* Exported data definition */

/* Definition for custom storage class: ExportToFile */
uint8_T Output_Display;                /* '<S2>/Switch' */

/* Const memory section */
/* Definition for custom storage class: Const */
const boolean_T INTERRUPT_1 = 1;       /* Referenced by: '<S2>/Constant4' */
const boolean_T INTERRUPT_2 = 1;       /* Referenced by: '<S2>/Constant5' */
const uint8_T NO_DISPLAY = 0U;         /* Referenced by: '<S2>/Constant3' */
const uint8_T OFF_MODE = 2U;           /* Referenced by: '<S2>/Constant1' */
const uint8_T ON_MODE = 1U;            /* Referenced by: '<S2>/Constant' */
const uint8_T STANDBY_MODE = 3U;       /* Referenced by: '<S2>/Constant2' */
const uint8_T VOLTAGE_MAXIMUM_RANGE = 50U;/* Referenced by: '<S3>/Constant1' */
const uint8_T VOLTAGE_MINIMUM_RANGE = 30U;/* Referenced by: '<S3>/Constant' */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: TJA_head.h
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_TJA_head_h_
#define RTW_HEADER_TJA_head_h_
#include "rtwtypes.h"
#include "Traffic_Jam_Assist_types.h"

/* Exported data declaration */

/* Declaration for custom storage class: ExportToFile */
extern uint8_T Output_Display;         /* '<S2>/Switch' */

/* Const memory section */
/* Declaration for custom storage class: Const */
extern const boolean_T INTERRUPT_1;    /* Referenced by: '<S2>/Constant4' */
extern const boolean_T INTERRUPT_2;    /* Referenced by: '<S2>/Constant5' */
extern const uint8_T NO_DISPLAY;       /* Referenced by: '<S2>/Constant3' */
extern const uint8_T OFF_MODE;         /* Referenced by: '<S2>/Constant1' */
extern const uint8_T ON_MODE;          /* Referenced by: '<S2>/Constant' */
extern const uint8_T STANDBY_MODE;     /* Referenced by: '<S2>/Constant2' */
extern const uint8_T VOLTAGE_MAXIMUM_RANGE;/* Referenced by: '<S3>/Constant1' */
extern const uint8_T VOLTAGE_MINIMUM_RANGE;/* Referenced by: '<S3>/Constant' */

#endif                                 /* RTW_HEADER_TJA_head_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: Traffic_Jam_Assist.c
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Traffic_Jam_Assist.h"
#include "Traffic_Jam_Assist_private.h"

/* Real-time model */
static RT_MODEL_Traffic_Jam_Assist_T Traffic_Jam_Assist_M_;
RT_MODEL_Traffic_Jam_Assist_T *const Traffic_Jam_Assist_M =
  &Traffic_Jam_Assist_M_;

/* Model step function */
void Traffic_Jam_Assist_step(void)
{
  /* local block i/o variables */
  boolean_T Optimum_Voltage;
  uint8_T tmp;

  /* Logic: '<S3>/AND' incorporates:
   *  Constant: '<S3>/Constant'
   *  Constant: '<S3>/Constant1'
   *  Inport: '<Root>/Input_Voltage'
   *  RelationalOperator: '<S3>/Relational Operator'
   *  RelationalOperator: '<S3>/Relational Operator1'
   */
  Optimum_Voltage = ((Input_Voltage >= VOLTAGE_MINIMUM_RANGE) && (Input_Voltage <=
    VOLTAGE_MAXIMUM_RANGE));

  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S2>/Constant4'
   *  Constant: '<S2>/Constant5'
   *  Inport: '<Root>/Input_switch'
   *  Logic: '<S2>/NOT'
   *  Logic: '<S2>/NOT1'
   *  RelationalOperator: '<S2>/Relational Operator'
   */
  if ((!Input_Switch) && Optimum_Voltage && (INTERRUPT_1 == INTERRUPT_2)) {
    /* Saturate: '<S2>/Saturation' incorporates:
     *  Inport: '<Root>/Enable_Display'
     */
    if (Enable_Display < 7) {
      tmp = Enable_Display;
    } else {
      tmp = 7U;
    }

    /* End of Saturate: '<S2>/Saturation' */

    /* MultiPortSwitch: '<S2>/Multiport Switch' */
    switch (tmp) {
     case 1:
      /* Switch: '<S2>/Switch' incorporates:
       *  Constant: '<S2>/Constant'
       */
      Output_Display = ON_MODE;
      break;

     case 2:
      /* Switch: '<S2>/Switch' incorporates:
       *  Constant: '<S2>/Constant'
       */
      Output_Display = ON_MODE;
      break;

     case 3:
      /* Switch: '<S2>/Switch' incorporates:
       *  Constant: '<S2>/Constant1'
       */
      Output_Display = OFF_MODE;
      break;

     case 4:
      /* Switch: '<S2>/Switch' incorporates:
       *  Constant: '<S2>/Constant1'
       */
      Output_Display = OFF_MODE;
      break;

     default:
      /* Switch: '<S2>/Switch' incorporates:
       *  Constant: '<S2>/Constant2'
       */
      Output_Display = STANDBY_MODE;
      break;
    }

    /* End of MultiPortSwitch: '<S2>/Multiport Switch' */
  } else {
    /* Switch: '<S2>/Switch' incorporates:
     *  Constant: '<S2>/Constant3'
     */
    Output_Display = NO_DISPLAY;
  }

  /* End of Switch: '<S2>/Switch' */
}

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

/* Model terminate function */
void Traffic_Jam_Assist_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: Traffic_Jam_Assist.h
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_Traffic_Jam_Assist_h_
#define RTW_HEADER_Traffic_Jam_Assist_h_
#ifndef Traffic_Jam_Assist_COMMON_INCLUDES_
#define Traffic_Jam_Assist_COMMON_INCLUDES_
#include "rtwtypes.h"
#endif                                 /* Traffic_Jam_Assist_COMMON_INCLUDES_ */

#include "Traffic_Jam_Assist_types.h"

/* Includes for objects with custom storage classes. */
#include "TJA_head.h"

/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm)         ((rtm)->errorStatus)
#endif

#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val)    ((rtm)->errorStatus = (val))
#endif

/* Real-time Model Data Structure */
struct tag_RTM_Traffic_Jam_Assist_T {
  const char_T * volatile errorStatus;
};

/* Model entry point functions */
extern void Traffic_Jam_Assist_initialize(void);
extern void Traffic_Jam_Assist_step(void);
extern void Traffic_Jam_Assist_terminate(void);

/* Real-time Model object */
extern RT_MODEL_Traffic_Jam_Assist_T *const Traffic_Jam_Assist_M;

/*-
 * The generated code includes comments that allow you to trace directly
 * back to the appropriate location in the model.  The basic format
 * is <system>/block_name, where system is the system number (uniquely
 * assigned by Simulink) and block_name is the name of the block.
 *
 * Use the MATLAB hilite_system command to trace the generated code back
 * to the model.  For example,
 *
 * hilite_system('<S3>')    - opens system 3
 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
 *
 * Here is the system hierarchy for this model
 *
 * '<Root>' : 'Traffic_Jam_Assist'
 * '<S1>'   : 'Traffic_Jam_Assist/Traffuc_Jam_Assist'
 * '<S2>'   : 'Traffic_Jam_Assist/Traffuc_Jam_Assist/Display Unit'
 * '<S3>'   : 'Traffic_Jam_Assist/Traffuc_Jam_Assist/Requirement1'
 */
#endif                                 /* RTW_HEADER_Traffic_Jam_Assist_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: Traffic_Jam_Assist_private.h
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_Traffic_Jam_Assist_private_h_
#define RTW_HEADER_Traffic_Jam_Assist_private_h_
#include "rtwtypes.h"

/* Imported (extern) block signals */
extern uint8_T Input_Voltage;          /* '<Root>/Input_Voltage' */
extern boolean_T Input_Switch;         /* '<Root>/Input_switch' */
extern uint8_T Enable_Display;         /* '<Root>/Enable_Display' */

#endif                            /* RTW_HEADER_Traffic_Jam_Assist_private_h_ */

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
/*
 * File: Traffic_Jam_Assist_types.h
 *
 * Code generated for Simulink model 'Traffic_Jam_Assist'.
 *
 * Model version                  : 1.8
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Thu Apr  7 12:57:23 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_Traffic_Jam_Assist_types_h_
#define RTW_HEADER_Traffic_Jam_Assist_types_h_

/* Model Code Variants */

/* Forward declaration for rtModel */
typedef struct tag_RTM_Traffic_Jam_Assist_T RT_MODEL_Traffic_Jam_Assist_T;

#endif                              /* RTW_HEADER_Traffic_Jam_Assist_types_h_ */

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

Result:

Thus, the required model was developed according to modeling standards and guidelines.

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.