This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Design a System in Simulink

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.

'help', 'toolbox', 'simulink', 'examples', 'system_model'))

This tutorial analyzes this system and adds functionality to it.

Identify Designed Components and Design Goals

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.

Analyze System Behavior Using Simulation

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:

  1. In the model, double-click the Inputs subsystem.

  2. Delete the existing input and add a Pulse Generator block with the default Amplitude parameter.

  3. Set parameters for the Pulse Generator block:

    • Period: 20

    • Pulse Width: 15

    These parameters are designed to ensure that the top speed is reached. You can change parameters to see their effect.

  4. Run the model for 20 sec.

The first scope shows that the speed rapidly starts decreasing when the power is cut at time 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,

  1. Zoom on the stable region of the velocity output in time, from 1 s to 3 s.

  2. Leave zoom mode by clicking the zoom button again. Click Cursor Measurements button .

  3. 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.

Design Components and Verify Design

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.

Add Designed Component

Build the sensor:

  1. Create a subsystem with the ports as shown.

  2. 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 ports.

  3. Model sampling. Add a Zero-Order Hold block from the Discrete library to the subsystem and set its Sample Time parameter to 0.25.

  4. Model the alert logic. Use the Compare to Constant from Math Operations and set its parameters:

    • Operator: <=

    • Constant Value: 0.21

    This logical block sets its output to 1 when its input is less than 0.21.

Verify Design

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.

  1. Set the obstacle location: Add two Constant blocks from the Sources library set the constant values to 0.65 and 0. Connect the position outputs of the robot to the inputs of the sensor.

  2. Add a scope to the Alert output.

  3. 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 is satisfied.

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.

Related Topics