Challenge

Project 1- Traffic Jam Assistant Feature

Project 1(Traffic Jam Assistance feature)

Aim:

To develop one specific requirement of Traffic Jam Assistant algorithm which would predominantly feature in the IPC algorithm.Please note that the whole Traffic Jam Assistant is a very huge algorithm & only one small part of the logic is implemented here. Idea is to familiarize with concepts of Model Based Development in MATLAB Environment. The Project must be done keeping in mind the following processes & steps.

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

SLDD signals and calibration values:

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

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 2:

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

Top level model:

Here created the two requirements and interconnected by a localized signal optimum_voltage as output from requirement1 given as an input to requirement2 along with input_switch and Enable_Display.

The output from the requirement 2 is Output_Display as shown below,

Requiremenr1 subsystem:

As per the requirement1 mentioned above we have created the model as shown below,

Requirement2 subsystem:

As per the requirement2 mentioned above we have created the model as shown below,

Resolving and propagating signals:

Here resolve the input and output signals and also propagated inside the subsystems as shown below,

Code generation configuration:

Here code generation setting set as ert.tlc for embedded code generation as shown below,

Also solver configuration set as Fixed step discrete and sample time as auto.

Results:

Model advisor report:

Here checked the MAAB guidelines using model advisor and the results are shown as,

The report attached with this submission.

Code generation:

After compiling the model sucessfully we generated the source files .c and .h as shown below,

C source file:

*
 * File: AUTOSAR_Prj1.c
 *
 * Code generated for Simulink model 'AUTOSAR_Prj1'.
 *
 * Model version                  : 1.41
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Sat Oct 23 18:56:22 2021
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "AUTOSAR_Prj1.h"
#include "AUTOSAR_Prj1_private.h"

/* Exported data definition */

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

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

/* Real-time model */
static RT_MODEL_AUTOSAR_Prj1_T AUTOSAR_Prj1_M_;
RT_MODEL_AUTOSAR_Prj1_T *const AUTOSAR_Prj1_M = &AUTOSAR_Prj1_M_;

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

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

  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S2>/Constant4'
   *  Constant: '<S2>/Constant5'
   *  Inport: '<Root>/Input_Switch'
   *  Logic: '<S2>/AND'
   *  Logic: '<S2>/AND1'
   *  Logic: '<S2>/Logical Operator'
   *  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 AUTOSAR_Prj1_initialize(void)
{
  /* (no initialization code required) */
}

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

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

C header file:

/*
 * File: AUTOSAR_Prj1.h
 *
 * Code generated for Simulink model 'AUTOSAR_Prj1'.
 *
 * Model version                  : 1.41
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Sat Oct 23 18:56:22 2021
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#ifndef RTW_HEADER_AUTOSAR_Prj1_h_
#define RTW_HEADER_AUTOSAR_Prj1_h_
#ifndef AUTOSAR_Prj1_COMMON_INCLUDES_
#define AUTOSAR_Prj1_COMMON_INCLUDES_
#include "rtwtypes.h"
#endif                                 /* AUTOSAR_Prj1_COMMON_INCLUDES_ */

#include "AUTOSAR_Prj1_types.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_AUTOSAR_Prj1_T {
  const char_T * volatile errorStatus;
};

/* Model entry point functions */
extern void AUTOSAR_Prj1_initialize(void);
extern void AUTOSAR_Prj1_step(void);
extern void AUTOSAR_Prj1_terminate(void);

/* Exported data declaration */

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

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

/* Real-time Model object */
extern RT_MODEL_AUTOSAR_Prj1_T *const AUTOSAR_Prj1_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>' : 'AUTOSAR_Prj1'
 * '<S1>'   : 'AUTOSAR_Prj1/Requirement1'
 * '<S2>'   : 'AUTOSAR_Prj1/Requirement2'
 */
#endif                                 /* RTW_HEADER_AUTOSAR_Prj1_h_ */

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

Conclusion:

Thus based on the requirements we had created the model,SLDD file attached with the model,model advisor check taken up and finally embedded code had been generated sucessfully.

Note: Model file,SLDD file,Code generation files and model advisor report were attached with this submission.

Thank you

Submitted by,

Praveen Kumar L V

Date:23/10/2021.

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.