To simulate the mobile robot logical architecture, link Simulink® models to the components. These linked models act as Simulink behaviors and can be simulated in System Composer™ by selecting Run. To access the models and supporting files used in this example, see Simulate Mobile Robot with System Composer Workflow.
The initial logical architecture model describes the behavior of the mobile robot system — trajectory generator, trajectory follower, motor controller, and robot and environment — for simulation. The connections represent the interactions in the system. To open the initial logical architecture model, double-click the file or enter this command in the MATLAB® Command Window.
% Open the initial logical architecture model for the mobile robot systemcomposer.openModel('scMobileRobotLogicalArchitectureInitial');
The structure of the logical architecture is similar to that of a Simulink model because simulation models are designed based on the flow of information. The components of the logical architecture model are linked to behavior models so that the architecture model can be simulated.
Each component is responsible for one or more functions defined in the functional
architecture model. The
Trajectory Follower component is responsible for
calculating the wheel speed of the robot based on the path the generator created. The
Motor Controller component controls the speed of each
actuator motor according to the output from the
Note that some components are omitted from this example model. For example, sensor
Lidar Sensor and
RGB Camera are not
required in this model because the true value from simulation gets the
x-y position and orientation of the robot. For more complex
simulations, you can add sensor models like
RGB Camera to test different
algorithms, such as object recognition. If you were to add such a sensor model,
Lidar Sensor, another behavior component, would be required to decipher
the sensor data in the
Scan Matching Algorithm component.
Simulate the logical architecture model by adding Simulink behavior to a
Sensor Algorithm component.
Sensor Algorithm component. Add two input ports on the
right side called
Sensor Reading 1 and
2. Add two output ports on the left side called
x-y position and
q for quaternion.
To create a new Simulink behavior, right-click the
Sensor Algorithm component
Create Simulink Behavior. From the
Type list, select
Choose a new model name. In this example, it is
Click OK. The new Simulink model is saved in the current folder. The component is converted to a reference component.
To edit the behavioral model, double-click the
component. Observe that bus element ports are created during the conversion process.
For more information on setting bus ports, see Explore Simulink Bus Capabilities.
Any port block can be used to connect different components. Convert the
Sensor Reading 2 bus port and the
q bus port
Outport blocks by
deleting them and recreating them as
Sensor Reading 1 bus port to view its
properties, then pause on the name
Sensor Reading 1 and click the
pencil icon to open Attributes. Set the
Sensor Reading 2 port to open Block
Parameters, then switch to the Signal Attributes
tab. Set the
Sensor Reading 2 port Port
Return to the logical architecture and connect the components. The result should
scMobileRobotLogicalArchitecture.slx in the next
The logical architecture model describes the behavior of the mobile robot system — trajectory generator, trajectory follower, motor controller, sensor algorithm, and robot and environment — for simulation. The connections represent the interactions in the system. To open the logical architecture model, double-click the file or enter this command in the MATLAB Command Window.
% Open the logical architecture model for the mobile robot systemcomposer.openModel('scMobileRobotLogicalArchitecture');
A behavior algorithm is created based on port information only. When designing a logical architecture, you can set the interface of the port to define the information in more detail. For example, if you know that 800 x 600 RGB images captured at 24 frames per second are transferred from the camera sensor, then you can set the corresponding port interfaces accordingly to ensure efficient data transfer. For more information about setting interfaces, see Define Port Interfaces Between Components.
Once behavior models are linked, you can simulate the architecture model just like any
other Simulink model by clicking Run. Simulation verifies requirements
Collision Avoidance, and
The scope from the
MotorController component behavior shows how well
a simple P-gain controller performs to follow the reference velocity for one of the wheels
on the robot.
Run this script to observe how well the robot follows the waypoints.
out = sim('scMobileRobotLogicalArchitecture.slx'); % waypoints are manually defined in Constant block waypoints = eval(get_param('TrajectoryGenerator/Manual Waypoints','Value')); figure hold on plot(out.pose.Data(:,1),out.pose.Data(:,2)) plot(waypoints(:,1),waypoints(:,2)) hold off xlabel('X Position (m)') ylabel('Y Position (m)') legend('Actual Trajectory','Commanded Trajectory')