Monday, December 9, 2024
HomeMatlabThe Curling Sport… Model 2022 » Man on Simulink

The Curling Sport… Model 2022 » Man on Simulink


For the 2022 Winter Olympic Video games, I’m excited to share a brand new model of the Simulink Curling Simulator! That is now the third Winter Olympics that our curling sport is taking part in, making it one thing of a Simulink custom. For these not aware of this app, you may see the way it developed through the years in these posts:
For the 2022 Winter Olympics, we upgraded the app to make it suitable with Simulink Compiler so it may be deployed as a standalone executable or as a Net App that may run in an internet browser.
Disclaimer: I actually wished to incorporate a hyperlink on this weblog publish to a publicly obtainable internet app for all of you to attempt the sport in your internet browser, as we did final yr for the Exponential virus unfold simulator, however I ran right into a technical challenge. We’re nonetheless investigating that; I’ll replace the publish as soon as the online app is on the market.

Right here is an animation with annotations that can assist you getting began along with your first sport:

CurlingTutorialSmall.gif

Acknowledgements

Earlier than going into the main points of the curling app model 2022, I need to acknowledge a number of colleagues who labored on these updates. As I discussed above, this curling simulator has a comparatively lengthy historical past, and MathWorkers like making an attempt out new options with it.

Karthiga, Michael, Robyn, Ying, Sarah, and Corey

Linking App Designer, Stateflow for MATLAB and Simulink

One of many vital issues to comprehend with the curling app is that the app graphical components are outlined in App Designer, however a lot of the app logic is outlined in a Stateflow chart executed as a MATLAB object. I like this manner of doing issues as a result of the Stateflow language could be very handy to precise the sort of logic wanted for the app.

When you take a look at the startupFcn callback of the app, the very first thing it does is instantiate the Stateflow chart and go to it a deal with to the app itself. That is the important thing for the bi-directional linking between the app and the chart.

In a single course, within the app callbacks, this enables me to set off occasions outlined within the Stateflow chart. Within the different course, the Stateflow chart can entry and management widgets within the app:

Simulink Compiler

This model of the curling app is the second app I attempt deploying as a Net App utilizing Simulink Compiler. The final time was in 2020, with the Virus Unfold Simulator. At the moment, in R2020a, I might solely name the sim command and animate the outcomes as soon as the simulation was accomplished.

Since R2020b, Simulink Compiler launched new features to set callbacks to get information out and in of the simulation whereas it’s operating:

Here’s what the code creating the Simulink.SimulationInput object handed to the sim command appears to be like like:

In a means just like how we linked the app and the Stateflow chart, a deal with to the app is handed to the callbacks. That means, the callbacks can entry and management the app widgets. For instance, right here is the chain of occasions for the InputFcn callback:

  • The consumer clicks the Sweep button within the app
  • The sweep button callback triggers the sweep occasion within the Staflow chart
  • The sweep occasion adjustments the worth of the “sweepVal” property outlined within the Stateflow chart
  • When the simulation triggers the inputFcn callback, it reads the worth of app.curl.sweepVal
  • The Inport block sweepInput outputs the worth of app.curl.sweepVal learn within the inputFcn callback.
I’m not going the describe the main points right here, however an analogous course of occurs for the OutputFcn callback. For a less complicated instance leveraging these callbacks, I like to recommend taking a look at this: Deploy Mass Spring Damper App with LiveIO

3D Visualization

One other enhancement you in all probability seen in comparison with the earlier model is the addition of a 3D visualization.

curling3Dsmall.gif

Now it is your flip

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments