Create an Architecture Model

In this example, create an architecture model of a mobile robot that consists of sensors, motion, and a planning algorithm. Define the interfaces and link the requirements.

Visually Represent the System

Capture the construction of a robot arm using System Composer™. The robot arm consists of these components.

Create Architecture Model

  1. In the MATLAB® Command Window, type


    The Simulink Start Page opens to System Composer.

  2. Click Architecture Model.

    A Simulink Editor window opens with a new architecture model. You can identify an architecture model by the badge on the lower left corner and the component palette on the left side.

  3. On the upper-left of the architecture model, double-click untitled and name it Robot. The name of the model reflects the name of the architecture model.

  4. Save the model.

Draw Components

  1. Click and drag a Component from the left-side palette.

  2. Rename the component to Sensors.

  3. Continue with adding Motion and Trajectory Planning components.

Create Ports and Connections

You can add a port to a component on any side and in any direction. To create a port, pause the mouse cursor over a component side , Click-and-release the mouse button to view direction options. Select either the input or outport direction arrow. Rename the port using a proper MATLAB variable name.

  1. Create an output port on the bottom side of the Sensors component. Rename it SensorData.

  2. Click and drag a line from the SensorData output port to the Motion component. When you see an input port created at the component side, release the mouse button. By default, this new port has the same name as the source port.

  3. Hover over the corner of the SensorData line until you see the branch icon.. Right-click and drag a branch line to the Trajectory Planning component.

  4. Complete connections as shown in the following figure.

The architecture model can also have ports. In this example, the target position for the robot is provided by a computer external to the robot architecture. Represent this relationship with an input port.

  1. Click the left edge of the architecture model and type the port name TargetPosition.

  2. Connect an architecture port to a component by dragging a line from the TargetPositon input port to the Trajectory Planning component. Connections to or from an architecture port appear as tags.

Edit Interfaces

Specify the data flow between components by structuring the data interface with data types, units, dimensions, and so on. An interface can be as simple as sending an integer value, but it can also be a set of numbers, an enumeration, a combination of numbers and strings, or a bundle of other predefined interfaces.

Consider the interface between the Sensors and the Motion components. The sensor data consists of:

  • Position data from two motors

  • Obstacle proximity data from two sensors

  • A time stamp it adds to this data set

The data has these specifications.

NameData TypeUnit
position1 for motor 1doubledegrees
position2 for motor 2doubledegrees
distance1 for sensor 1doublemeters
direction1 for sensor 1doubledegrees
distance2 for sensor 2doublemeters
direction2 sensor 2doubledegrees
  1. On the Modeling tab and from the Design section, select Interface Editor . The interface Editor opens in the right-side pane under the Property Inspector.

  2. Click the Add an interface button and name the interface sensordata.

    The interface is named and defined separately from a component port and then assigned to a port.

  3. In the model and on the Sensors component, click the SensorData output port. In the Interface Editor, right-click sensordata, and then select Assign to Selected Port(s).

    The three SensorData ports are highlighted, indicating the ports are associated with the interface sensordata.

  4. Add an element to the selected interface. Click the add element button and type timestamp.

  5. Continue adding elements to the interface by clicking the add element button .

  6. Edit the properties of an interface element using the Property Inspector. Right-click an any element and select Inspect Properties. The Property Inspector opens above the Interfaces editor.

    Click each interface element and add units as shown in the specification. Click the drop-down next to the button to save the interface to a data dictionary. Here it is saved as MotionControl.

Decompose Components

Each component can have an architecture of its own. Double-click a component to decompose it into its subcomponents.

  1. Double-click the Trajectory Planning component. The title or Model Browser indicates the position of the component in the model hierarchy.

    This component first uses the motor position data that is part of the sensordata interface to compute the ideal position and velocity command. It then processes the obstacle distance information in the same interface to condition this motion command, according to some safety rules.

  2. Add Motion Control and Safety Rules components as part of the Trajectory Planning architecture.

    Drag a TargetPosition port to the Motion Control component. Add a Command output port to Motion Control, and then drag a line to the Safety Rules component. Drag lines from SensorData port to Motion Control and Safety Rules components.

Implement Component Behavior

If you have a Component block that represents a single functional unit that does not need further architectural decomposition, you can define its behavior in Simulink®.

  1. Right-click the Motion Control block and select Create Simulink Behavior.

  2. Type the name for a new Simulink model and click OK.

    This creates a new Simulink model in the current directory, converts the Component block to a Reference Component block, and indicates a link by adding a Simulink icon with the name of the referenced model to the block title. The Simulink behavior model reflects the ports from the component in the architecture model and allows you to define the behavior in Simulink.

  3. Double-click Motion Control block to open the Simulink Editor window.

  4. Add a Sum block to subtract SensorData from TargetPosition, and add a Gain block before connecting to the output Command.

Link to an Existing Simulink Behavior Model

You can link to an existing Simulink behavior model from a System Composer component.

  1. Right-click the component and select Link to Model.

  2. Enter the name of a Simulink model.

Any subcomponents and ports that are present in the component are deleted when the component links to a Simulink model.

Related Topics