Model-Based Design paradigm is centered around models of physical components and systems as a basis for design, testing, and implementation activities. This tutorial adds a designed component to an existing system model.
The model is a flat robot that can move or rotate with the help of two wheels, similar to a home vacuuming robot. Open the model by entering the code at the MATLAB® command line.
open_system(fullfile(matlabroot,... 'help', 'toolbox', 'simulink', 'examples', 'system_model'))
This tutorial analyzes this system and adds functionality to it.
Proper specification of the objective is a critical first step to the design task. Even with a simple systems, there could be multiple, and even competing design goals. Consider these for the example model:
Design a controller that varies the force input so that the wheels turn at a desired speed.
Design inputs that make the device move in a predetermined path.
Design a sensor and a controller so that the device follows a line.
Design a planning algorithm so that the device reaches a certain point using the shortest path possible while avoiding obstacles.
Design a sensor and an algorithm so that the device moves over a certain area while avoiding obstacles.
This tutorial designs an alert system. You determine the parameters for a sensor that measures the distance from an obstacle. A perfect sensor measures the distance from an obstacle accurately, an alert system samples those measurements at fixed intervals so that the output is always within 0.05 m of the measurement, and generates an alert in time for the robot to come to a stop.
The design of the new component requires analyzing linear motion to determine:
How far the robot can travel at the top speed if power to the wheels is cut
The robot's top speed
Run the model with a force input that starts motion, waits until the robot reaches a steady velocity, and then sets the force to zero:
In the model, double-click the Inputs subsystem.
Delete the existing input and add a Pulse Generator block with the default Amplitude parameter.
Set parameters for the Pulse Generator block:
These parameters are designed to ensure that the top speed is reached. You can change parameters to see their effect.
Run the model for 20 sec.
The first scope shows that the speed rapidly starts decreasing when the power is cut
3, and then asymptotically approaches zero but does not quite
reach it. This is a limitation of modeling — the dynamics at low speeds without external
force may require a more complex representation. For the objective here, however, it is
possible to make approximations. Zoom into the position signal
At time 3, the position of the robot is at about 0.55 m, and when the simulation ends, it is less than 0.71 m. It is safe to say that the robot travels less than 0.16 m after the power is cut.
To find the top speed,
Zoom on the stable region of the velocity output in time, from 1 s to 3 s.
Leave zoom mode by clicking the zoom button again. Click Cursor Measurements button .
Set the second cursor to the region where the line is horizontal.
The Value column in Cursor Measurements indicate that the top speed of the robot is 0.183 m/s. Divide 0.05 by this speed to obtain the time it takes the robot to travel 0.05 m — 0.27 s.
Sensor design consists of these components:
Measurement of the distance between the robot and the obstacle — This example assumes that the measurement is perfect.
The interval at which the sensor system measures the distance: To keep the measurement error below 0.05 m, this interval should be less than 0.27 sec. Use 0.25 sec.
The distance at which the sensor produces an alert — Analysis shows that slow down must start at 0.16 m, but the actual alert distance must also take the measurement error, 0.05, into account.
Build the sensor:
Create a subsystem with the ports as shown.
Construct the distance measurement. In the sensor model block, use
Subtract, Math Function with
magnitude^2 function, Sum, and
Sqrt blocks as shown. Note the reordering of the input
Model sampling. Add a Zero-Order Hold block from the
Discrete library to the subsystem and set its Sample
Time parameter to
Model the alert logic. Use the Compare to Constant from Math Operations and set its parameters:
This logical block sets its output to
when its input is less than
Test the design with an obstacle location of X=0.65, Y=0, using Constant blocks as input. This test verifies functionality in the X direction, you can create similar tests for different paths. This model only generates an alert. It does not control the robot.
Set the obstacle location: Add two Constant blocks from the
Sources library set the constant values to
0. Connect the position outputs of the robot to the
inputs of the sensor.
Add a scope to the Alert output.
Run the model.
Observe that the alert status becomes
1 once the position is
within 0.21 m of the obstacle location and the design requirement for this component
For real-world systems with complex components and formal requirements, the Simulink® product family includes additional tools refine and automate the design process. Simulink Requirements™ provide tools to formally define requirements and link them to model components. Simulink Control Design™ can facilitate the design if you want to build a controller for this robot. Simulink Verification and Validation™ products establish a formal framework for testing components and systems.