Build a Hybrid Model

Overview

This tutorial shows you how to add SimEvents® blocks to an existing Simulink® model to create a hybrid model. In SimEvents, a hybrid model is one that incorporates both time-based and event-based modeling.

The Simulink model is an anti-lock braking system (ABS). You introduce discrete-event blocks that simulate a network delay effect between the ABS controller and the braking system, creating a simple distributed control system. The completed model, shown in the graphic below, will illustrate the negative effects of communication delays on the overall braking performance.

You will:

  • Use SimEvents gateway blocks to convert time-based signals to event-based signals and vice-versa.

  • Attach data from time-based dynamics to SimEvents entities whose timing is independent of the time-based dynamics.

  • Use discrete events to update signals that influence time-based dynamics.

  • Adjust parameters in the discrete-event system to affect the results of the overall hybrid model.

Lesson 1: Run the Time-Based Model

This lesson examines the performance of the existing ABS model. In this version of the model, which contains only Simulink blocks, there is no communication delay between components of the ABS.

Open the existing ABS model by clicking abs_timebasedabs_timebased.

The model contains the following subsystem blocks that together form a completed closed-loop model of an ABS:

  • Desired Relative Slip block that provides a setpoint to the controller.

  • ABS Controller subsystem that accepts a setpoint from the Desired Relative Slip block and provides a control signal to the braking system.

  • Brake System Dynamics subsystem that models the behavior of an actual braking system.

  • Sensor Relative Slip subsystem that feeds a measured slip value back to the ABS Controller block.

Simulate the braking system. In the Simulink Editor, select Simulation > Run.

The scope outputs show:

  • The change in wheel speed versus the decreasing speed of the vehicle. The plot shows that the wheel speed stays below the vehicle speed without locking up (suddenly decreasing towards zero), with vehicle speed going to zero in less than 15 seconds.

  • The slip response of the braking system relative to the Desired setpoint. Throughout the simulation, the error between the desired slip value and the measured slip value remains small.

Lesson 2: Explore the Time-Based Model

Before you modify the model to add discrete-event behavior, you should understand how the time-based portion of the model works. This lesson examines each block in the time-based model.

Desired Relative Slip Block

The desired slip value is based on some physical modeling known as the mu-slip curve. The mu-slip curve is the friction coefficient between the tire and the road surface, mu, expressed as an empirical function of slip. The desired slip is set to the value of slip at which the mu-slip curve reaches a peak value, this being the optimum value for minimum braking distance. For more information about the mu-slip curve, see Modeling an Anti-Lock Braking SystemModeling an Anti-Lock Braking System.

Controller Subsystem

The ABS Controller subsystem contains a further subsystem that executes bang-bang control, based upon the error between measured slip and desired slip. A bang-bang controller is a type of feedback controller that switches between two states, based on the sign of the error signal at its input. In this model, the output of the bang-bang controller translates to an on/off rate that is supplied to the braking system.

Brake System Dynamics Subsystem

The Brake System Dynamics subsystem is complex. What follows is a high-level examination of how it works. For a more detailed analysis of a similar system, see Modeling an Anti-Lock Braking SystemModeling an Anti-Lock Braking System.

The Brake System Dynamics subsystem:

  • Accepts a control signal from the ABS Controller subsystem, based on the error between measured slip and desired slip.

  • Delays the signal from the ABS Controller subsystem to model the delay associated with the hydraulic lines of an actual braking system.

  • Integrates the on/off rate supplied by the ABS Controller subsystem, to determine the required braking pressure.

  • Multiplies the brake pressure signal by the area and radius of the hydraulic braking system piston, relative to the wheel, to determine the brake torque that is applied to the wheel.

  • Uses the calculated brake torque to calculate the wheel speed.

  • Uses both the vehicle weight and the friction coefficient between the tire and the road surface to determine the vehicle speed.

  • Calculates the relative slip, based on the wheel speed, the vehicle speed, and the minimum required stopping distance.

Sensor Relative Slip Subsystem

The Sensor Relative Slip subsystem contains a Gain block where you can specify the accuracy of the sensor in converting the actual relative slip to a measured value that feeds back to the controller. A gain value of 1 simulates the ideal case of a sensor that measures the slip with 100% accuracy.

Lesson 3: Add Event-Based Behavior

In this lesson, you'll create the hybrid model by adding blocks from the SimEvents library to the model introduced in Lesson 1: Run the Time-Based Model. To simplify the top-level view of the model, the SimEvents blocks are placed in a subsystem. This subsystem models a communication delay between the ABS controller and the braking system. The communication delay is a simple representation of the delay effect that distributed components might experience when they communicate over a heavily-loaded in-vehicle network. Each SimEvents entity in the delay subsystem represents a data packet that conveys control signal information between the controller and the braking system.

