Elevator Control Simulation and Code Generation Using Ladder Logic

This example shows how to model a controller for a single-car elevator in Simulink® by using ladder logic. The elevator system is modeled as a MATLAB Function Block. The example also showcases ladder code generation.

Step 1: Opening the Model

Open the plcdemo_ladder_elevator by using:

>> plcdemo_ladder_elevator

Step 2: Model Initialization

When the model is opened, it sets the initial values of different parameters used in elevator controller from the plcdemo_ladder_elevator_init.m file.

Step 3: Model Components

Floor Requests

Floor Requests are a group of constant blocks. It specifies the indoor and outdoor floor requests to the controller. By default all the constant blocks are set to zero.

Elevator Control System

Elevator Control System is a subsystem which consists of Digital Input modules(DI), Digital Output modules(DO) and a PLC Controller. DI modules preprocess floor request input and other sensor inputs. Similarly, DO modules preprocess output of PLC controller and sets output contactors. PLC controller is the brain of the system. It performs all the calculations and control action.

Elevator

Elevator is a MATLAB function block which show cases mathematical model of a single car elevator system.

Step 4: Run the Simulation

Click Run button to start simulation. Open HMI and use the following controls:

  • Exterior Buttons: Represents the exterior floor request buttons.

  • Interior Buttons: Represents the interior floor request buttons.

  • Photocell: Represents the door sensor.

Step 5: Ladder code generation

Open elevator control model:

>> plcdemo_ladder_elevator

Select the plcdemo_ladder_elevator/Elevator Control System/Elevator PLC Ladder Diagram System/Elevator Controller block and right-click PLC Coder->Generate Code for Subsystem to generate ladder code.