Project Report Adaptive Cruise Control
Project Report Adaptive Cruise Control
Group Members:
Barro Alessandro, Bruscoli Nicolas, Ceccarelli Viviana,
Chiacchiararelli Leonardo, Cintura Manuel, Mariani Lucia
1 Introduction 3
2 Project organization 4
2.1 Hardware and software components . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Model-based design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Project development 9
4.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.1 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.2 High-level requirements . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.3 Low-level requirements . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Unit & Integration testing . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.1 Switch subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2.2 Torque split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2.3 SoC handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.4 Integration test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 Model-in-the-loop (MIL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.4 Automatic code generation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.4.1 Preparation of a Model for Code Generarion . . . . . . . . . . . . . 19
4.4.2 Generate Code using Embedded Coder . . . . . . . . . . . . . . . . 20
4.5 Software-in-the-loop Simulation (SIL) . . . . . . . . . . . . . . . . . . . . . 21
4.6 Processor-in-the-loop Simulation (PIL) . . . . . . . . . . . . . . . . . . . . 23
5 Conclusion 25
1
List of Figures
3.1 Plant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Transmission Dynamics block . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Vehicle longitudinal dynamics block . . . . . . . . . . . . . . . . . . . . . . 8
3.4 Emulation of the radar function . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1 ACC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Front radar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 An overview of the controller block . . . . . . . . . . . . . . . . . . . . . . 11
4.4 An overview of the switch subsystem . . . . . . . . . . . . . . . . . . . . . 12
4.5 Inputs of the test: acceptable speed is the one set by the user, the target
speed is the one of the car ahead . . . . . . . . . . . . . . . . . . . . . . . 12
4.6 Automatically generated test reports . . . . . . . . . . . . . . . . . . . . . 13
4.7 An overview of the torque split subsystem . . . . . . . . . . . . . . . . . . 13
4.8 Test inputs (up) Outputs vs baseline (down) . . . . . . . . . . . . . . . . . 14
4.9 An overview of the SoC handler chart . . . . . . . . . . . . . . . . . . . . . 14
4.10 Input fed to the SoC handler . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.11 OTR output vs baseline (up) PID::P output vs baseline (down) . . . . . . 16
4.12 Speed of the vehicle for 10 SoC . . . . . . . . . . . . . . . . . . . . . . . . 17
4.13 Speed of the vehicle for 50 SoC . . . . . . . . . . . . . . . . . . . . . . . . 18
4.14 Speed of the vehicle for 100 SoC . . . . . . . . . . . . . . . . . . . . . . . . 18
4.15 Comparison of the speed with different SoC . . . . . . . . . . . . . . . . . 19
4.16 Target selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.17 Creation of the SIL block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.18 Difference in longitudinal speed of the original Simulink model and the SIL
model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.19 Hardware settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.20 PIL block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.21 Simulation PIL block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.22 Difference in the longitudinal speed of the original Simulink model and the
PIL model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
Chapter 1
Introduction
The reason for the choice of the Adaptive Cruise Control is because it is one of the most
commonly used features of the ADAS. ADAS (Advance Driver Assistance Systems) are
the electronic systems that assist drivers in driving and parking functions. ADAS increase
car and road safety, using automated technology, such as sensors and cameras.
Nowdays, more and more vehicles are equipped with them, often as standard features.
Adaptive Cruise Control is one of the most advanced technology, being able to facilitate
the driving.
The Adaptive Cruise Control (ACC) is an active safety system that automatically controls
the acceleration and braking of a vehicle. It is activated through a button on the steering
wheel and disengaged by the driver’s braking and/or another button. This report offers
an example which illustrates the benefits of using Model-Based Design in the engineering
workflow. The goal is to show how this approach can be used in the entire development
of the system design.
This report is divided in to the following sections:
• Chapter 2: The project organization is shown and the Model-Based Design is ex-
plained;
• Chapter 3: The Model explanation and the design of the Adaptive Cruise Control
are illustrated;
• Chapter 4: The different steps for the project development (Unity test, MIL, Au-
tomated Generated Code, SIL and PIL simulations are described;
3
Chapter 2
Project organization
2.1.1 Hardware
The hardware used for this project is a PC running Windows and a Raspberry Pi 4 Model
B.
The Raspberry has been used as the core component of the Processor-in-the-loop simu-
lation.
2.1.2 Software
The software used for this project is Simulink: Embedded Coder package, Simscape pack-
age, Powertrain Blockset are required. The software employed to organize the work and
the communication between team members are listed below:
• GitHub: VCS;
4
Figure 2.1: The V-model
• Automatic code generation: using Embedded Coder, the low-level code for the
controller is generated;
• PIL: deploying the generated code to the hardware, performing the processor-in-
the-loop simulation;
• HIL: the plant should be simulated in the HIL module. This step could not be
implemented;
• Acceptance: the real plant is realized, integration tests are performed. This step
could not be implemented.
5
Chapter 3
As anticipated before, this project aims to design an Adaptive Cruise Control: to design
it following the MBD, a plant that models the vehicle longitudinal dynamics is needed.
In Fig 3.1 it is possible to see the whole plant model.
6
3.2 Transmission Dynamics
Thanks to this block it is possible to model the entire driveline, from the ECU torque
request to the motion of the wheels.
7
Figure 3.3: Vehicle longitudinal dynamics block
8
Chapter 4
Project development
4.1 Requirements
4.1.1 Software requirements
In order to be able to interact with the developed model, the following software tools are
needed:
• Matlab R2019b;
• Simulink;
• Simscape;
• Simscape Driveline.
9
Figure 4.1: ACC
10
the system needs to be designed as following: when the first vehicle accelerates, the control
must operate so that the vehicle speed becomes the one desired if it is possible, that is to
say if the two vehicles are far enough. Otherwise, the system must adequate the vehicle
speed to the one needed to keep the safety distance.
11
4.2.1 Switch subsystem
This system is composed of a switch commanded by a majority operator fed with the
same signals that have to be switched. In Fig 4.5 the inputs used to test the unit are shown
that. The two inputs were differentiated as much as possible in order to better understand
which of the signals has been chosen As shown in Fig. 4.6 (right), the Simulink test tool
3
Target_speed
acceptable_speed
2.5
1.5
0.5
Figure 4.5: Inputs of the test: acceptable speed is the one set by the user, the target
speed is the one of the car ahead
is able to generate a document reporting the configuration of the test, to guarantee to the
customer that the test was performed accordingly to his needs. This feature also gives
the opportunity to an external part to perform the same test and verify that the results
are coherent. In the same way the tool can generate a report regarding the output of the
test, in Fig. 4.6 (left) is shown that the test produces successful results, in fact the output
of the test coincides perfectly with the baseline signal.
12
Figure 4.6: Automatically generated test reports
This unit’s goal is to split the signal coming from the PID, asking for torque. The PID
asks for a negative or positive torque, the system has to be able to translate the negative
torque in a signal to be sent to the brake module. To test this unit the following steps
have to be performed: when a positive input is given this is transferred to the engine,
while when a negative input is given it is transferred to the brake output. At the same
time the output assigned to the opposite sign has to be zero. In Fig. 4.8 it is possible to
see how the test input was designed and also that the output corresponds exactly to the
baseline signal, meaning a successful test.
13
Reqested Torque Input
100
80
60
40
20
Req_torque
-20
-40
-60
-80
-100
100
Engine_torque: out
Brake_torque: out
Engine_torque: baseline
90
Brake_torque: baseline
80
70
60
50
40
30
20
10
This unit is a FSM, so a slightly more complicated test has to be performed. The goal
of this unit is to manage the aggressiveness of the control depending on the SoC of the
vehicle’s battery pack: a less aggressive control when the car has less autonomy left. The
interval of possible SoC values has been devided in three segments: minimum, medium
14
and maximum. Each segment corresponds to a different state. There are three states,
since from each state you can go to the other two there are in total 6 transitions. There
is only one input: SoC signal. The input signal, shown in Fig.4.10, is designed in order to
stimulate all the possible transitions. To be more robust against unexpected behaviour
an additional output has been added for the FSM. The SoC signal is expected to never
trespass the 0% and 100% boundaries, so a signal “OutOfRange(OTR)” that rises when
this condition is verified was created. The FSM is designed to check constantly the OTR
signal while performing the ordinary tasks, so a parallel state is created in the FSM. The
100
90
80
70
60
unnamed
50
40
30
20
10
1 2 3 4 5 6 7 8 9 10
Time (seconds)
behaviour of this signal has been tested too. In Fig.4.10 it can be deduced from the input
signal (second half of the signal) that regardless the current state and the previous value
of the SoC signal, the OTR signal raises when expected too. In Fig.4.11 it can be seen
that the output signal matches the baseline, meaning a successful test.
15
OTR: output vs baseline
1 OutOfRange: output
OutOfRange: baseline
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0 1 2 3 4 5 6 7 8 9 10
95
90
85
80
75
70
65
60
55
50
0 1 2 3 4 5 6 7 8 9 10
Figure 4.11: OTR output vs baseline (up) PID::P output vs baseline (down)
16
and cost are significantly reduced.
When validating the model, the first step to be performed is to create the plant of the
system. Then, after the design of the controller, the next step is to verify that “the
controller is able to control the plant” fulfilling all the requirements that were previously
discussed. If this happened, the model is verified and it is possible to continue with the
next step (SIL).
In this case, MIL simulation has the aim to verify the Adaptive Cruise Control.
The implemented control law depends on the speed of the leading vehicle and the distance
that must be respected between two consecutive vehicles according to the Highway code:
1
ds = dmin + v 2
k
The behaviour of the whole system has been tested by plotting the speed of the first
vehicle and the following one.
Since, as mentioned before, the controller takes into account also the SoC value, three
different situations depending on the State of Charge of the battery have been plotted.
As a result, three different responses are shown:
17
Figure 4.13: Speed of the vehicle for 50 SoC
18
As can be seen from the graphs, the model fulfils all the requirements previously de-
fined: the speed limit imposed by the driver (50 Km/h in this case) is not overcame.
In addition, a particular time interval has been considered to show how the SoC value
influences the controller response.
As can be seen from the graphs, where the SoC is higher, the controller can be more
aggressive since it can drain more battery. On the other hand, when the SoC is at its
minimum, the controller has a smoother and slower response to preserve the battery
charge extending its life.
19
Advisor in order to check that the controller is MISRA C compliant.
20
4.5 Software-in-the-loop Simulation (SIL)
A software-in-the-loop (SIL) simulation compiles generated source code and executes the
code as a separate process on a target host computer. By comparing normal and SIL
simulation results, it is possible to test the numerical equivalence of the model and the
generated code. Thanks to the Embedded Coder Toolbox there are different ways to
perform a SIL simulation.
Through a communication channel, Simulink sends stimulus signals to the code on the
computer or target process for each sample interval of the simulation:
• Top-model (SIL simulation generates the stand-alone code interface) and Model
block. For both, the Test behaviour of generated source code on the development
computer. Execution is host/host and non-real time.
• SIL or PIL block (block uses stand-alone code interface). In this case the Simulation
runs compiled object code through S-function. S-function communicates with object
code executing as stand-alone application on the development computer. Execution
is host/host and non-real time.
Then it is possible to check the hardware implementation and check the host archi-
tecture on which automatically generated code for the controller will run.
The following step is to check a specific flag in the Code Generation section, in particular
in the Verification in which it is possible to select the created block. After that, clicking
on the unit, in the C/C++ Code, clicking Build creates the SIL version of the Controller
subsystem block.
After the creation of the SIL block, a comparison simulation has been carried out. The
entire plant has been simulated and then it is possible to observe the error between the
two different simulations.
21
1. From the Configuration Parameters → Code Generation → Verification → Ad-
vanced Paramters → Create block drop-down list, select the SIL block.
2. Click OK.
5. Click Build, which starts the subsystem build process that creates the SIL block for
the generated subsystem code.
Figure 4.18: Difference in longitudinal speed of the original Simulink model and the SIL
model
It is possible to see that the difference between the two simulations is negligible, so
the whole result is acceptable.
22
4.6 Processor-in-the-loop Simulation (PIL)
The chosen hardware for the simulation is the Raspberry Pi 4 model B, equipped with
quad-core processor (ARM-cortex), wirelessly connected to the PC. To provide a stable
connection between hardware and Simulink it is necessary to set properly the device ad-
dress (IP address) and the credential of the OS system for privileged read/write operation.
The generation of the code is widely described above on the SIL section and the
procedure for generation of the PIL block is the same as for SIL.
Once the controller has been replaced by PIL block, the entire code is deployed on
Raspberry board and the simulation starts.
23
Figure 4.21: Simulation PIL block
From the comparison simulation, it can be noticed the difference between the longi-
tudinal speed of original Simulink model and the one of PIL model.
Figure 4.22: Difference in the longitudinal speed of the original Simulink model and the
PIL model
The overall result is acceptable. The difference between the two simulations is negli-
gible and bounded in a very short range.
24
Chapter 5
Conclusion
The designed controller is quite simple and cheap in terms of control design (a PID con-
troller is the core of the control law). It can be easily integrated into a more complex
structure thanks to the used modular approach. Future improvements would consist of
using the OTR signal for more complex control actions, like some checks or the disen-
gagement of the whole system. The system can be integrated with other ADAS systems
like an emergency brake system or a collision-avoidance system (alternatively a simpler
overtake assist). The system can not be directly deployed into a passenger vehicle as it
is. Its interface by the way is structured in order to be integrated in a more complex
ECU software: in modern ECUs there are various systems able to request torque, these
signals are handled by a high level controller that dispatches the most adequate torque
signal coming from one of the various subsystems, accordingly to predefined policies. The
presented document illustrates how powerful the model-based design approach can be.
Following the V-model tool, the designer is able to guarantee a rigorous step by step
workflow. Thanks to the followed standardized workflow the output product could be
sold to a final user that would have all the needed documentation to assess the correct
behaviour of the system.
25