Challenge

Traffic Jam Assistant Feature

  • Aim: -
  1. To Build a Simulink model for Traffic Jam Assistant as per the requirement document and create requirements tagging.
  2. To check a model under standard guidelines with help of a model adviser. (MABB guidelines)
  3. To build an embedded code for the model.
  • Objective: -
  1. Development of MATLAB Simulink model as per requirement.
  2. Tag the requirements to the Simulink model; tagging requirement 1 & requirement 2 to their corresponding subsystems is fine.
  3. MBD compliant changes, Data Dictionary creation & code generation are added advantages, and that is not the scope of this project.
  4. When choosing code generation, Storage class for Input signals: ImportedExtern; Storage class for Output signal: Export to File; Storage class for local signals: localizable; Storage class for calibration signals: Const.
  5. Choose sample time for all signals as 0.01s
  • Requirement Analysis Data: -
  • Requirement No 1: -
  1. Input Signal “Input_Voltage” is compared against voltage values “VOLTAGE_MINIMUM_RANGE” & “VOLTAGE_MAXIMUM_RANGE”.
  2. Incoming input signal “Input_Voltage” must be greater than – equal to “VOLTAGE_MINIMUM_RANGE” and less than – equal to “VOLTAGE_MAXIMUM_RANGE”.
  3. The output signal from here is “Optimum_Voltage” which will be one of the inputs to the subsystem “DisplayUnit”
  • Requirement No 2 (DisplayUnit Subsystem): -
  1. Input Signals are “Optimum_Voltage”, “Input_Switch”, “Enable_Display”. Signal “Enable_Display” must be saturated between the range 0 – 7. The output signal from the subsystem is “Output_Display”.
  2. Input Signal “Enable_Display” is compared against pre – defined set of values in a multiport switch. Total data ports in the multiport switch are 5.
  3. Multiport switch inputs 1 & 2 are 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”.
  4. 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”.
  5. 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.
  6. The output from the switch block is “Output_Display”.
  • Signals & Calibration Data List:

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

  • Simulink model: -
  • Requirement-1 subsystem: -

Here first we created a subsystem for our 1st requirement. For every requirement, we have to generate a subsystem.

Blocks used: - inport, outport, compare to constant, AND gate logic operator.

  1. Took one subsystem named as requirement-1.
  2. Took inport block gave named as Input Voltage.
  3. Now I compared input is compared against voltage values “VOLTAGE_ MINIMUM RANGE” & “VOLTAGE_MAXIMUM_RANGE”. with the help of logic operator block AND gate.
  4. Incoming input signal “Input_Voltage” must be greater than – equal to “VOLTAGE_ MINIMUM_RANGE” and less than – equal to “VOLTAGE_MAXIMUM_RANGE”
  5. Which means when the input voltage I between operating range then only signal will go forward otherwise zero value will go.
  6. The output signal from output port is “Optimum_Voltage” which will be one of the inputs to the subsystem “DisplayUnit”.
  • Requirement-2 subsystem: -

Here first we created a subsystem for our 2nd requirement.

Blocks used: - inport, outport, multiport switch, logic operator, relational operator, constant, saturation.

  1. Took one subsystem named as requirement 2 (Display Unit). inport for this subsystem is output signal from requirement 1 which is “Optimum_Voltage”.
  2. Now two more input signals added these are “Input_Switch”, “Enable_Display”
  3. Signal “Enable_Display” was saturated between the range 0 – 7 with help of saturation block.
  4. Input Signal “Enable_Display” is compared against pre – defined set of values in a multiport switch. Total data ports in the multiport switch are 5.
  5. Added multiport switch as 5 input port are connected to predefine value with help of constant block.
  6. Multiport switch inputs 1 & 2 are 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”.
  7. Now one switch block is added and 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”.
  8. Now add one NOT block input signal “Input_Switch” is connected to AND gate second port and first port is connected to input signal “Optimum_Voltage”.
  9. Now add the second AND gate. Output signal from first AND gate is input for second AND gate and another input are the comparison of calibration signals “INTERRUPT_1” & “INTERRUPT_2”.
  10. If the calibration signals “INTERRUPT_1” & “INTERRUPT_2” are equal then only the condition is satisfied.
  11. The output of the second AND gate is the second input of the switch block. Which is the control port of switch block.
  12. Lastly added one outport to the switch block is “Output_Display”.
  • Traffic Jam Assistant model: -

