Challenge

Project 1 - Wiper control system and Vehicle speed calculation for ABS using Wheel Speed sensor

/* Project 1 - Wiper control system and Vehicle speed */

1: Develop Simulink/state flow modules for wiper control system based on the given conditions.

Description of Challenge:

If the density of the rain is low, then wiper rotates with low speed, the output signal should be 100rpm.

If the density of the rain is medium, then wiper rotates with low speed, the output signal should be 200rpm.

If the density of the rain is high, then wiper rotates with low speed, the output signal should be 500rpm.

Note: Rain density input comes from the external sensor, for the simulation purpose constant block with knob can be taken.

Ans:

Creating a Simulink model for a wiper control system based on the given conditions involves using a combination of blocks to simulate the rain density input and the wiper motor output speed.

1: Open Simulink and Create a New Model :

Open MATLAB.

In the MATLAB Command Window, type Simulink to open Simulink.

Create a new model by selecting New > Blank Model.

2: Add Blocks to the Model :

a: Constant Block (for Rain Density Input) :

Go to the Library Browser.

Navigate to Simulink > Sources > Constant.

Drag the Constant block into the model. This block will simulate the rain density input. we can use a knob to vary the constant value during the simulation.

b: Switch Blocks (to Handle Different Rain Densities):

Add three Switch blocks from Simulink > Signal Routing > Switch.

These will be used to switch between different RPM values based on the rain density.

c: Comparison Blocks (to Compare Rain Density):

Add two Compare To Constant blocks from Simulink > Logic and Bit Operations > Relational Operator.

These blocks will compare the rain density against thresholds to determine the wiper speed.

d: Constant Blocks (for RPM Values):

Add three more Constant blocks from Simulink > Sources > Constant.

These blocks will hold the RPM values (100, 200, 500).

e: Output Block:

Add a Display block from Simulink > Sinks > Display to visualize the RPM value.

3: Configure the Blocks :

a: Constant Block for Rain Density:

Set the Constant value to a variable (e.g., rain_density).

b: Comparison Blocks:

For the first Compare To Constant block, set the Constant value to the threshold between low and medium rain density.

For the second Compare To Constant block, set the Constant value to the threshold between medium and high rain density.

c: RPM Constant Blocks:

Set the values of the three Constant blocks to 100, 200, and 500, respectively.

4: Connect the Blocks :

Connect the Constant block (rain_density) to the inputs of the two Compare To Constant blocks.

Connect the outputs of the Compare To Constant blocks to the control inputs of the Switch blocks.

Set up the Switch blocks to select the correct RPM value based on the rain density comparison results.

Connect the outputs of the Switch blocks to the Display block.

5: Configuration and Connections :

a: First Switch Block:

Input 1 (u2): Connect to the 100 RPM Constant block.

Input 2 (u3): Connect to the output of the second Switch block.

Control input (u1): Connect to the output of the first Compare To Constant block.

b: Second Switch Block:

Input 1 (u2): Connect to the 200 RPM Constant block.

Input 2 (u3): Connect to the 500 RPM Constant block.

Control input (u1): Connect to the output of the second Compare To Constant block.

c: Final Output:

Connect the output of the first Switch block to the Display block.

6: Model Simulation :

a: Set the Simulation Parameters:

Go to Simulation > Model Configuration Parameters.

Set the solver options and simulation time as needed.

b: Run the Simulation:

Adjust the value of the rain_density constant block using the knob or by setting it manually in the block parameters.

Run the simulation and observe the RPM value on the display.

MATLAB code to create a Simulink model :

% Create a new Simulink model

modelName = 'WiperControlSystem';

open_system(new_system(modelName));

% Add Constant block for Rain Density input

add_block('simulink/Sources/Constant', [modelName '/Rain Density'], ...

'Position', [100, 100, 140, 120], 'Value', 'rain_density');

% Add Compare To Constant blocks for threshold comparisons

add_block('simulink/Logic and Bit Operations/Relational Operator', [modelName '/Compare Low to Medium'], ...

'Position', [300, 100, 350, 120], 'Operator', '>=');

add_block('simulink/Logic and Bit Operations/Relational Operator', [modelName '/Compare Medium to High'], ...

'Position', [300, 150, 350, 170], 'Operator', '>=');

% Add Constant blocks for RPM values

add_block('simulink/Sources/Constant', [modelName '/Low RPM'], ...

'Position', [500, 50, 540, 70], 'Value', '100');

add_block('simulink/Sources/Constant', [modelName '/Medium RPM'], ...

'Position', [500, 150, 540, 170], 'Value', '200');

