Main Content

Author Functions for Software Components of 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 contains three stereotypes.

  • FunctionBase is a stereotype used as the base for all function stereotypes.

  • CriticalFunction stereotype applies to functions that are critical in determining the output acceleration.

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

  1. To open the Property Inspector, select Modeling > Design > Property Inspector.

  2. In the Functions Editor, select fuse_vision_and_radar.

  3. In the Property Inspector, select Stereotype > Add ACCSoftwareProfile.CriticalFunction to 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 TrackerLogging component.

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 SensorFusion component.

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.

See Also




Related Topics