Transcript
Hello and welcome to this short video on using Rhapsody with Simulink. In this video I will show how you can import a Simulink model into Rhapsody and use it along with the rest of your Rhapsody model to simulate your application. Here we can see the Rhapsody user interface. This particular model is for a power window in a car. Here we can see three different classes: driver, window and the windowsys class, which will represent the Simulink model. The driver and window both have behavior. We can see some various attributes and operations as well as state machines that describe both the driver and window. Essentially the driver can push the window button to go up or down. We’ll grab the position of the window from the Simulink model. Before we import the Simulink model let’s have a look, here we can see the Simulink model for the power window. As you can see it has an up and a down command and outputs a position. Let’s see how we can go ahead and import this into rhapsody. The first thing we want to do is go ahead and tell Rhapsody that the Windowsys block is a special type of block call a Simulink block. Once this is done we can import and sync the Simulink model. This gives us a dialog to choose the Simulink model file and generate source code from the real time workshop. We’ll go ahead and choose the power window model and choose the generated code. We can also choose the model sample time. How often we want to sample the output form the Simulink model. Once we are finished we’ll click the input sync button. This uses the Simulink comand line interface to grab the information from the model. As you can see the model has changed. It now shows three different ports on the windowsys block. It has two ports for inputs the up and down and now has a port for the output, which is its position. Now that we’ve synchronized with the Simulink model we can now hook it up to the reset of the model. To do this let’s take a look at a different diagram that show the objects. To link the objects together we will use UML links. The position port with go over here and the up and down ports will go on this side. Now let’s go ahead and link these together. Once these are linked we can the go ahead and have Rhapsody simulate the model and grab the outputs, not only push inputs into the Simulink model, but grab the position as well. Ok, let’s go ahead and compile our simulation. Once this is completed we’ll go ahead and execute the model. Rhapsody allows us to see the the various diagrams, such as state machines and sequence diagrams, animate as we execute the application. Ok our build is complete and we’ll go ahead and start up the simulation. In order to see what is going on here we can look at a sequence diagram. In this sequence diagram, we see the environment, the driver, the windowsys block, which represents the Simulink block, and the window. Let’s go ahead and run the simulation. We can see initially that the driver is in the neutral state. We can now go ahead and inject events into the rhapsody model such as pushing the up button on the driver side to see how the window system responds to that. Another easy way to inject events is to have rhapsody
create or crate panels yourself So rhapsody can either create automatic panels or you can create you own custom gui panels to interact with the simulation. Here we see the window and the controls of the driver as well as the position which will come from the Simulink model. Let’s see what happens when we push the up button. Ok let me pause that. Because its sampling time is so quickly, every 100 milli seconds, I’m going to go ahead pause and see what happened here. . As you can the sequence diagram is recording the simulation as I inject different signals. Here we can see where I pushed the up button on the window. That caused the drive to go into a going up state and sent a command into the Simulink model to tell it that we’re now going up. The Simulink model then does its calculations and sends the output position to the window class. This continues on until I release the up button which now put its back into a neutral state and again we can see the position calculated from the Simulink model. So not only can we look at the animation of the sequence diagram but can also take a look at the animation of the state machine. Let me close the sequence diagram. And we’ll take a look at the animation of the driver state machine. Here we can see it’s currently in the neutral state. Lets’ bring back up the gui and continue to raise the window. Every time I click the up button you can see a transition to the going up state. When I release the button it goes back to neutral. And again we can see here that the position is being gathered from the Simulink model Ok this concludes this brief demonstration on how you can import a Simulink model to be used within your rhapsody model and be able to simulate those models together. Thank you for watching this brief video.