Main Content

Communicating with LEGO MINDSTORMS EV3 Hardware

This example shows you how to tune the parameter values of and monitor the signals from an algorithm running on LEGO® MINDSTORMS® EV3 hardware.

Introduction

When you are developing algorithms, it is often necessary to determine appropriate values of critical algorithm parameters in iterative fashion. Simulink®'sExternal modefeature enables you to accelerate the process by letting you change certain parameter values while the model is running on target hardware, without stopping the model. When you change parameter values from within Simulink, the modified parameter values are communicated to the target hardware immediately. The effects of the parameters tuning activity may be monitored by viewing algorithm signals on scopes or displays in Simulink.

This example introduces the SimulinkExternal modefeature by showing you how to:

  • Configure communications between Simulink and LEGO MINDSTORMS EV3 hardware

  • Tune parameters of an algorithm from the same Simulink model that is running on the LEGO MINDSTORMS EV3 hardware

  • Use Simulink scopes to monitor results from an algorithm running on LEGO MINDSTORMS EV3 hardware

Prerequisites

We recommend completingGetting Started with LEGO MINDSTORMS EV3 Hardwareexample.

Required Hardware

You will need the following hardware:

  • LEGO MINDSTORMS EV3 Brick

  • EV3 Wi-Fi® Dongle or USB Ethernet Adaptor (Recommendation: Apple USB Ethernet Adapter)

Task 1 - Set up the Network Connection

Please refer to Task 1 and 2 inGetting Started with LEGO MINDSTORMS EV3 Hardwareexample and make a note the IP address of the EV3 brick.

任务2 -监视和优化仿真软件模型金宝app

1.Open theCommunicating with LEGO MINDSTORMS EV3 Hardwaremodel, which is preconfigured to run on LEGO MINDSTORMS EV3 hardware.

2.In theHardwaretab, click theMonitor & Tunebutton.

Task 3 - Communicate with the Model

This task shows you how to tune the parameter and monitor the execution of hardware from the model.

1.Open theScopeblock. The scope displays the value of signal from the left button on the EV3 brick. Press the left button. The scope shows the value of the signal change from 0 to 1.

2.Double-click theFrequencyblock in the model and change the value of the Constant value parameter to 600. When you clickOKorApply, the tone coming from the speaker of EV3 brick changes

Task 4 - Stop communication

1.Click the停止button in the Simulink model. This stops both the application on the EV3 brick and the simulation on your host machine.

Summary

This example showed a workflow for tuning and monitoring an algorithm running on LEGO MINDSTORMS EV3 hardware. In this example you learned:

  • How to configure and run a model in External mode on LEGO MINDSTORMS EV3 hardware.

  • How to tune an algorithm parameter and monitor algorithm execution on LEGO MINDSTORMS EV3 hardware using the External mode feature.