authoring functions for software components of an adaptive cruise control -凯发k8网页登录
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 .
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.
to open the property inspector, select modeling > design > property inspector.
in the functions editor, select
fuse_vision_and_radar
.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.
slbuild('accsoftwarecompositionscratch');
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 .
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
tools
- |
objects
functions
- | |