add_block('simulink/Sources/Constant', [modelName '/High RPM'], ...

'Position', [500, 250, 540, 270], 'Value', '500');

% Add Switch blocks for decision making

add_block('simulink/Signal Routing/Switch', [modelName '/Switch Low to Medium'], ...

'Position', [400, 100, 450, 130]);

add_block('simulink/Signal Routing/Switch', [modelName '/Switch Medium to High'], ...

'Position', [400, 200, 450, 230]);

% Add Display block for output

add_block('simulink/Sinks/Display', [modelName '/Display'], ...

'Position', [600, 150, 640, 170]);

% Configure Compare To Constant blocks

set_param([modelName '/Compare Low to Medium'], 'Constant', '1'); % Set appropriate threshold

set_param([modelName '/Compare Medium to High'], 'Constant', '2'); % Set appropriate threshold

% Connect blocks

add_line(modelName, 'Rain Density/1', 'Compare Low to Medium/1');

add_line(modelName, 'Rain Density/1', 'Compare Medium to High/1');

add_line(modelName, 'Compare Low to Medium/1', 'Switch Low to Medium/1');

add_line(modelName, 'Compare Medium to High/1', 'Switch Medium to High/1');

add_line(modelName, 'Low RPM/1', 'Switch Low to Medium/2');

add_line(modelName, 'Medium RPM/1', 'Switch Low to Medium/3');

add_line(modelName, 'Switch Low to Medium/1', 'Switch Medium to High/2');

add_line(modelName, 'High RPM/1', 'Switch Medium to High/3');

add_line(modelName, 'Switch Medium to High/1', 'Display/1');

% Save and open the model

save_system(modelName);

open_system(modelName);

Explanation :

1: Model Creation:

A new Simulink model is created and opened.

2: Blocks Addition:

Constant blocks for rain density as 0.5 and RPM values, relational operator blocks for comparing rain density, switch blocks for decision-making, and a display block for output are added to the model.

3: Block Configuration:

The comparison blocks are configured with appropriate thresholds.

4: Connections:

Lines are added to connect the blocks according to the required logic.

5: Save and Open Model:

The model is saved and opened for viewing and simulation.

2: Develop Simulink/state flow model for vehicle speed calculation unit inside the ABS system using given conditions.

Description of Challenge: fl, fr, rl and rr are the wheel speeds of front left, front right, rear left and rear right respectively.

Modes Vehicle speed

If all wheel speed sensors are working =(fl+fr+rl+m)/4

F1 is down =(fr+rl+11)/3

Fr is down =(fl+rl+ır)/3

R1 is down =(fr+fl+rr)/3

Rr is down =(fr+fl+rl)/3

If any two sensors are down then avg of remaining two sensors

If three sensors are down Vehicle speed =0

Ans :

To develop a Simulink model for a vehicle speed calculation unit inside an ABS system based on the given conditions, we need to set up a logic that computes the vehicle speed depending on which wheel speed sensors are operational or down.

1: Open Simulink and Create a New Model:

Open MATLAB.

In the MATLAB Command Window, type Simulink to open Simulink.

Create a new model by selecting New > Blank Model.

2: Define the Wheel Speed Inputs: Constant Blocks for Wheel Speeds:

Go to the Library Browser.

Navigate to Simulink > Sources > Constant.

Drag four Constant blocks into the model. Name them fl, fr, rl, and rr to represent the front left, front right, rear left, and rear right wheel speeds.

Set their values to simulate the wheel speeds.

3: Define Modes for Sensor Status: Constant Blocks for Sensor Status:

Add five Constant blocks to represent the status of each sensor (F1, Fr, R1, Rr) and the status of "any two sensors down".

Set their values to 1 (working) or 0 (down).

4: Mode Detection Logic: Logical Operator Blocks:

Add Logical Operator blocks (AND, OR) from Simulink > Logic and Bit Operations to implement the conditions based on sensor statuses.

All Sensors Working: Connect the four sensor status constants (F1, Fr, R1, Rr) to an AND block.

Any Two Sensors Down: Use OR blocks and combinations to detect if any two sensors are down.

5: Vehicle Speed Calculation: Math Function and Sum Blocks:

Sum Blocks: These blocks will add the wheel speeds based on the given formula.

Product Blocks: These blocks will divide the sum by the number of active sensors to calculate the average speed.

6: Switch Blocks for Mode Selection:

Add Switch blocks from Simulink > Signal Routing > Switch to select the correct speed calculation formula based on the active mode.