Top-Level View of Completed Hybrid Model

The completed model will look as shown in the preceding graphic. Both the ABS Controller and Brake System Dynamics blocks are time-based systems. The Network Delay subsystem block is an event-based system. In SimEvents, when signals transition between the time-based domain and the event-based domain, or vice-versa, the blocks in the Gateways block library manage this signal conversion.

To learn about the Network Delay subsystem behavior and for instructions on building and integrating the subsystem, see:

How the Network Delay Subsystem Works

The Network Delay subsystem models a communication link that samples information from the ABS controller and conveys that information to the braking system. The following sections discuss how the network delay subsystem works, before providing instructions to build the subsystem and integrate it with the existing ABS system to complete the hybrid model.

Network Delay Subsystem Contents

  • A control signal from the ABS Controller block enters the subsystem via the In1 block. The Timed to Event Signal gateway block converts the time-based signal from the controller into an event-based signal, so that the data is available to the discrete-event blocks. In any SimEvents model, the way that the software converts time-based signals to event-based signals depends on the solver you use for your simulation. In this tutorial, the model uses a variable-step solver. For more information, see Variable-Step Solvers for Discrete-Event Systems.

  • Periodically, the Time-Based Entity Generator block creates an entity that conveys the control signal value from the ABS controller to the braking system.

  • The Set Attribute block attaches the control signal value to the entity. This data-carrying entity is a data packet in the network.

  • The N-Server block models the latency in the communication system by delaying each data packet.

  • The Get Attribute block models the reconstruction of data at the receiver. This block connects to an Event to Timed Signal block that converts the data back to a time-based signal. This time-based signal connects to the Brake System Dynamics block at the top level of the model.

  • Once the time-based control signal departs the subsystem and enters the Brake System Dynamics block, the entity that carries the data through the delay susbsystem is not needed. The Entity Sink block absorbs the entity.

This subsystem models communication from the controller to the braking system, but does not model the feedback path from the braking system to the controller. The model that you create is only a first step toward modeling a true distributed control system, where all components of the system communicate over a common communication bus. Next steps might involve modeling the communication in the feedback path and replacing the N-Server block with a more realistic representation of the communication link.

Add the Network Delay Subsystem Block

To add the Network Delay subsystem block to the original time-based model:

  1. Open the abs_timebasedabs_timebased model.

  2. Select File > Save As. Save the model to your working folder as abs_hybrid.

  3. Open the Simulink and SimEvents libraries. In the MATLAB® Command Window enter simulink and simevents.

  4. From the Simulink Ports & Subsystems library, drag a Subsystem block into the model window.

  5. For the newly inserted Subsystem block, place the cursor in the text box that is beneath the block. Type the new name, Network Delay.

  6. Double-click the Delay Subsystem block. The procedure, Add the Network Delay Subsystem Contents shows you how to build the contents of the subsystem.

Add the Network Delay Subsystem Contents

In this procedure, you add event-based blocks that model a communications delay to the Network Delay subsystem block. When you complete the procedure, the contents of the Network Delay block should look as shown in the graphic.

  1. In the SimEvents library, double-click the Generators library. Double-click the Entity Generators sublibrary and drag a Time-Based Entity Generator block into the subsystem window.

  2. To review the entity generation behavior of the Time-Based Entity Generator block, double-click it. The default value of Generate entities upon is Intergeneration time from dialog, with a default intergeneration period of 1 s. Accept these default values without making any change by clicking Cancel.

  3. In the Generators library, double-click the he Signal Generators sublibrary. Drag the Event-Based Random Number block into the subsystem window.

  4. Double-click the Event-Based Random Number block. Set Distribution to Uniform, Minimum to 0.01, and Maximum to 0.06. Click OK. These settings ensure that the service time of the N-Server block varies with a uniform distribution of values between a minimum of 0.01s and a maximum of 0.06s.

  5. From the Attributes library, drag the Set Attribute and Get Attribute blocks into the subsystem window.

  6. Double-click the Set Attribute block. The Set Attribute tab of the dialog box contains a table. On the first row of the table, set Name to Value and set Value From to Signal port. Click OK. The block acquires an extra signal input port, Value.

  7. Double-click the Get Attribute block. The Get Attribute tab of the dialog box contains a table. On the first row of the table, set Name to Value. Click OK. The block acquires an extra signal output port, Value.

  8. From the Servers library, drag the N-Server block into the subsystem window.

  9. Double-click the N-Server block. Set Service time from to Signal port t. Click OK. The block acquires an extra signal input port, t.

  10. From the SimEvents Sinks library, drag an Entity Sink block into the subsystem window.

  11. From the Gateways library, drag a Timed to Event Signal block and an Event to Timed Signal block into the subsystem window.

  12. Connect and place the blocks as shown in Network Delay Subsystem Contents.

  13. Navigate to the top-level view of the model. Select View > Navigate > Up to Parent. Save the model.

