main content

model an elevator system by using atomic subcharts -凯发k8网页登录

this example shows how to model a two-car elevator system by using linked atomic subcharts in stateflow®. the elevator system consists of a simulink® model and a user interface (ui). the model contains two stateflow charts:

  • elevator system models the core logic that delegates incoming requests from the ui to the nearest available elevator car. this chart contains a pair of atomic subcharts that implement identical logic for the cars.

  • ui controller processes information from the elevator system chart and updates the ui display. in this chart, each atomic subchart determines when to move an elevator car and when to open its doors.

at the start of simulation, the model opens the ui. the ui shows two elevator cars that can stop at nine floors. at the bottom of the ui, two yellow rectangles represent the interior of the elevator cars. while the example is running, you call an elevator car, request a stop at a floor, or set off a fire alarm by clicking the buttons on each floor hallway and inside the elevator cars. the ui responds by modifying the input values and triggering input events for the elevator system chart.

manage requests from user interface

the elevator system chart consists of three parallel subcharts. each of these subcharts manages a queue of requests from the ui:

  • the elevator_manager subchart implements the main control logic for the elevator system. this subchart manages the hall queue, which holds all the requests that are generated when you click a button in one of the floor hallways. the subchart processes these requests and delegates them to one of the elevator cars, depending on availability and proximity to the request.

  • elevator_a and elevator_b represent the logic for the two elevator cars. each car has its own queue that holds all of its floor requests. floor requests are generated when you click a button inside the elevator car or when the elevator_manager delegates a request from the hall queue to the car.

reuse logic patterns by using atomic subcharts

the elevator cars use identical logic to process their individual request queues. the elevator system chart models their behavior by using linked atomic subcharts from a .

in the library model, the chart elevator implements the logic for a generic elevator car. to program the subcharts elevator_a and elevator_b so that they control the appropriate car, you map data and events in each subchart to the corresponding data and events in the main chart. for instance, for elevator_b:

  • the subchart input floor_request maps to the chart input carb_floor_request.

  • the subchart output position maps to the chart output b_position.

  • the subchart output dooropen maps to the chart output doorbopen.

  • the subchart event car_call maps to the chart event car_call_b.

to see the mappings for each atomic subchart, right-click the subchart and select subchart mappings.

to control the ui display of each elevator car, the ui controller chart uses two atomic subcharts linked from a .

for more information about using atomic subcharts to encapsulate and reuse logic, see .

incorporate atomic subcharts in your design

the model in this example is a redesigned version of an that does not use atomic subcharts. the original model uses separate subcharts to manage floor requests (subcharts elevator_a and elevator_b of the elevator system chart) and to control the ui display of elevator cars (subcharts cara_controller and carb_controller of the ui controller chart). in each case, the subcharts are nearly identical copies of one another. they differ only in the names of the data and events that they use.

to convert the duplicate subcharts to atomic subcharts, first make a library atomic subchart out of one of the subcharts. then use linked instances of this library to replace the duplicate subcharts. for example, consider the duplicate elevator car subcharts of the elevator system chart. these subcharts call several functions and local variables that are defined in the elevator_manager subchart. before creating an atomic subchart, you must make these subcharts independent and self-contained units.

1. migrate these functions from the elevator_manager subchart into the parent chart:

  • exists_in_queue

  • deregister

  • dequeue

rename these functions to distinguish them from the functions inside the elevator car subcharts.

2. using the model explorer, migrate these variables from the elevator_manager subchart into the parent chart:

  • hall_call_queue

  • hall_call_status

3. in the elevator system chart, set the export chart level functions chart property to true. for more information, see .

4. modify the elevator_manager and elevator_a subcharts to use the migrated functions and variables.

5. create a library atomic subchart from the elevator_a subchart, as described in .

6. to enable the atomic subchart to pass the position of the elevator car to the containing chart, change the scope of the subchart data position from local to output.

7. replace the two elevator subcharts with the linked atomic subchart. for each linked atomic subchart, map data and events to the parent chart. for more information, see .

related topics

    网站地图