Contenuto principale

Monitor and Tune the Model Running on ArduPilot Autopilots

You can use Monitor and Tune (External Mode) action to tune parameters and monitor a Simulink® model running on your target hardware.

Monitor and Tune enables you to tune model parameters and evaluate the effects of different parameter values on model results in real-time. When you change parameter values in a model, the modified parameter values are communicated to the target hardware immediately. You can monitor the effects of different parameter values by viewing the output signals on Sink (Simulink) blocks or in the Simulation Data Inspector (SDI) (Simulink). This helps you find the optimal values for performance. This process is called parameter tuning.

Monitor and Tune accelerates parameter tuning. You do not have to rerun the model each time you change the parameters. You can also use Monitor and Tune to develop and validate your model using the actual data and hardware for which it is designed. This software-hardware interaction is not available by solely simulating a model.

The support package supports Monitor and Tune simulation over XCP on TCP/IP when ArduPilot® Host Target is selected as hardware board:

Communication InterfaceDescription
XCP on TCP/IP

In Universal Measurement and Calibration Protocol (XCP)-based External mode simulation over TCP/IP, you can use:

  • Dashboard (Simulink) blocks: In addition to Sources (Simulink) and Sink (Simulink) blocks, you can use Dashboard (Simulink) blocks to change parameter values and to monitor the effects of parameter tuning. The Dashboard library contains set of blocks using which you can interactively control and visualize the model.

  • Simulation Data Inspector (SDI) (Simulink): You can inspect and compare data from multiple simulations to validate model designs using SDI.

The support package supports Monitor and Tune simulation over XCP on Serial when Cube Blue H7, Cube Orange, Cube Orange +, Generic Board, Pixhawk® 4, Pixhawk 6C, or Pixhawk 6X is selected as hardware board:

Communication InterfaceDescription
XCP on Serial

In Universal Measurement and Calibration Protocol (XCP)-based External mode simulation over Serial, you can use:

  • Dashboard (Simulink) blocks: In addition to Sources (Simulink) and Sink (Simulink) blocks, you can use Dashboard (Simulink) blocks to change parameter values and to monitor the effects of parameter tuning. The Dashboard library contains set of blocks using which you can interactively control and visualize the model.

  • Simulation Data Inspector (SDI) (Simulink): You can inspect and compare data from multiple simulations to validate model designs using Simulation Data Inspector.

These sections explain:

Prepare a Simulink Model for External Mode

This section explains how to prepare a Simulink model to run in External mode.

  1. Configure the Model Configuration Parameters to set the Hardware Board as one of the supported ArduPilot hardware boards, as explained in Model Configuration Parameters.

  2. In the Model Configuration Parameters dialog box, under Hardware board settings > Target Hardware Resources, select External Mode tab.

    When ArduPilot Host Target is selected as hardware board, Communication interface is XCP on TCP/IP.

    ArduPilot Host Target selected as hardware board

    When Cube Blue H7, Cube Orange, Cube Orange +, Generic Board, Pixhawk 4, Pixhawk 6C, or Pixhawk 6X is selected as the hardware board, Communication interface is XCP on Serial.

    ArduPilot Cube Blue H7 selected as hardware board

  3. Ensure that you select the Verbose check box to view the external mode execution progress and updates in the Diagnostic Viewer or in the Command Window.

  4. Select Automatically determine host serial port for Monitor and Tune simulation parameter to set the same host serial port for External mode as the one used for serial port for firmware upload. By default, this parameter is selected. If you clear this parameter, the Host Serial port parameter becomes available, where you can explicitly define the serial port for External mode on the host computer. Automatically determine host serial port for Monitor and Tune simulation and Host Serial port parameters are available only when Cube Blue H7, Cube Orange, Cube Orange +, Generic Board, Pixhawk 4, Pixhawk 6C, or Pixhawk 6X is selected as hardware board.

  5. If the communication interface is XCP on Serial, the Set logging buffer size automatically parameter becomes available. Select this parameter to automatically set the number of bytes to preallocate for the buffer in the hardware during simulation. By default, the Set logging buffer size automatically parameter is selected. If you clear this parameter, Logging buffer size (in bytes) parameter becomes available, where you can manually specify the memory buffer size for XCP-based External mode simulation. Set logging buffer size automatically and Logging buffer size (in bytes) parameters are available only when Cube Blue H7, Cube Orange, Cube Orange +, Generic Board, Pixhawk 4, Pixhawk 6C, or Pixhawk 6X is selected as hardware board.

  6. By default, the ArduPilot board serial port is USB (serial 0) and this cannot be modified. This parameter is available only when Cube Blue H7, Cube Orange, Cube Orange +, Generic Board, Pixhawk 4, Pixhawk 6C, or Pixhawk 6X is selected as the hardware board.

    Default serial port

  7. If the Serial port for monitor and tune simulation on hardware board is a port other than USB (Serial 0) mention the corresponding COM port on host.

    Specify serial port

    Note

    If the serial port used for Monitor and Tune communication on the hardware board is a port other than the USB port, then make sure that ArduPilot is not using that port.

  8. Click Apply and then OK to close the Model Configuration Parameters dialog box.

  9. If the communication interface is XCP on Serial or XCP on TCP/IP, you can send multiple contiguous samples in same packet to enhance signal logging performance in models containing signals of high sample rates. To do so, perform these steps.

    1. Click Hardware tab, in the Prepare gallery, select Control Panel.

      Open Control Panel

    2. In the External Mode Control Panel screen click Signal & Triggering.

      Control Panel

    3. In the External & Signal Triggering dialog box, select Send multiple contiguous samples in same packet and enter a value for Duration.

      This enables sending multiple contiguous samples in a single packet whose length is the value specified for Duration parameter.

      Packed mode

    4. Click Apply and OK.