7: Output Block:

Add a Display block from Simulink > Sinks > Display to visualize the vehicle speed output.

Configuration and Connections :

1: Set Up Constant Blocks for Wheel Speeds:

Set the values of fl, fr, rl, and rr to simulate different wheel speeds.

2: Set Up Sensor Status Constants:

Define the initial sensor status values (1 for working, 0 for down).

3: Implement Mode Logic:

Use logical operators to create conditions for each mode.

For example, use AND gates to check if all sensors are working, if one or more sensors are down, and so on.

4: Compute Vehicle Speeds:

Implement the formulas for vehicle speed based on the active mode:

If all sensors are working: (fl + fr + rl + rr) / 4

If F1 is down: (fr + rl + rr) / 3

If Fr is down: (fl + rl + rr) / 3

If R1 is down: (fl + fr + rr) / 3

If Rr is down: (fl + fr + rl) / 3

If any two sensors are down: average of the remaining two sensors

If three sensors are down: vehicle speed = 0

5: Connect the Blocks:

Connect the sensor status constants to the logical operator blocks to determine the active mode.

Connect the wheel speed constants to the appropriate Sum and Product blocks to compute the vehicle speed.

Use Switch blocks to select the correct speed calculation formula based on the logical operator outputs.

MATLAB Code to Create the Simulink Model :

% Create a new Simulink model

modelName = 'VehicleSpeedABS';

open_system(new_system(modelName));

% Add Constant blocks for wheel speeds

add_block('simulink/Sources/Constant', [modelName '/fl'], 'Position', [100, 100, 140, 120], 'Value', '0');

add_block('simulink/Sources/Constant', [modelName '/fr'], 'Position', [100, 150, 140, 170], 'Value', '0');

add_block('simulink/Sources/Constant', [modelName '/rl'], 'Position', [100, 200, 140, 220], 'Value', '0');

add_block('simulink/Sources/Constant', [modelName '/rr'], 'Position', [100, 250, 140, 270], 'Value', '0');

% Add Constant blocks for sensor statuses

add_block('simulink/Sources/Constant', [modelName '/F1'], 'Position', [300, 100, 340, 120], 'Value', '1');

add_block('simulink/Sources/Constant', [modelName '/Fr'], 'Position', [300, 150, 340, 170], 'Value', '1');

add_block('simulink/Sources/Constant', [modelName '/R1'], 'Position', [300, 200, 340, 220], 'Value', '1');

add_block('simulink/Sources/Constant', [modelName '/Rr'], 'Position', [300, 250, 340, 270], 'Value', '1');

add_block('simulink/Sources/Constant', [modelName '/any_two_sensors_down'], 'Position', [300, 300, 340, 320], 'Value', '0');

% Add logical operators for mode detection

add_block('simulink/Logic and Bit Operations/AND', [modelName '/All Sensors Working'], 'Position', [450, 100, 480, 120]);

add_block('simulink/Logic and Bit Operations/OR', [modelName '/Any Two Sensors Down'], 'Position', [450, 300, 480, 320]);

% Add Sum blocks for speed calculations

add_block('simulink/Math Operations/Add', [modelName '/Sum1'], 'Position', [600, 100, 630, 120]);

add_block('simulink/Math Operations/Add', [modelName '/Sum2'], 'Position', [600, 150, 630, 170]);

add_block('simulink/Math Operations/Add', [modelName '/Sum3'], 'Position', [600, 200, 630, 220]);

add_block('simulink/Math Operations/Add', [modelName '/Sum4'], 'Position', [600, 250, 630, 270]);

add_block('simulink/Math Operations/Add', [modelName '/Sum5'], 'Position', [600, 300, 630, 320]);

% Add Product blocks for division

add_block('simulink/Math Operations/Product', [modelName '/Product1'], 'Position', [700, 100, 730, 120]);

add_block('simulink/Math Operations/Product', [modelName '/Product2'], 'Position', [700, 150, 730, 170]);

add_block('simulink/Math Operations/Product', [modelName '/Product3'], 'Position', [700, 200, 730, 220]);

add_block('simulink/Math Operations/Product', [modelName '/Product4'], 'Position', [700, 250, 730, 270]);

add_block('simulink/Math Operations/Product', [modelName '/Product5'], 'Position', [700, 300, 730, 320]);

% Add Switch blocks for mode selection

add_block('simulink/Signal Routing/Switch', [modelName '/Switch1'], 'Position', [800, 100, 830, 130]);

