Power Window Control Project
This example shows how to use a project to model a power window system for an automobile. The project uses Model-Based Design and these large-scale modeling techniques.
Model blocks to separate the hierarchy into separate models.
Variant Subsystems blocks to model and switch between different design choices.
Libraries to capture algorithms for reuse in variant subsystems.
Projects to manage the files required for the system development.
Design Requirements
In this example, consider the passenger-side power window system of an automobile. This system can never exert a force of more than 100 N on an object when closing the window.
When the model detects such an object, the model must lower the window by about 10 centimeters.
For more information on the design requirements, see Power Window.
Explore the Project
Upon visual inspection of the project, you can see features used to organize the example. These features are used to organize the project:
Folders
File Classification
Shortcuts
Folders
The project is organized into these folders:
configureModel
- MATLAB® files that control the main system model variant configurationdata
- Images required by the projecthmi
- Files that animate the power window responsemodel
- Main system model, controller model, models for testing the controller, and libraries that support these modelstask
- MATLAB files that simulate the model for the different model configurations and generate coverage reports for the controllerutilities
- MATLAB files to initialize the model, to generate spreadsheet input, to add data to the generated spreadsheet, and manage the project environment at startup and shutdown
File Classification
Files in Projects have different classifications visible in the Labels pane. Each label describes the specific role a file contributes to the body of the project.
Configuration
- Files that configure the project or model.PrjConfig
- Files that configure the project by adding its files to the path at startup and removing them at shutdownDesignConfig
- Files that determine which model configuration is active at a given timeDesign
- Main system model and its referenced control modelDesignSupport
- Files such as libraries, data, and model simulationSimulation
- Files that simulate the model for a specific configurationTest
- Control coverage, the control interaction, and the test harness modelsVisualization
- Files that animate the motion of the power window
Shortcuts
Project shortcuts provide quick access to project files that are used most often. Some shortcuts contain general tasks, such as adding the project to the path at startup and removing it at shutdown. In addition, project shortcut groups help organize the shortcuts.
Interactive Testing - Files used for interactive testing of the controller
Main Model - File for top-level Simulink model
Model Coverage - Files used for model coverage of the controller
Simulation - Files used for simulation of model variant configurations
Explore Simulink Models in Project
The Simulink models for this project are located in the model
folder.
Main System Model
Models for Testing
Main System Model
The main system model is slexPowerWindowExample
. This model consists of driver_switch
and passenger_switch
subsystem blocks, which generate the inputs to the power_window_control_system
block. The power_window_control_system
block validates the states of the passenger and driver inputs. This block also determines if obstacle is blocking the path of the window. The referenced controller produces the window motion command signals sent to the active variant of the window system. The window_system
block output is the feedback to the control system block.
To visualize the results of simulation, the Simulation Data Inspector logs the output data and Simulink 3D Animation™ animates the motion of the window.
Model Variants
The main system model in this project uses Variant Subsystem blocks to allow for multiple implementations within a subsystem. You can change the active implementation programmatically prior to simulation. The main model contains four Variant Subsystem blocks, each with variant choices that can be programmatically modified. Those four variant subsystems are:
slexPowerWindowExample/driver_switch
slexPowerWindowExample/passenger_switch
slexPowerWindowExample/window_system
slexPowerWindowExample/power_window_control_system/detect_obstacle_endstop
Each variant choice is associated with a variant control. The variant choice is active when its variant control evaluates to true
.
You can control the combinations of variant choices to create model variant configurations using the files under the DesignConfig
classification. Model variant configurations include:
Power Window Controller Hybrid System Model
Power Window Controller and Detailed Plant Model
Power Window Controller With Data Acquisition Effects
Power Window Controller With Controller Area Network (CAN) Communication
Power Window Controller Hybrid System Model
This model variant uses Stateflow® and Simulink to model both discrete event reactive behavior and continuous time behavior. The models uses a low-order plant model to validate the roll-up and roll-down behavior. You can simulate this variant configuration using the SimHybridPlantLowOrder
shortcut. This shortcut activates only the variant subsystem corresponding to this model configuration. Since this model does not take into account power effects, the only output logged is position. The Simulation Data Inspector displays the logged position data.
Power Window Controller and Detailed Plant Model
This model variant shows a more detailed plant model that includes power effects in the electrical and mechanical domains. This variant validates that the force exerted by the window on a trapped object never exceeds 100 N. This model variant requires Simscape™ Multibody™ and Simscape™ Electrical™ licenses. You can simulate this variant configuration using the SimHybridPlantPowerEffects
shortcut. Unlike the Power Window Controller Hybrid System Model, this variant configuration takes into account the power effects. The Simulation Data Inspector displays the logged data from armature current, position, and force exerted by the power window.
Power Window Controller With Data Acquisition Effects
This model variant shows additional effects due to implementation that affect the control. The phenomena included are signal conditioning to measure the armature current and quantization of the measurement. This model variant requires Simscape Multibody, Simscape Electrical, DSP System Toolbox™, and Fixed-Point Designer™ licenses. You can simulate this variant configuration using the SimHybridPlantPowerEffects+ControlDAQEffects
shortcut. As with the Power Window Controller and Detailed Plant Model, the Simulation Data Inspector displays the logged data from armature current, position, and force exerted by the power window.
Power Window Controller With CAN Communication
This model variant shows the use of a CAN to communicate the commands to control window movement. The switches that may be located in the center console of the vehicle and that produce the commands are included in this model variant. This model variant requires Simscape Multibody, Simscape Electrical, DSP System Toolbox, and Fixed-Point Designer licenses. You can simulate this variant configuration on a machine running windows OS using the SimCANCommunication
shortcut.
Models for Testing
To test the state machine that controls the power window, you can run the project shortcuts for testing. Model shortcuts for testing the controller include:
InteractiveExample
CoverageExample
IncreaseCoverageExample
InteractiveExample
This model shortcut opens the model slexPowerWindowCntlInteract
. This model contains the power window controller, which is a state machine. This model also contains inputs to the controller that are selected with manual switch blocks.
The power window controller has four external inputs:
Passenger Input
input consists of a vector with three elements:
neutral
: Passenger control switch is not depressed.up
: Passenger control switch generates the up signal.down
: Passenger control switch generates the down signal.
Driver Input
input consists of a vector with three elements:
neutral
: Driver control switch is not depressed.up
: Driver control switch generates the up signal.down
: Driver control switch generates the down signal.
Window Frame Endstops
input consists of a vector with two elements:
0
: Window moves freely between top or bottom.1
: Window is stuck at the top or bottom because of physical limitations.
Obstacle Present
input consists of a vector with two elements:
0
: window moves freely between top or bottom1
: window has obstacle within its frame
You can interactively test the controller by simulating the model and selecting the desired combination of inputs via the manual switch blocks. After selecting inputs, you can verify the internal controller state and controller output against the desired result for the specific set of inputs.
CoverageExample
This model shortcut opens the model slexPowerWindowCntlCoverage
. The model contains a state machine power window controller with Repeating Sequence block inputs.
You can use the Simulink Coverage Model Coverage tool to validate the discrete event control of the window. The Model Coverage tool determines the extent to which a model test case exercises the conditional branches of the controller. The tool evaluates whether all transitions in the discrete event control are taken given the test case. The tool also evaluates whether all clauses in a condition that enables a particular transition have become true. One transition may be enabled by multiple clauses, for example, the transition from emergency back to neutral occurs when either 100 ticks have occurred or when the endstop is reached.
IncreaseCoverageExample
This model shortcut opens the model slexPowerWindowCntlCoverageIncrease
. This model contains the power window controller that is a state machine. This model also contains a From Spreadsheet block that provides multiple sets of inputs to the controller. These input sets combine with the one from the CoverageExample model to exercise more of the logic in the power window controller:
Logged
: Logged from theCoverageExample
.LoggedObstacleOffEndStopOn
: Logged from theCoverageExample
with ability to hit endstop.LoggedObstacleOnEndStopOff
: Logged from theCoverageExample
with obstacle in window.LoggedObstacleOnEndStopOn
: Logged from theCoverageExample
with obstacle in window and ability to hit endstop.DriverLoggedPassengerNeutral
: Logged from theCoverageExample
for only the driver. Passenger takes no action.DriverDownPassengerNeutral
: Driver lowering window. Passenger takes no action.DriverUpPassengerNeutral
: Driver raising window. Passenger takes no action.DriverAutoDownPassengerNeutral
: Driver lowering window for 1 second (auto-down). Passenger takes no action.DriverAutoUpPassengerNeutral
: Driver raising window for 1 second (auto-up). Passenger takes no action.PassengerAutoDownDriverNeutral
: Passenger lowering window for 1 second (auto-down). Driver takes no action.PassengerAutoUpDriverNeutral
: Passenger raising window for 1 second (auto-up). Driver takes no action.
The model coverage shortcut GenerateIncreasedCoverage
uses the multiple input sets with the Simulink Coverage Model Coverage tool to validate the discrete event control of the window and generate a coverage report for the multiple input sets.