Documentation Center

  • Trial Software
  • Product Updates

Power Window Control Project

This example shows how you can use MathWorks® software and the Model-Based Development process to go from concept to implementation for a power window system for an automobile.

Overview of Design Requirements

In this example, consider the passenger-side power window system of an automobile. Note a critical aspect of this system is that it can never exert a force of more than 100 N on an object when closing the window, for example:

When the model detects such an object, it must lower the window by about 10 centimeters.

For more information on design requirements see power window controller documentationsee power window controller documentation

Using Model-Based Development and Large Scale Modeling

This example uses Model-Based Design and large scale modeling techniques such as,

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

  • Simulink® Project to manage the files required for the system development.

Opening Power Window Control Project

Run the following command to create and open a working copy of the project files for this example.

slexPowerWindowStartslexPowerWindowStart

Exploring the Project

Upon visual inspection of the project, you can see features from Simulink Project used to organize the example. These features are

  • Folders

  • File Classification

  • Shortcuts

Folders

The project is organized into the following folders:

  • configureModel - Contains the MATLAB® files controlling the main system model variant configuration.

  • data - Contains the images required by the project.

  • hmi - Contains the files to animate the response of the power window.

  • model - Contains the main system model, controller model, models for testing the controller, and libraries which support these models.

  • task - Contains the MATLAB files that simulate the model for the different model configurations.

  • utilities - Contains the MATLAB files to initialize the model, and to manage the project's environment at startup and shutdown.

File Classification

Files in Simulink Projects have different classifications visible in Labels Pallete. Each label describes the specific role a file contributes to the body of the project. In this project, new classifications were added, including:

  • Configuration - the files that configure the project or model.

  • PrjConfig - the files that configure the project by adding its files to the path at startup and removing them at shutdown.

  • DesignConfig - the files that determine which model configuration is active at a given time.

  • Design - the main system model and its referenced control model.

  • DesignSupport - files such as libraries, data, and model simulation.

  • Simulation - the files that simulate the model for a specific configuration.

  • Test - the control coverage, the control interaction, and the test harness models.

  • Visualization - the files that animate the motion of the power window.

Shortcuts

Project shortcuts are used to obtain 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. The new shortcut groups are

  • Interactive Testing contains files used for interactive testing of controller.

  • Main Model contains file for top level Simulink model.

  • Model Coverage contains files used for model coverage of controller.

  • Simulation contains files used for simulation of model variant configurations.

Exploring Simulink Models in Project

The Simulink Models for this project are located in the model folder. The models of interest are

  • Main System Model

  • Models for Testing

Main System Model

In this example under the model folder, the main system model is slexPowerWindowExample. This model consists of the driver and passenger switch blocks, which generate the inputs to the system. The inputs then go through the control system model, which validates the states of the passenger and driver inputs. The control system block also determines if there is an obstacle blocking the window's path. The referenced controller produces the window motion command signals sent to the active variant of the window system. The window system output is the feedback to the control system block.

To visualize the results of simulation, Simulation Data Inspector (SDI) logs the output data and Simulink 3D Animation™ animates the window's motion.

Model Variants

The main system model in this project uses the Variant Subsystem block to allow for multiple implementations of within a subsystem. The active implementation can be programmatically changed prior to simulation. In the main model, there are four Variant Subsystem blocks each with variant choices. 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.

Since there are four Variant Subsystem blocks in the main model, there are MATLAB files to control the combinations of variant choices to create model variant configurations which are found under the DesignConfig classification. Available model variant configurations are

  • 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. It 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. Simulation Data Inspector(SDI) 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 is used to validate that the force exerted by the window on a trapped object never exceeds 100 N. This model variant requires SimMechanics™ and SimPowerSystem™ products to be installed. You can simulate this variant configuration using the SimHybridPlantPowerEffects shortcut. Unlike the previous variant model, this variant configuration takes into account the power effects. SDI 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 SimMechanics, SimPowerSystem, DSP System Toolbox™, and Fixed-Point Designer™ products to be installed. You can simulate this variant configuration using the SimHybridPlantPowerEffects+ControlDAQEffects shortcut. Like the previous model, SDI 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 SimMechanics, SimPowerSystem, DSP System Toolbox, Fixed-Point Designer, and Simulink® Real-Time™ products to be installed. 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. Available model shortcuts for testing the controller are

  • InteractiveExample

  • CoverageExample

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 which are selected with manual switch blocks.

The power window controller has four external inputs:

  • Passenger Input

  • Driver Input

  • Window Frame Endstops

  • Obstacle Present

Passenger Input

This input consists of a vector with three elements:

  • neutral: the passenger control switch is not depressed

  • up: the passenger control switch generates the up signal

  • down: the passenger control switch generates the down signal

Driver Input

This input consists of a vector with three elements:

  • neutral: the driver control switch is not depressed

  • up: the driver control switch generates the up signal

  • down: the driver control switch generates the down signal

Window Frame Endstops

This 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

This input consists of a vector with two elements:

  • 0: window moves freely between top or bottom

  • 1: 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 making the selection of inputs, you can verify the internal controller state and controller output against the desired result for this specific set of inputs.

CoverageExample

This model shortcut opens the model, slexPowerWindowCntlCoverage. This model contains the power window controller which is a state machine. This model also contains inputs to the controller which are repeating sequence blocks.

You can use the Simulink Verification and Validation™ Model Coverage tool to validate the discrete event control of the window. The Model Coverage tool helps determine the extent to which a model test case exercises the conditional branches of the controller. It also helps evaluate whether all transitions in the discrete event control are taken given the test case we run. It also evaluates whether all clauses in a condition that enables a particular transition have become true. One transition may be enabled by multiple clauses, e.g., the transition from emergency back to neutral occurs when either 100 ticks have occurred or when the end stop is reached.

More Information on Power Window Controller

See power window controller documentationSee power window controller documentation

More Information on Simulink® Project

See Simulink Project documentationSee Simulink Project documentation

Was this topic helpful?