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.

robotROSFeedbackControlExample

Set the configuration parameters of the model.

  1. In the Simulation menu, click Model Configuration Parameters to open the Configuration Parameters dialog box.

  2. On the Solver pane, set Type to Fixed-step and the Fixed-step size to 0.05.

  3. On the Hardware Implementation pane, specify the Hardware board as Robot Operating System (ROS). Specify related parameters in Target Hardware Resources.

  4. In Build Options, set the Build action to Build and run. By default, Simulink always uses Build and run when using external mode.

  5. In Target Hardware Resources, set the External mode parameters. To prioritize model execution speed, enable Run external mode in a background thread.

  6. In the model, set the Simulation mode to External.

In the model, add scope blocks to the signals you want to view. For this example, add an XY Graph scope to the X and 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 [-10 10].

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 Tools menu, under Robotics Operating System, select Configure Network Addresses. 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 192.168.154.131.

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.

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 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. Open the Proportional Controller subsystem and change the Linear Velocity slider to 0.25. 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.

Related Topics