add_block('simulink/Signal Routing/Switch', [modelName '/Switch2'], 'Position', [800, 150, 830, 180]);

add_block('simulink/Signal Routing/Switch', [modelName '/Switch3'], 'Position', [800, 200, 830, 230]);

add_block('simulink/Signal Routing/Switch', [modelName '/Switch4'], 'Position', [800, 250, 830, 280]);

add_block('simulink/Signal Routing/Switch', [modelName '/Switch5'], 'Position', [800, 300, 830, 330]);

% Add Display block for output

add_block('simulink/Sinks/Display', [modelName '/Display'], 'Position', [900, 200, 940, 220]);

% Connect sensor statuses to logical operators

add_line(modelName, 'F1/1', 'All Sensors Working/1');

add_line(modelName, 'Fr/1', 'All Sensors Working/2');

add_line(modelName, 'R1/1', 'All Sensors Working/3');

add_line(modelName, 'Rr/1', 'All Sensors Working/4');

% Connect wheel speeds to Sum blocks

add_line(modelName, 'fl/1', 'Sum1/1');

add_line(modelName, 'fr/1', 'Sum1/2');

add_line(modelName, 'rl/1', 'Sum1/3');

add_line(modelName, 'rr/1', 'Sum1/4');

add_line(modelName, 'fr/1', 'Sum2/1');

add_line(modelName, 'rl/1', 'Sum2/2');

add_line(modelName, 'rr/1', 'Sum2/3');

add_line(modelName, 'fl/1', 'Sum3/1');

add_line(modelName, 'rl/1', 'Sum3/2');

add_line(modelName, 'rr/1', 'Sum3/3');

add_line(modelName, 'fr/1', 'Sum4/1');

add_line(modelName, 'fl/1', 'Sum4/2');

add_line(modelName, 'rr/1', 'Sum4/3');

add_line(modelName, 'fr/1', 'Sum5/1');

add_line(modelName, 'fl/1', 'Sum5/2');

add_line(modelName, 'rl/1', 'Sum5/3');

% Connect Sum blocks to Product blocks for division

add_line(modelName, 'Sum1/1', 'Product1/1');

add_line(modelName, 'Sum2/1', 'Product2/1');

add_line(modelName, 'Sum3/1', 'Product3/1');

add_line(modelName, 'Sum4/1', 'Product4/1');

add_line(modelName, 'Sum5/1', 'Product5/1');

% Set division values

set_param([modelName '/Product1'], 'Inputs', '*/4');

set_param([modelName '/Product2'], 'Inputs', '*/3');

set_param([modelName '/Product3'], 'Inputs', '*/3');

set_param([modelName '/Product4'], 'Inputs', '*/3');

set_param([modelName '/Product5'], 'Inputs', '*/3');

% Connect logical operators to Switch blocks

add_line(modelName, 'All Sensors Working/1', 'Switch1/1');

add_line(modelName, 'All Sensors Working/1', 'Switch2/1');

add_line(modelName, 'All Sensors Working/1', 'Switch3/1');

add_line(modelName, 'All Sensors Working/1', 'Switch4/1');

add_line(modelName, 'All Sensors Working/1', 'Switch5/1');

add_line(modelName, 'Any Two Sensors Down/1', 'Switch1/2');

add_line(modelName, 'Any Two Sensors Down/1', 'Switch2/2');

add_line(modelName, 'Any Two Sensors Down/1', 'Switch3/2');

add_line(modelName, 'Any Two Sensors Down/1', 'Switch4/2');

add_line(modelName, 'Any Two Sensors Down/1', 'Switch5/2');

% Connect Product blocks to Switch blocks

add_line(modelName, 'Product1/1', 'Switch1/3');

add_line(modelName, 'Product2/1', 'Switch2/3');

add_line(modelName, 'Product3/1', 'Switch3/3');

add_line(modelName, 'Product4/1', 'Switch4/3');

add_line(modelName, 'Product5/1', 'Switch5/3');

% Connect Switch blocks to Display

add_line(modelName, 'Switch1/1', 'Display/1');

% Save and open the model

save_system(modelName);

open_system(modelName);

Explanation :

1: Define and Initialize Constants:

Four constants for wheel speeds (fl, fr, rl, rr) and five constants for sensor statuses.

2: Logical Operators:

To check different combinations of sensor statuses.

3: Sum and Product Blocks:

To compute average speeds for different scenarios.

4: Switch Blocks:

To choose the correct speed calculation based on sensor statuses.

5: Connections:

Connecting inputs, logical operators, sum and product blocks, and switches to produce the correct output.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.