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. This example uses Simulink®, Simulink® Coverage™, DSP System Toolbox™, Simscape™ Multibody™, Fixed-Point Designer™, Simscape™ Electrical™, Simscape™, and Simulink® Real-Time™.

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 the design requirements, see Power Window.

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.

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

slexPowerWindowStart

Exploring the Project

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

  • Folders

  • File Classification

  • Shortcuts

Folders

The project is organized into the following folders:

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

  • data - Images required by the project

  • hmi - Files that animate the power window response

  • model - Main system model, controller model, models for testing the controller, and libraries which support these models

  • task - MATLAB files that simulate the model for the different model configurations and generate coverage reports for the controller

  • utilities - MATLAB files to initialize the model, to generate spreadsheet input, to add data to the generated spreadsheet and to manage the project environment at startup and shutdown

File Classification

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

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

  • DesignConfig - Files that determine which model configuration is active at a given time

  • Design - Main system model and its referenced control model

  • DesignSupport - Files such as libraries, data, and model simulation

  • Simulation - Files that simulate the model for a specific configuration

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

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

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

Since there are four programmatically modifiable 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 Simscape™ Multibody™ and Simscape Power Systems™ 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 Simscape Multibody, Simscape Power Systems, 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 Simscape Multibody, Simscape Power Systems, DSP System Toolbox, and Fixed-Point Designer 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

  • 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 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 Coverage (TM) 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 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.

These input sets are:

  • Logged: Logged from the CoverageExample.

  • LoggedObstacleOffEndStopOn: Logged from the CoverageExample with ability to hit endstop.

  • LoggedObstacleOnEndStopOff: Logged from the CoverageExample with obstacle in window.

  • LoggedObstacleOnEndStopOn: Logged from the CoverageExample with obstacle in window and ability to hit endstop.

  • DriverLoggedPassengerNeutral: Logged from the CoverageExample 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. 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 if all transitions in the discrete event control have been taken into account given the input sets we run.

Related Topics