Communicating with LEGO MINDSTORMS EV3 Hardware Using XCP-Based Simulation
This example shows how to tune the parameters and monitor the signals of an algorithm running on the LEGO® MINDSTORMS® EV3 hardware using XCP-based simulation.
The provided model is preconfigured for LEGO MINDSTORMS EV3 and can be run on any of the boards listed in the Supported Hardware section. To select a hardware board, follow the steps in the Configuring the Model for the Legomindstormsev3 Board section.
Simulink® Support Package for LEGO MINDSTORMS EV3 Hardware enables you to monitor and tune algorithms running on Legomindstormsev3 hardware from the same Simulink models from which you developed the algorithms.
In this example, you will learn how to tune and monitor the algorithm in real time. When you are developing algorithms, it is often necessary to determine appropriate values of critical algorithm parameters in an iterative fashion. For example, a surveillance algorithm that measures motion energy in a room may use a threshold to detect an intruder in the presence of ambient noise. If the threshold value is set too low, the algorithm may erroneously interpret any movement as an intruder. If the threshold value is set too high, the algorithm may not be able to detect any movement at all. In such cases, you can try different threshold values until the desired algorithm performance is reached. This iterative process is called parameter tuning.
The Simulink External mode feature enables you to accelerate the process of parameter tuning by letting you change certain parameter values while the model is running on the target hardware, without stopping the simulation. When you change the parameter values from within Simulink, the modified parameter values are communicated to the target hardware immediately. The effects of the parameter tuning activity can be monitored by viewing algorithm signals on scopes or displays in Simulink.
Simulink provides these additional features for the targets that support XCP:
Before you start with this example, we recommend you complete Set Up the EV3 Hardware.
LEGO MINDSTORMS EV3
The following figure shows the example model.
Configuring the Model for the LEGO MINDSTORMS EV3 Hardware
Open the ev3_xcp_externalmode model.
Click Hardware Implementation and then select LEGO MINDSTORMS EV3 from the Hardware board parameter list. Do not change any other settings.
This example model has one signal selected for logging. To select additional signals, right-click the required signal and select the Log Selected Signals option.
Signal Monitoring and Parameter Tuning
1. In the model, click Hardware tab and then click Monitor & Tune.
At this point, your model is running on the LEGO MINDSTORMS EV3 hardware and communicating with Simulink. You can select the Simulation Data Inspector button to view the logged signals, as shown.
2. You can tune the parameters and visualize the signals selected for logging by:
Double-clicking the Manual Switch block to change the input source.
Using the Slider to change the signal gain.
Double-clicking the Scope block to view the External mode simulation results.
The model runs in real-time on the target while performing these actions.