For the requirement_1 and requirement_2 inport, output is connected properly.

  • SLDD file: -

1. To create an SLDD file under modelling tan 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 create a new file save this file in the same directory.

3. Now open this file and add all given signals and constant with all parameters.

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

5. No need to change the 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.

  • Code compiled model (non-virtual Subsystem): - (treat as atomic subsystem)

1. Now the most important thing is we created whole Simulink model as atomic subsystem. For code generation we need to make sub systems as atomic.

2. After Right click on subsystem in block parameter option we have to check the treat as atomic unit option.

  • Signal resolve and propagation: -
  1. In signal properties you can resolve and propagate the signal.
  2. If the signal is the first type to appear in the system you have to resolve it otherwise propagate it.
  3. Signal resolve and propagation is most important for code generation.

  • Requirement tagging: -
  1. Requirement tagging is nothing but linking 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 parameter you can tag the requirement.
  4. First you have to select the requirement in the requirement document to tag with related subsystem. Also, the file has to be saved in the same directory.

  • Code generation settings: -

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

2. For code generation we can only use a fixed step solver.

3. As per requirement we change the solver setting to fix step discrete and fixed step time as 0.01 sec.

4. For embedded code generation in system target file will always ert.tlc which is embedded coder. Which generates embedded c code.

5. We can do coverage settings to check the execution of all blocks.

6. Here we can check the execution of eery block in model and also generate coverage report to analysis.

  • MAAB guideline check: - (Model advisor)

1. Under the modelling tab there is a model adviser 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 adviser 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 adviser check for selected checked guidelines.

6. If some errors occur you can check for that under the MAB tab.

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

8. You can check for individual errors and warnings also.

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

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

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

  • Code generation steps: -

1. It is a simple step if your model has no error according to MAAB guidelines then you are good to go for code generation.

2. In the tool bar under the app section there is an embedded coder option.

3. In that option the build code option is there. Once you click on that tab your code will generate.

4. You can view your c code in the view code tab on toolbar under code section.

  • code file: -
/*
 * File: Traffic_Jam_Assistant.c
 *
 * Code generated for Simulink model 'Traffic_Jam_Assistant'.
 *
 * Model version                  : 1.6
 * Simulink Coder version         : 9.5 (R2021a) 14-Nov-2020
 * C/C++ source code generated on : Tue Apr 12 12:15:26 2022
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Traffic_Jam_Assistant.h"
#include "Traffic_Jam_Assistant_private.h"

/* Exported data definition */

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

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

/* Real-time model */
static RT_MODEL_Traffic_Jam_Assistan_T Traffic_Jam_Assistant_M_;
RT_MODEL_Traffic_Jam_Assistan_T *const Traffic_Jam_Assistant_M =
  &Traffic_Jam_Assistant_M_;

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

  /* Outputs for Atomic SubSystem: '/Subsystem' */
  /* Logic: '/AND' 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: '/Constant4'
   *  Constant: '/Constant5'
   *  Inport: '/Input_Switch'
   *  Logic: '/AND'
   *  Logic: '/AND2'
   *  Logic: '/NOT'
   *  RelationalOperator: '/Relational Operator'
   */
  if ((INTERRUPT_1 == INTERRUPT_2) && (Optimum_Voltage && (!Input_Switch))) {
    /* 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 0:
      /* Switch: '/Switch' incorporates:
       *  Constant: '/Constant'
       */
      Output_Display = ON_MODE;
      break;

     case 1:
      /* Switch: '/Switch' incorporates:
       *  Constant: '/Constant'
       */
      Output_Display = ON_MODE;
      break;

     case 2:
      /* Switch: '/Switch' incorporates:
       *  Constant: '/Constant1'
       */
      Output_Display = OFF_MODE;
      break;

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

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

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

  /* End of Switch: '/Switch' */
  /* End of Outputs for SubSystem: '/Subsystem' */
}

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

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

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

All files for the codes that are generated for model will automatically be saved in same directory.

  • Conclusion: -

The code generation for model-based development is very easy compared to writing millions of codes. It will be possible with the right solver and code generation setting and mainly due to model adviser check for standard MAAB 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 a cost efficient and 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 modelling environment but for better understanding and ease of use we can always prefer MATLAB.

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.