External mode enables Simulink® models on your host computer to communicate with a deployed model on your robot hardware during runtime. Use external mode to view signals or modify block mask parameters on your deployed Simulink model. Parameter tuning with external mode helps you make adjustments to your algorithms as they run on the hardware as opposed to in simulation in Simulink itself. This example shows how to use external mode with the Feedback Control of a ROS-enabled Robot example when the model is deployed to the robot hardware.
Configure the Simulink model to deploy to the robot hardware and enable external mode.
Open the model.
Set the configuration parameters of the model.
In the Simulation menu, click Model Configuration Parameters to open the Configuration Parameters dialog box.
On the Solver pane, set Type to
the Fixed-step size to
On the Hardware Implementation pane,
specify the Hardware board as
Operating System (ROS). Specify related parameters in Target
In Build Options, set the Build
Build and run. By default, Simulink always
Build and run when using external mode.
In Target Hardware Resources, set the External mode parameters. To prioritize model execution speed, enable Run external mode in a background thread.
In the model, set the Simulation mode to
In the model, add scope blocks to the signals you want to view. For this
example, add an XY Graph scope to the
Y signals that are exiting the
Bus Selector from the ROS subscriber that monitors the robot
position. Open the XY Graph block and change the minimum and
maximum values for each axis to
Now that the model is configured, you can deploy and run the model on the robot hardware.
Connect to the ROS network by setting the network address. The network must be
running on your target robotics hardware. This example uses the "Gazebo Empty"
simulator environment is used from the Virtual Machine with ROS Hydro and Gazebo example. In the
Tools menu, under Robotics Operating
System, select Configure Network Addresses.
Specify your device address by selecting
Network Address and specifying the IP address or host
name under Hostname/IP Address. For this virtual machine,
the IP address is
Run the model. The model is deployed to the robot hardware and runs after the build process is complete. This step might take some time.
After you deploy the model and the model is running, you can view its signals and modify its parameters.
While the model runs on the hardware, view the XY Graph window to monitor the robot position over time.
The path has a slight wobble, which is due to the high velocity of the robot as it tracks the path.
While the model is still running, you can also tune parameters.
Proportional Controller subsystem and
change the Linear Velocity slider to
Back in the main model, change the Desired Position constant
block to a new position,
[0 -5]. The robot drives
to the new position slower.
The lowered velocity reduces the wobble along the path. All these modifications were done while the model was deployed on the hardware.