Project 1- Traffic Jam Assistant Feature
Traffic Jam Assistant Feature
Introduction to the Feature:
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.
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.
Problem Statement:
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.
Requirement No 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”

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

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 |
step: create data dictionary seperately
step : Link data dictionary to model



step: changing model setting
1.solver setting
2. code generation




step:
check model advisor


model advisor report is attached herewith.

model after correcting errors :



Code Generation process :

Code:
File: ert_main.c
1 /*
2 * File: ert_main.c
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include <stddef.h>
17 #include <stdio.h> /* This ert_main.c example uses printf/fflush */
18 #include "traffic_jam.h" /* Model's header file */
19 #include "rtwtypes.h"
20
21 /*
22 * Associating rt_OneStep with a real-time clock or interrupt service routine
23 * is what makes the generated code "real-time". The function rt_OneStep is
24 * always associated with the base rate of the model. Subrates are managed
25 * by the base rate from inside the generated code. Enabling/disabling
26 * interrupts and floating point context switches are target specific. This
27 * example code indicates where these should take place relative to executing
28 * the generated code step function. Overrun behavior should be tailored to
29 * your application needs. This example simply sets an error status in the
30 * real-time model and returns from rt_OneStep.
31 */
32 void rt_OneStep(void);
33 void rt_OneStep(void)
34 {
35 static boolean_T OverrunFlag = false;
36
37 /* Disable interrupts here */
38
39 /* Check for overrun */
40 if (OverrunFlag) {
41 rtmSetErrorStatus(traffic_jam_M, "Overrun");
42 return;
43 }
44
45 OverrunFlag = true;
46
47 /* Save FPU context here (if necessary) */
48 /* Re-enable timer or interrupt here */
49 /* Set model inputs here */
50
51 /* Step the model */
52 traffic_jam_step();
53
54 /* Get model outputs here */
55
56 /* Indicate task complete */
57 OverrunFlag = false;
58
59 /* Disable interrupts here */
60 /* Restore FPU context here (if necessary) */
61 /* Enable interrupts here */
62 }
63
64 /*
65 * The example "main" function illustrates what is required by your
66 * application code to initialize, execute, and terminate the generated code.
67 * Attaching rt_OneStep to a real-time clock is target specific. This example
68 * illustrates how you do this relative to initializing the model.
69 */
70 int_T main(int_T argc, const char *argv[])
71 {
72 /* Unused arguments */
73 (void)(argc);
74 (void)(argv);
75
76 /* Initialize model */
77 traffic_jam_initialize();
78
79 /* Attach rt_OneStep to a timer or interrupt service routine with
80 * period 0.01 seconds (the model's base sample time) here. The
81 * call syntax for rt_OneStep is
82 *
83 * rt_OneStep();
84 */
85 printf("Warning: The simulation will run forever. "
86 "Generated ERT main won't simulate model step behavior. "
87 "To change this behavior select the 'MAT-file logging' option.\n");
88 fflush((NULL));
89 while (rtmGetErrorStatus(traffic_jam_M) == (NULL)) {
90 /* Perform other application tasks here */
91 }
92
93 /* Disable rt_OneStep() here */
94
95 /* Terminate model */
96 traffic_jam_terminate();
97 return 0;
98 }
99
100 /*
101 * File trailer for generated code.
102 *
103 * [EOF]
104 */
105
File: traffic_jam.c
1 /*
2 * File: traffic_jam.c
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include "traffic_jam.h"
17 #include "traffic_jam_private.h"
18
19 /* Exported block signals */
20 uint8_T Output_Display; /* '<S1>/Switch' */
21
22 /* Exported data definition */
23
24 /* ConstVolatile memory section */
25 /* Definition for custom storage class: ConstVolatile */
26 const volatile boolean_T INTERRUPT_1 = 1;/* Referenced by: '<S1>/Constant4' */
27 const volatile boolean_T INTERRUPT_2 = 1;/* Referenced by: '<S1>/Constant5' */
28 const volatile uint8_T NO_DISPLAY = 0U;/* Referenced by: '<S1>/Constant3' */
29 const volatile uint8_T OFF_MODE = 2U; /* Referenced by: '<S1>/Constant1' */
30 const volatile uint8_T ON_MODE = 1U; /* Referenced by: '<S1>/Constant' */
31 const volatile uint8_T STANDBY_MODE = 3U;/* Referenced by: '<S1>/Constant2' */
32 const volatile uint8_T VOLTAGE_MAXIMUM_RANGE = 50U;/* Referenced by: '<S2>/Constant1' */
33 const volatile uint8_T VOLTAGE_MINIMUM_RANGE = 30U;/* Referenced by: '<S2>/Constant' */
34
35 /* Real-time model */
36 RT_MODEL_traffic_jam_T traffic_jam_M_;
37 RT_MODEL_traffic_jam_T *const traffic_jam_M = &traffic_jam_M_;
38
39 /* Model step function */
40 void traffic_jam_step(void)
41 {
42 /* local block i/o variables */
43 boolean_T Optimum_Voltage;
44
45 /* Logic: '<S2>/Logical Operator' incorporates:
46 * Constant: '<S2>/Constant'
47 * Constant: '<S2>/Constant1'
48 * Inport: '<Root>/Input_Voltage'
49 * RelationalOperator: '<S2>/Relational Operator'
50 * RelationalOperator: '<S2>/Relational Operator1'
51 */
52 Optimum_Voltage = ((Input_Voltage >= VOLTAGE_MINIMUM_RANGE) && (Input_Voltage <=
53 VOLTAGE_MAXIMUM_RANGE));
54
55 /* Switch: '<S1>/Switch' incorporates:
56 * Constant: '<S1>/Constant3'
57 * Constant: '<S1>/Constant4'
58 * Constant: '<S1>/Constant5'
59 * Inport: '<Root>/Input_Switch'
60 * Logic: '<S1>/Logical Operator'
61 * Logic: '<S1>/Logical Operator1'
62 * RelationalOperator: '<S1>/Relational Operator'
63 */
64 if ((!Input_Switch) && Optimum_Voltage && (INTERRUPT_1 == INTERRUPT_2)) {
65 /* MultiPortSwitch: '<S1>/Multiport Switch' incorporates:
66 * Constant: '<S1>/Constant'
67 */
68 Output_Display = ON_MODE;
69 } else {
70 Output_Display = NO_DISPLAY;
71 }
72
73 /* End of Switch: '<S1>/Switch' */
74 }
75
76 /* Model initialize function */
77 void traffic_jam_initialize(void)
78 {
79 /* (no initialization code required) */
80 }
81
82 /* Model terminate function */
83 void traffic_jam_terminate(void)
84 {
85 /* (no terminate code required) */
86 }
87
88 /*
89 * File trailer for generated code.
90 *
91 * [EOF]
92 */
93
File: traffic_jam.h
1 /*
2 * File: traffic_jam.h
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_traffic_jam_h_
17 #define RTW_HEADER_traffic_jam_h_
18 #ifndef traffic_jam_COMMON_INCLUDES_
19 # define traffic_jam_COMMON_INCLUDES_
20 #include "rtwtypes.h"
21 #endif /* traffic_jam_COMMON_INCLUDES_ */
22
23 #include "traffic_jam_types.h"
24
25 /* Macros for accessing real-time model data structure */
26 #ifndef rtmGetErrorStatus
27 # define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
28 #endif
29
30 #ifndef rtmSetErrorStatus
31 # define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
32 #endif
33
34 /* Real-time Model Data Structure */
35 struct tag_RTM_traffic_jam_T {
36 const char_T * volatile errorStatus;
37 };
38
39 /*
40 * Exported Global Signals
41 *
42 * Note: Exported global signals are block signals with an exported global
43 * storage class designation. Code generation will declare the memory for
44 * these signals and export their symbols.
45 *
46 */
47 extern uint8_T Output_Display; /* '<S1>/Switch' */
48
49 /* Model entry point functions */
50 extern void traffic_jam_initialize(void);
51 extern void traffic_jam_step(void);
52 extern void traffic_jam_terminate(void);
53
54 /* Exported data declaration */
55
56 /* ConstVolatile memory section */
57 /* Declaration for custom storage class: ConstVolatile */
58 extern const volatile boolean_T INTERRUPT_1;/* Referenced by: '<S1>/Constant4' */
59 extern const volatile boolean_T INTERRUPT_2;/* Referenced by: '<S1>/Constant5' */
60 extern const volatile uint8_T NO_DISPLAY;/* Referenced by: '<S1>/Constant3' */
61 extern const volatile uint8_T OFF_MODE;/* Referenced by: '<S1>/Constant1' */
62 extern const volatile uint8_T ON_MODE; /* Referenced by: '<S1>/Constant' */
63 extern const volatile uint8_T STANDBY_MODE;/* Referenced by: '<S1>/Constant2' */
64 extern const volatile uint8_T VOLTAGE_MAXIMUM_RANGE;/* Referenced by: '<S2>/Constant1' */
65 extern const volatile uint8_T VOLTAGE_MINIMUM_RANGE;/* Referenced by: '<S2>/Constant' */
66
67 /* Real-time Model object */
68 extern RT_MODEL_traffic_jam_T *const traffic_jam_M;
69
70 /*-
71 * The generated code includes comments that allow you to trace directly
72 * back to the appropriate location in the model. The basic format
73 * is <system>/block_name, where system is the system number (uniquely
74 * assigned by Simulink) and block_name is the name of the block.
75 *
76 * Use the MATLAB hilite_system command to trace the generated code back
77 * to the model. For example,
78 *
79 * hilite_system('<S3>') - opens system 3
80 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
81 *
82 * Here is the system hierarchy for this model
83 *
84 * '<Root>' : 'traffic_jam'
85 * '<S1>' : 'traffic_jam/DisplayUnit'
86 * '<S2>' : 'traffic_jam/Subsystem'
87 */
88 #endif /* RTW_HEADER_traffic_jam_h_ */
89
90 /*
91 * File trailer for generated code.
92 *
93 * [EOF]
94 */
95
File: traffic_jam_private.h
1 /*
2 * File: traffic_jam_private.h
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_traffic_jam_private_h_
17 #define RTW_HEADER_traffic_jam_private_h_
18 #include "rtwtypes.h"
19
20 /* Imported (extern) block signals */
21 extern uint8_T Enable_Display; /* '<Root>/Enable_Display' */
22 extern uint8_T Input_Voltage; /* '<Root>/Input_Voltage' */
23 extern boolean_T Input_Switch; /* '<Root>/Input_Switch' */
24
25 #endif /* RTW_HEADER_traffic_jam_private_h_ */
26
27 /*
28 * File trailer for generated code.
29 *
30 * [EOF]
31 */
32
File: traffic_jam_types.h
1 /*
2 * File: traffic_jam_types.h
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTW_HEADER_traffic_jam_types_h_
17 #define RTW_HEADER_traffic_jam_types_h_
18
19 /* Forward declaration for rtModel */
20 typedef struct tag_RTM_traffic_jam_T RT_MODEL_traffic_jam_T;
21
22 #endif /* RTW_HEADER_traffic_jam_types_h_ */
23
24 /*
25 * File trailer for generated code.
26 *
27 * [EOF]
28 */
29
File: rtwtypes.h
1 /*
2 * File: rtwtypes.h
3 *
4 * Code generated for Simulink model 'traffic_jam'.
5 *
6 * Model version : 1.6
7 * Simulink Coder version : 9.2 (R2019b) 18-Jul-2019
8 * C/C++ source code generated on : Mon Jan 10 20:24:08 2022
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #ifndef RTWTYPES_H
17 #define RTWTYPES_H
18
19 /* Logical type definitions */
20 #if (!defined(__cplusplus))
21 # ifndef false
22 # define false (0U)
23 # endif
24
25 # ifndef true
26 # define true (1U)
27 # endif
28 #endif
29
30 /*=======================================================================*
31 * Target hardware information
32 * Device type: Intel->x86-64 (Windows64)
33 * Number of bits: char: 8 short: 16 int: 32
34 * long: 32
35 * native word size: 64
36 * Byte ordering: LittleEndian
37 * Signed integer division rounds to: Zero
38 * Shift right on a signed integer as arithmetic shift: on
39 *=======================================================================*/
40
41 /*=======================================================================*
42 * Fixed width word size data types: *
43 * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
44 * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
45 * real32_T, real64_T - 32 and 64 bit floating point numbers *
46 *=======================================================================*/
47 typedef signed char int8_T;
48 typedef unsigned char uint8_T;
49 typedef short int16_T;
50 typedef unsigned short uint16_T;
51 typedef int int32_T;
52 typedef unsigned int uint32_T;
53 typedef float real32_T;
54 typedef double real64_T;
55
56 /*===========================================================================*
57 * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T, *
58 * real_T, time_T, ulong_T. *
59 *===========================================================================*/
60 typedef double real_T;
61 typedef double time_T;
62 typedef unsigned char boolean_T;
63 typedef int int_T;
64 typedef unsigned int uint_T;
65 typedef unsigned long ulong_T;
66 typedef char char_T;
67 typedef unsigned char uchar_T;
68 typedef char_T byte_T;
69
70 /*===========================================================================*
71 * Complex number type definitions *
72 *===========================================================================*/
73 #define CREAL_T
74
75 typedef struct {
76 real32_T re;
77 real32_T im;
78 } creal32_T;
79
80 typedef struct {
81 real64_T re;
82 real64_T im;
83 } creal64_T;
84
85 typedef struct {
86 real_T re;
87 real_T im;
88 } creal_T;
89
90 #define CINT8_T
91
92 typedef struct {
93 int8_T re;
94 int8_T im;
95 } cint8_T;
96
97 #define CUINT8_T
98
99 typedef struct {
100 uint8_T re;
101 uint8_T im;
102 } cuint8_T;
103
104 #define CINT16_T
105
106 typedef struct {
107 int16_T re;
108 int16_T im;
109 } cint16_T;
110
111 #define CUINT16_T
112
113 typedef struct {
114 uint16_T re;
115 uint16_T im;
116 } cuint16_T;
117
118 #define CINT32_T
119
120 typedef struct {
121 int32_T re;
122 int32_T im;
123 } cint32_T;
124
125 #define CUINT32_T
126
127 typedef struct {
128 uint32_T re;
129 uint32_T im;
130 } cuint32_T;
131
132 /*=======================================================================*
133 * Min and Max: *
134 * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
135 * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
136 *=======================================================================*/
137 #define MAX_int8_T ((int8_T)(127))
138 #define MIN_int8_T ((int8_T)(-128))
139 #define MAX_uint8_T ((uint8_T)(255U))
140 #define MAX_int16_T ((int16_T)(32767))
141 #define MIN_int16_T ((int16_T)(-32768))
142 #define MAX_uint16_T ((uint16_T)(65535U))
143 #define MAX_int32_T ((int32_T)(2147483647))
144 #define MIN_int32_T ((int32_T)(-2147483647-1))
145 #define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU))
146
147 /* Block D-Work pointer type */
148 typedef void * pointer_T;
149
150 #endif /* RTWTYPES_H */
151
152 /*
153 * File trailer for generated code.
154 *
155 * [EOF]
156 */
157
Conclusion:
1)model is created as per MAAB guidelines
one condition is not followed for saturation block as mentioned in question that limit should be 0-7 but except limit -0.5 to 0.5 this block is showing error that's why i set it to min value -0.5 to 0.5 .
2)seperately data dictionary is created and linked to this model.
3)Code is generated in Embedded coder.