Sonja Krzok, MathWorks
Learn how you can quickly iterate and optimize your design by taking your control algorithm developed in Simulink® and deploying it to a Speedgoat target computer configured as a prototype controller. You can connect the prototype controller to physical systems to iterate your control algorithm design to find issues earlier. Explore design trade-offs and verify system architecture before beginning implementation.
Hello, my name is Sonja Krzok, and I'm an application engineer at MathWorks specialized on real-time simulation and testing, what will also be the topic of this presentation. Simulink Real-Time lets you create real-time applications from Simulink models and run them on Speedgoat target computer hardware. It is designed for real-time simulation and testing tasks, including rapid control prototyping and hardware-in-the-loop simulation.
With Simulink Real-Time, you can extend your Simulink models with Speedgoat I/O driver blocks, automatically build real-time applications, create your own instrumentation panels, and perform interactive automated runs on a Speedgoat target computer equipped with a real-time kernel, multicore CPU, I/O and protocol interfaces, and also FPGAs. Simulink Real-Time and Speedgoat target computer hardware are expressly designed to work together to create real-time systems for desktop, lab, and field environments. This is also the only software and hardware solution that supports the latest versions of MATLAB and C modeling.
Starting with the traditional V development cycle, beginning with system requirements to system integration, we have highlighted the two main applications for real-time simulation and testing in blue. In this presentation, I'm going to talk about rapid control prototyping and show you how to get from modeling to real-time prototyping with Speedgoat hardware, and also how you can create your own graphical user interface, which can also be used with a real-time target machine, and to highlight what you have to do to run the system royalty free without any MATLAB and Simulink licenses. My colleague, Pablo Romero, who also works in this area together with me, will show you in another presentation the workflow for hardware-in-the-loop testing and how you can automate your testing within the Simulink environment. I can only recommend you to watch this video as well.
For rapid control prototyping, we're going to model the controller and the plant in Simulink and reuse the model for real-time testing. Therefore, we're going to replace the plant model with the I/O inputs and outputs from the Speedgoat driver library to interface the physical system. And the controller will run in real time on the Speedgoat target hardware, so you can test your controller in an early development stage already in real-time with the physical system.
In this demo, we're going to have a look at an electrical DC motor and its controller, which will run in real-time on the Speedgoat. The hardware set up I'm working with is the following-- I have one development computer where MATLAB Simulink is running, and I'm connected with an ethernet to the Speedgoat baseline, which is the entry machine from Speedgoat. With the interfaces, I communicate with my physical system, the DC motor in our example.
I'm working with Simulink Project, so it's easy to manage and cheer, find, and set things, but also to interact directly with the source control system. For example, you can directly commit your changes from Simulink Project, and push it to the repository. But it's also good to collaborate with your colleagues on files you have used, for example, by creating project shortcuts. Simulink allows you to simulate plant and controller in one environment, so it can study the closed loop behavior and reuse the model for real-time testing. We start with modeling the DC motor.
Modeling a plant allows you to design an appropriate control system for it. Therefore, we have different possibilities how to implement starting with the variant of a Simulink model. Therefore, you have to first derive the equations, and then build the differential equation with the help of Simulink blocks. Another possibility is using Simscape.
Simscape enables you to rapidly create models of physical systems within the Simulink environment. You model the electric motor by assembling fundamental components into a schematic, which can be much easier and faster than deriving the equations, especially when the system gets more complex. In our example, we can select the DC motor directly from the Simscape library and just adapt to the parameters to our needs.
If you run the simulation of the motor model, and the outputs don't match up well with the real motor, you can calibrate the DC motor with the help of the Parameter Estimation app. It allows you to input and process input output test data, such as voltage input and rotor speed output of your DC motor and to specify which model parameters to estimate. You then perform the estimation and compare and validate the estimation results.
In the next step, we have to design the controller. In our case, we're using a PID controller, which you also select directly from the Simulink library and adapt according to your parameters. We have saved our parameters in a data dictionary, which is linked directly to our model.
To run the simulation, we have created this dashboard test [? band ?] to vary the inputs in order to trace the signal on the dashboard scope during simulation. Our closed loop model is implemented as a reference model. With this going, I can easily switch to the variant I want to use for the simulation. I'm selecting Simscape, and for data logging, we're using STI.
So I can directly click on Run and start the simulation, and in the scope block, you see our position come on-- in that case, the square wave and the actual position. During simulation, I can now change our position command, for example, to a sawtooth or to a sine wave. But I also can activate the switch during simulation and change the position command menu with the slider.
When I stop the simulation, you see that our simulation results are available in Data Inspector. So we have our run and all the segments we are logging, so I'm selecting actual position and position for position command. And I can use the tools from Simulation Data Inspector to have a closer look-- for example, zoom in in time and use cursor to see the actual values.
So now, we have tested the control algorithm on the desktop computer, and it seems to work well. Now, we want to check how the controller behaves with the external DC motor. Therefore, I am selecting the variant Speedgoat, and we can have a look at our closed loop model and see that, now, the Speedgoat I/O variant is active, and our plant model is now replaced by the I/O driver blocks from the Speedgoat library. So in our case, the voltage is sent by a PWM generation block, and the actual position is read in by this analog input.
For the PWM generation, you find all the settings here and the steps, and you can change, for example, the PWM pattern. So in our case, we're using this metric one. And also the channel settings for the B channel, so in our case, it's independent of our A channel output.
If we click on Help, you see that the documentation of the Speedgoat library is integrated in the model of Simulink documentation, and there you find all the information, how to set up your I/O driver blocks. You also find really helpful usage notes so you know how to use, for example, the PWM blocks, and on the other side are inputs. So we have to select the channel how to read in our actual position, but you could also change here the analog input range. And the Speedgoat library blocks, you find directly in your library. So on the one hand, you have the Simulink Real-Time, and here, the Speedgoat library with all the available I/O modules.
Going back to our dashboard test bench, you see that we can use the same model with the variant Speedgoat, and for the real-time simulation, we switch to the Real-Time tab. And I highlight some hardware settings you have to keep in mind when you want to execute your model in real-time, so one thing you have to keep in mind that you use a fixed-step solver. And the other setting you have to make is to select Simulink Real-Time system target file. You can use the same model now for Real-Time execution, clicking only on this one button, Run On Target.
By clicking Run On Target-- you can also open the diagnostic here-- you start the process so that we generate from our Simulink model in our C code, which has to be compiled and then transferred through a Speedgoat target machine. But for that, we also stay in the same environment. So this process will take a few moments, but then we're using Simulink as user interface and can still interact with our model during simulation.
So we see the build process was successfully. We can close that window. We have created the real-time application, which is now transferred, and maybe as you also can hear, the DC motor is now moving.
The application is running, and also for the real-time simulation, I can interact now directly with our models and change the input here. So selecting, for example, the square wave. Switching to the sawtooth, or to the fast sine wave. And should also hear how our DC motor is moving now. Also to change to manual is possible, changing the position command with the slider again.
Good. So if I stop application, you see our data's again available in Data Inspector, which is freely available in Simulink. So you don't have to change any settings for data logging. You can have a look at the simulation results, and you see from our logging settings from before, it remembered our settings and already selected extra position and position command.
So this is our actual run, but we can compare to runs we have executed before just by selecting, from our recent runs, the same signals. So it's really easy now to compare your results, and again can also use the same tools. Zoom in in time, and work with cursors. Good. So this was using Simulink in external mode with dashboard blocks, but you can also use App Design and create your own user interfaces.
App Design is included in MATLAB, and you can use it for your desktop simulation, but also for your Real-Time application. To create your GUI, you can select from different components and create a design for you. In our case, we're using different buttons. We have knobs to change, for example, the position command, but also for visualisation, you can use different scopes.
After creating your designs here, you want to add the functionality. So in our case, adding a callback to set the parameter of the position command. So as you can see here, everything what is in gray is added automatically by your design view, and for example, for the position command note value, we have the function setParam to change the value for the position command. Similar to different other buttons, you always can change the functionality here.
When your graphical user interface is finished, you can click on Run, and this is how your user interface can look like. You can also resize it, and it adapts automatically. And from that GUI, you can also now click on Open Model. We're using-- and also execute the commands like connect the target, build the model, download the application, start the application.
So I click on Build button, and we see, in the background, what you've seen before in the diagnostic view, now we see it in the command window, the progress of the build process. Again, we have to generate code from our application. Now, compile it, link it, and then the next step, after we have our Real-Time application, we can then download it to the Speedgoat target machine.
This can take now a few seconds. Going back to our GUI-- so as soon as the application is available, you will see that the buttons for the next action are activated again. So these are things you can implement also in your graphical user interface. So we're waiting for the application, and those user interfaces are really good if you want to give it to maybe a colleague who is not that experienced in MATLAB Simulink and only wants to test the model and your system.
Now, the application build was successful. We have our ml.x file, so I can download the application now to our Speedgoat target machine. And again, we also see the status of our target. The deprecation is loaded now, and it can execute the command start application. And as you can hear, our DC motor is moving again.
Now we have a sine wave as input, or we can activate also the manual position command and change it with this knob. You're seeing the results for our reference position and actual position in the scopes. And we can also control parameters from our controller directly from the graphical user interface and get additional information, like sample time, stop time, and simulation time. So stopping the application from our user interface, now, you can also open directly Simulation Data Inspector, and you will get the possibility to have now a look, again, at our recent results.
Another highlight from the App Designer is that you can share that app now and create a standalone desktop app. So you see, therefore you need the MATLAB compiler once to create that standalone application. This is done within a few clicks, and we can change the name on this graphical user interface. And you see that you can create then an executable which will run on any PC without any MATLAB Simulink license.
So the only thing you have to do, you have to also install a runtime, MATLAB runtime, on that PC. But as you see, you can already edit to that download package, or you can download it from the web. So this is-- the option's up to you. By clicking on Package, you have then this graphical user interface and can work independent from any MATLAB and Simulink license, but maybe also to mention this MATLAB runtime is also available for free.
This presentation gave you an overview about rapid control prototyping with Speedgoat hardware. If you want to know more in detail how to set up Simulink project, physical modeling with Simscape script, how to calibrate your model and design your controller, or how to integrate real-time simulation in your validation and verification workflow, please don't hesitate to contact us. If you're interested in hardware-in-the-loop simulation and testing, I highly recommend to watch part two with my colleague, Pablo Romero. Thank you very much, and have a nice.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .Select web site
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.