Modeling Software Architecture of Throttle Position Control System
This example shows how to author the software architecture of a throttle position control system in System Composer™, schedule and simulate the execution order of the functions from its components, and generate code.
Throttle Control Composition
In this example, the software architecture of a throttle position control system is modeled in System Composer using six components. The throttle position control component reads the throttle and pedal positions and outputs the new throttle position. Two throttle position sensor components provide the current position of the throttle, and a pedal position sensor component provides the applied pedal position. A controller component uses these signals to determine the new throttle position as a percent value. An actuator component then converts the percent value to the appropriate value for the hardware.
model = systemcomposer.openModel('ThrottleControlComposition');
Simulate the Model at the Architecture Level
Simulate the software architecture model.
To view the list of functions from the components and edit their properties, such as execution order, use the Functions Editor. To open the Functions Editor, on the Modeling tab, in the Design section, click Functions Editor. For more information about the Functions Editor, see Simulate and Deploy Software Architectures.
Simulate the Model at the System Level
To simulate the throttle control system with the throttle body, use a Model block to reference the software architecture model in the system model. The
ThrottleControlSystem model also contains a Stateflow® Chart block to model a more complex scheduling of the functions of the software architecture.
A Stateflow license is required for this functionality.
To simulate the system model containing the plant and Stateflow scheduler, use this command.
View the Types in the Software Architecture
To view the unique component types in the software architecture, create a class diagram view and add all components. To create a class diagram view, on the Modeling tab, in the Views section, click Architecture Views, then click New to create a new class diagram. Select Class Diagram from the Diagram section in the Views Gallery. From the list, select Add Component Filter > Select All Components to add all components in the software architecture to the view.
To populate methods in the class diagram, you must compile the software architecture model. To compile the model, navigate to Modeling > Update Model.
For more information, see Class Diagram View of Software Architectures.
You can generate code to deploy the control system to the target hardware. Code generation requires an Embedded Coder® license. Open the
ThrottleControlComposition model and execute the
slbuild command, or press Ctrl+B to build the model and generate code.
The generated code contains an entry-point function for each function of the components in the software architecture. For more information on code generation for export-function models, see Generate Code for Export-Function Model
Copyright 2020-2021 The MathWorks, Inc.