Add App Designer App to Inverted Pendulum Model
This example shows how to stream signal 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 two 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.
Open Example and Load Model
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.
Start the target computer.
Open the model
Connect the development computer to the target computer. Build the
Deploy the real-time application to the target computer.
In the MATLAB Command Window, type:
model = 'slrt_ex_pendulum_100Hz'; set_param(model, 'RTWVerbose', 'off'); tg = slrealtime; evalc('slbuild(model)'); load(tg,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
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 enter button.
5. To start running the application, click the start button.
6. To disrupt the equilibrium of the pendulum on each cart, click the Nudge button. You can adjust the nudge magnitude by using the value selection next to the button, hange 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:
Specify Block Paths for Signals in Referenced Models
To stream data from signals in the model, see the use of
connectLine functions in the
setupInstrumentation(app) function in the app.
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 Acquire Groups based on sample rate and decimation such that all signals in an Acquire Group 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
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 the open models. In the Command Window, type: