Authoring Functions for Software Components of an Adaptive Cruise Control
This example shows how to design an adaptive cruise control system in System Composer™:
Capture the system architecture in terms of constituent software components and functions.
Indicate which functions are critical for maintaining the desired speed of the vehicle using custom properties.
Implement the behavior of the functions using Simulink.
Adaptive Cruise Control Architecture
An adaptive cruise control (ACC) system is a control system that modifies the speed of a vehicle in response to conditions on the road. As in regular cruise control, the driver sets a desired speed for the vehicle. Additionally, the adaptive cruise control system can slow the vehicle down if there is another vehicle moving more slowly in the lane in front of it.
The ACC algorithm requires that the vehicle knows the curvature of the road, the relative distance, and velocity of the lead vehicle immediately in front of it. For more information about the ACC algorithm and the entire system, see Adaptive Cruise Control with Sensor Fusion (Automated Driving Toolbox). The system software retrieves detections from a radar sensor and video from a camera, which are fused by a sensor fusion component for more accurate detections. The detections are provided to multi-object tracker to determine the relative distance and velocity of the lead vehicle. These states and the longitudinal velocity of the vehicle are then provided to a controller component to compute the acceleration to apply to the vehicle to maintain a safe distance.
Author Components and Interfaces
First, create the architecture of the adaptive cruise control software. To open a new software architecture model, use this command.
systemcomposer.createModel('ACCSoftwareCompositionScratch', 'SoftwareArchitecture', true);
The system is composed of a
SensorFusion component, a
MultiObjectTracking component, a
Controller component, and a
TrackerLogging component for monitoring.
Author Component Functions
To specify the functions that define the behavior of each component, open the Functions Editor. To open the Functions Editor, on the Modeling tab, in the Design section, click Functions Editor. To create the functions to implement the behavior of each component, select a component and use the add button. For more information about authoring functions using the Functions Editor, see Author and Extend Functions for Software Architectures.
You can modify the built-in function properties such as the name, period, or execution order. The name and period properties can be modified by editing the corresponding cells in the table. You can specify the execution order of functions in the Functions Editor by dragging functions into the desired order or by selecting a function and clicking the up and down buttons.
Add Custom Properties to Functions
You can apply custom properties using System Composer profiles and stereotypes. Load the profile
ACCSoftwareProfile and import it into the composition. The profile constains three stereotypes.
FunctionBaseis a stereotype used as the base for all function stereotypes.
CriticalFunctionstereotype applies to functions that are critical in determining the output acceleration.
NonCriticalFunctionstereotype applies to functions that are not critical in determining the output acceleration.
Add custom properties to a function by applying stereotypes from the loaded profile.
To open the Property Inspector, select Modeling > Design > Property Inspector.
In the Functions Editor, select
In the Property Inspector, select Stereotype > Add
ACCSoftwareProfile.CriticalFunctionto apply the stereotype.
This stereotype designates functions that are executed to determine the output acceleration. In the ACC software architecture, all functions are critical to determining the acceleration except for the functions defined in the
Generate Code for Functions
Code for the adaptive cruise control system can be generated and deployed to the target hardware using Embedded Coder®. To generate code, execute the
slbuild command, or press Ctrl+B to build the model.
Since no component has a linked behavior, the generated code contains empty definitions for each function in the software architecture.
Implement Behaviors for Functions
You can implement the behaviors for functions of a component in Simulink by creating a Simulink behavior. Right-click the
SensorFusion component and select
Create Simulink Behavior, or navigate to Modeling > Component > Create Simulink Behavior. To choose the type of the Simulink behavior, for Type, select
Model Reference: Export-Function or
Model Reference: Rate-Based. Click OK to create a
SensorFusion export-function model linked to the
For more information on using the export-function modeling style, see Export-Function Models Overview.
The new model contains one inport block with a function-call output port,
fuse_vision_and_radar, with a sample time of 0.1 seconds, as specified in the Functions Editor. You can connect the output port to a function-call subsystem that models the behavior of that function.
Copyright 2021 The MathWorks, Inc.