Running the Simulink Model for Monitor and Tune

  1. Connect the ArduPilot Autopilots hardware to your host computer.

  2. Open the Simulink model and go to Hardware tab.

  3. Set a value for the Simulation stop time parameter. The default value is 10.0 seconds. To run the model for an indefinite period, enter inf.

  4. On the Hardware tab, in the Mode section, select Run on board and then click Monitor & Tune to run the model on external mode.

    Simulink automatically:

    • Runs the model on the target hardware.

    • Runs the model on the host computer for Monitor and Tune operation.

    • Creates a real-time connection between the model on target hardware and the model on the host computer.

Signal Monitoring and Parameter Tuning of Simulink Model

This section explains how to run:

XCP-Based External Mode Simulation over TCP/IP or Serial

Before you begin, complete the Prepare a Simulink Model for External Mode section.

  1. In the Simulink model, identify the signals to be logged for monitoring during simulation. Select the identified signal, open its context menu, and click the icon corresponding to Enable Data Logging.

    For instructions on logging the signal using other methods, refer to Mark Signals for Logging (Simulink). Simulink displays a logged signal indicator Logged signal indicator for each logged signal.

  2. (Optional) Place one or more Sink (Simulink) blocks in the model, and then mark the signals connected to them also for logging. For example, connect Display (Simulink) or Scope (Simulink) blocks and mark the signals connected to them for logging.

  3. To start the simulation, on the Hardware tab, in the Mode section, select Run on board and then click Monitor & Tune.

    Monitor and Tune

    For instructions on logging the signal, see Mark Signals for Logging (Simulink).

    After several minutes, Simulink starts running the model on the hardware.

    During simulation, when new simulation data becomes available in SDI, the Simulation Data Inspector button simulation data inspector button appears highlighted.

  4. View the simulation output in Sink blocks or in SDI.

    Note

    For XCP- Based External Mode over TCP/IP or Serial, it is recommended to use Signal Data Inspector (SDI) to view and log signals.

    • Sink blocks – To view the simulation output, double-click the Sink blocks in the model.

    • SDI – To view the new simulation data, perform these steps:

      1. Click the Simulation Data Inspector button.

      2. A new simulation run appears in the Inspect pane. The Inspect pane lists all logged signals in rows, organized by simulation run. You can expand or collapse any of the runs to view the signals in a run. For more information on signal grouping, see Signal Groups (Simulink).

      We recommend you use SDI rather than using Sink blocks for the following reasons:

      • Streaming data to SDI does not store data in memory, making more efficient use of the memory available on the hardware. Sink blocks such as Scope (Simulink) stores data in buffers before sending the data to the host.

      • Using SDI, you can stream signals from top models and reference models simultaneously. Scope blocks can only log signals from a top-level model.

  5. Change the parameter values in the model. Observe the corresponding changes in the simulation output.

  6. Find the optimal parameter values by adjusting and observing the results in the Sink blocks.

  7. After you are satisfied with the results, stop the Monitor and Tune action, and save the model.

Stop Monitor and Tune

To stop the model that is running in Monitor and Tune, open the Hardware tab and click the Stop button stop button.

If the Simulation stop time parameter is set to a specific number of seconds, Monitor and Tune stops when that time elapses.

Performing Disconnect and Connect

When you perform Monitor and Tune operation, you can use the Disconnect button to temporarily stop transferring the updated parameter values to the ArduPilot Autopilot. You can click Connect again to establish communication to send the updated values to ArduPilot Autopilot.

Performing Connect Operation to Run an Unchanged Simulink Model on Hardware

In some cases, the Monitor and Tune operation needs to be performed again even though there is no change to the Simulink model that was running on the ArduPilot Autopilot hardware. The reasons include:

  • Hardware reboot of ArduPilot Autopilot while Monitor and Tune is in progress

  • Disconnection of the port on the host computer while Monitor and Tune is in progress

You can resume Monitor and Tune operation again by:

  • Restarting the hardware board.

  • If Simulink code generated for Monitor & Tune in the previous run is already flashed on hardware, click Connect in Simulink instead of clicking Monitor & Tune again to establish External mode simulation. By clicking Connect, the Simulink code for the model is not generated again, and this avoids the time taken to build the code compared to the whole Monitor and Tune process.

Monitor & Tune vs Connect: Choosing Right Option

Simulink allows you to communicate with deployed code running on your ArduPilot hardware (or SITL) for real-time signal monitoring and parameter tuning.

When using External Mode, you have two main options:

  • Monitor & Tune

    • What it does:

      Downloads your model to the hardware, starts execution, and establishes a live connection to Simulink for real-time data exchange.

    • When to use :

      • You have made changes to your model or parameters and want to deploy the updated code.

      • You want to start a fresh execution and immediately begin monitoring signals and tuning parameters.

      • You are iteratively refining your algorithm and need to test the latest changes on hardware.

    • How to use:

      • Click Monitor & Tune (or Run in External Mode) in the Hardware tab.

      • Simulink rebuilds, deploys, starts the model, and connects for real-time interaction.

  • Connect:

    • What it does:

      Connects Simulink to an already running instance of your deployed model on the hardware, without recompiling or redeploying.

    • When to use :

      • The code is already deployed and running on the hardware.

      • When no model or parameter changes have been made since the last deployment.

    • How to use:

      • Click Connect in the External Mode controls.

      • •Simulink establishes a live connection to the running model for monitoring and tuning.

When to Use Each Option

ScenarioUse Monitor & TuneUse Connect
Model/parameter changes since last deploymentYes-
First time deploying to hardwareYes-
Hardware reset, model auto-starts, no changes made-Yes
Only want to monitor/tune, code already running-Yes
Save time by avoiding redeployment-Yes