Tune Parameters and View Signals on Deployed Robot Models Using External Mode
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.
Set Up the Simulink Model
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 Prepare section under ROS tab, click Hardware Settings to open the model configuration parameters dialog box.
On the Solver pane, set Type to
Fixed-stepand the Fixed-step size to
In Hardware Implementation > Target Hardware Resources, set the External mode parameters. To prioritize model execution speed, enable Run external mode in a background thread. Click OK.
In the model, add scope blocks to the signals you want to view. For this
example, add an Record, XY
Graph (Simulink) scope to the
signals that are exiting the Bus Selector from the ROS subscriber
that monitors the robot position. Open the Record block and
change the minimum and maximum values for each axis to
Deploy and Run the Model
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
Simulations tab select ROS Network
to configure your ROS network address. Specify your device address by selecting
Custom under Network Address and
specifying the IP address or host name under Hostname/IP
Address. For this virtual machine, the IP address is
Under ROS tab, click Monitor And Tune. The model is deployed to the robot hardware and runs after the build process is complete. This step might take some time.
Monitor Signals and Tune Parameters
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 Record, XY Graph (Simulink) 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.