Complete the Hybrid Model

Before you connect the newly created Network Delay subsystem block to complete the hybrid model, simplify the top-level view of the original ABS model by grouping related blocks. When you complete this procedure, the model looks as shown in Top-Level View of Completed Hybrid Model.

  1. To select both the Desired Relative Slip and ABS Controller blocks of the model, hold down the left mouse button and drag the mouse. As you drag the mouse, a box appears. Drag this box across a portion of both blocks. When you release the mouse button, the two blocks are highlighted in blue.

  2. Right-click one of the two highlighted blocks and select Create Subsystem from Selection. The software places both blocks inside a new Subsystem block.

  3. For the newly created Subsystem block, place the cursor in the text box that is beneath the block. type the new name, ABS Controller.

  4. To select both the Brake System Dynamics and Sensor Relative Slip blocks of the model, hold down the left mouse button and drag the mouse. As you drag the mouse, a box appears. Drag this box across a portion of both blocks. When you release the mouse button, the two blocks are highlighted in blue.

  5. Right-click one of the two highlighted blocks and select Create Subsystem from Selection. The software places both blocks inside a new Subsystem block.

  6. For the newly created Subsystem block, place the cursor in the text box that is beneath the block. type the new name, Brake System Dynamics.

  7. Connect the previously created Network Delay block between the ABS Controller and Brake System Dynamics blocks. The hybrid model is now complete.

  8. Save the model.

Lesson 4: Run the Hybrid Model

Run the completed abs_hybrid model. In the Simulink Editor, select Simulation > Run.

By comparing these plots with the plots in Lesson 1: Run the Time-Based Model, you can see that the delay introduced between the ABS controller and the braking system significantly degrades the performance of the braking system:

  • Between 6s and 8s, the measured slip increases and the wheel speed begins to lock up (decrease rapidly towards zero).

  • At about 14s, the measured slip increases again. The wheel speed locks up, falling to zero.

  • The vehicle takes almost 17s to come to rest. This value is almost 2s longer than in the original time-based model.

Change the Network Performance

One way to experiment with the simulation is to change the performance of the network and run the simulation again. Try making either of the following sets of changes. Observe the changes in results.

  • In the Event-Based Random Number block, set Maximum to 0.1. This change increases the maximum service time of the N-Server block, representing an increase in the latency of the network. Rerun the simulation. The increased latency further degrades the braking performance.

  • In the Time-Based Entity Generator block, restore the original values. Set Distribution to Uniform, Minimum to 0.01, and Maximum to 0.06. Also in the Time-Based Entity Generator block, set Intergeneration time from dialog to 0.01. The last change increases the frequency of entity generation. The increased entity generation means that the incoming control signal is sampled more regularly, increasing the fidelity of the network. Rerun the simulation. The increased network fidelity improves the braking performance.

Event-Based and Time-Based Dynamics in the Simulation

In the abs_hybrid model, the time-based dynamics of the braking system coexist with the event-based dynamics of the network delay subsystem. When you run the simulation, the solver and the event calendar both play a role. Upon major time steps of the solver, the simulation solves the ordinary differential equations that represent the dynamics of the braking system. Solving the event-based dynamics entails scheduling and processing events, such as service completion and entity generation, on the SimEvents event calendar. Because the model uses a variable-step solver, when events occur in the discrete-event system, the solver has a major time step.

To learn more about:

In this model, time-based blocks interact with event-based blocks at the input and output of the Network Delay subsystem. At each major time step of the solver, the ABS Controller block updates the value at the input port of the Network Delay subsystem. The Set Attribute block, which is event-based, uses this value upon the next entity arrival at the Set Attribute block. Such entity arrivals occur at times 0, 1, 2, and so on.

When an entity completes its service, the entity arrives at the Get Attribute block, which is event-based. This block updates the value at the output port of the subsystem. The Brake System Dynamics block, which is time-based, uses this value upon the next major time step of the solver.

Was this topic helpful?