Add App Designer App to Inverted Pendulum Model
This example shows how to stream signals to an App Designer instrument panel app from a Simulink® Real-Time™ application. The example builds the real-time application from the model slrt_ex_pendulum_100Hz
. The instrument panel contains these App Designer components:
Target selector dropdown list — To show all the available target computers.
Connect/disconnect button — To connect or disconnect the target computer chosen in the drop down window.
Load button — To load the application to the target computer.
Start/stop button — To start or stop the application on the target computer.
Stop time edit field — To display and set the stop time of the application loaded on the target computer.
Status message box — To display target computer status information.
Axes — To display an animation for the inverted pendulum and cart system.
Axes — To display signal output for responses to disrupting the pendulum.
Nudge cart button — To apply input (nudge) to the cart that hold the pendulum.
Reference position knob — To change the reference position of the pendulum and cart system.
Reference variation pattern knob — To add a variation pattern to the reference position of the pendulum and cart system.
Amplitude slider — To adjust the amplitude of the chosen reference variation pattern.
Frequency slider — To modify the frequency of the chosen reference variation pattern.
To stream signal and parameter data between the real-time application and the instrument panel app, the app uses the instrumentation object.
Create Target Object and Connect
Create a Target object for the default target computer and connect to the target computer.
In the MATLAB® Command Window, type:
tg = slrealtime; connect(tg);
Start Target Computer and Build Real-Time Application
These tasks generate the real-time application that streams data to the App Designer instrument panel app.
Open the model
slrt_ex_pendulum_100Hz
.Build the
slrt_ex_pendulum_100Hz
model.
In the MATLAB® Command Window, type:
model = 'slrt_ex_pendulum_100Hz'; open_system(model); modelSTF = getSTFName(tg); set_param(model,"SystemTargetFile",modelSTF) set_param(model, 'RTWVerbose', 'off'); evalc('slbuild(model)');
Run App Designer Instrument Panel App
The App Designer instrument panel app slrt_ex_pendulumApp
provides controls to start and interact with the real-time application slrt_ex_pendulum_100Hz
.
1. Run the app. To start the App Designer app slrt_ex_pendulumApp.mlapp
and create the handle app
, in the MATLAB Command Window, type:
app = slrt_ex_pendulumApp;
2. To connect with an available target computer, click the Connect button. The text on the button will switch to 'Disconnect' and the Load button will be enabled.
3. To load the application to the target computer, click the Load button. After the application is loaded on the target computer, the Start button and Stop time edit field will be enabled.
4. To set the stop time of the application, type your preferred stop time in the edit field and hit the Enter key on your keyboard.
5. To start the application, click the Start button.
6. To disrupt the equilibrium of the pendulum on each cart, click the Nudge Cart button. You can adjust the nudge magnitude by using the value selection next to the button, change the reference position by adjusting the value of reference position spinner, or choose a variation pattern for the reference position.
App Callback Code
The instrument panel app functionality is provided by callback code.
Comments in the callback code in the instrument panel app slrt_ex_pendulumApp.mlapp
describe the callback operations and programming suggestions. To view the callback code, open slrt_ex_pendulumApp.mlapp
in the App Designer, and then click the Code View tab. In the Command Window, type:
edit slrt_ex_pendulumApp
Specify Block Paths for Signals
To stream data from signals in the model, see the use of connectLine
functions in the setupInstrumentation(app)
function in the app.
updateAnimationCallback Function
For each AcquireGroup, this function checks whether there is fresh data since the last time the callback was called. If there is data, the function updates the animation objects.
Signals are placed in an AcquireGroup based on sample rate and decimation such that all signals in an AcquireGroup have the same time vector.
Update Axes and Animation by Using Acquire Groups
In the callback code, this processing is visible as AcquireGroupData
signal groups in the updateAnimationCallback
function.
Close the App and Models
The instrument panel app handle app
provides access to close the app.
Close the app. In the MATLAB Command Window, type:
close(app.UIFigure)
Close the open models. In the Command Window, type:
bdclose (model);