Simulink Basics - A Practical Look

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody happy thursday and welcome to our live stream on learning the simulink basics on the matlab youtube channel this is ed marcus here i work at mathworks and i focus on simulink and model-based design applications and today my buddy and colleague connell is joining us hey guys how you doing yeah how are you doing today uh my name is connolly everyone i've done a couple of these live streams before again i work on the student competition team here um i help a lot of our our student teams work on autonomous systems in aerospace so we're very excited to talk to you about sibling today um this is your first live stream right so yep that's right that's welcome welcome to the livestream team i guess yep so let's learn some simulink basics today uh let's go through the fundamentals and you know whether you have heard of simulink or and never used it um we're happy to have you here also if you've used simulink but you want to get more familiar with it we're happy to have you here so let's get started and at a high level we want to answer three questions what simulink you're probably wondering that so we'll go through that you probably want to know what can you do with it what can you do with simulink and for that you're going to see us do examples for modeling and simulation and also for working with hardware in simulink and the third and last question i've got a little i've got a little arduino here that we can play with a little later so very excited excited to see what happens look forward to that and the third question we want to answer is how do you get started where do you learn more and how do you get your hands dirty with simulink so to answer that first question of what's simulink i want to take us to mathworks.com right so here you see a nice banner for using matlab with ai or for ai hopefully you're familiar with matlab and today let's focus on simulink here so this is the home page for simulink and at a high level simulink is a low code environment for modeling simulating and analyzing dynamic systems that's what it is so ed i just want to stop you right there because like you know i i know we're going to have a lot of new people disabling on this on on on the stream um can you can you answer this question for me does simulink and matlab work together are they independent are they two separate products can you give me a little bit of a load on that before before we jump into what simulink does and stuff like that yeah yeah can you actually run simulink without having matlab i i guess that's that's a question i get asked a whole lot matlab and simulink work together right so you do need matlab for working in simulink and that's the key point there that they work together and in a way that makes simulink even more powerful because you have access to a lot of functionality that matlab gives you all right so we saw what simulink is and you know you can use it for modeling multi-domain systems what that means is that you can include multiple effects or domains of your system in one environment so let's think or let's imagine that you're designing a wind turbine right you have to take into account aerodynamics mechanical components and electrical components so you can include all of that in one environment and as you model or design a system like that one here are some of the benefits that you get with simulink right you can model and simulate so you can try situations that might be too time consuming or risky to consider with a prototype right yep simulation is also cheap and it's fast to run compared to working with a hardware prototype so you can test early and often and when you do that you can find issues earlier in your design process and i i i can see how that's useful because i mean if you're if you're building something as big as the the a380 or a huge jumbo jet you can't you can't build like 100 prototypes and test them and crash them that's just not it's not it's not economically feasible you don't have the time to do that so all right i i can see how testing early and often is is super important when you're when you're when you're building big systems exactly and that's not all once you have all these models you've tested them probably you need to end up running on hardware and so a nice thing is that you can automatically generate code from these system models that you already built okay so and here i have again uh the point that matlab and simulink work together right so that's one of the things that makes simulink so flexible and so powerful and so with this integration with matlab you can do things like extend your analysis simulink gives you a lot of tools for analysis but you can extend that with matlab you can also automate things like running simulations and trying different parameters for your models and you can even run your matlab code in your simulink models which is pretty cool okay so again now you know what it is let's jump into simulink now and the way i want to do that is by showing you simulink on the web browser right this is pretty cool because we just introduced this uh simulink online and so if we just do a quick search for simulink online that's the page you want to go to and you know if you want to use all the add-ons for specialized tasks the desktop version is great for that but if you want to access simulink from anywhere without downloads or installations you can always try it from your web browser okay so once you come here let's just start using simulink online and so you see this is loading matlab online and it's going to show me the simulink start page in just one second and so in case you missed it i want to show you how to get to the simulink start page uh you can get to the simulink start page by typing simulink here in the matlab command window or i can just click here on this button in the matlab tool strip and the nice thing with the start page is that you have templates that serve you as a starting point maybe if you want to design things like digital filters feedback controllers fixed up systems in this case today we're going to build a blank model step by step so we'll walk you through that and another cool thing about the start page is examples and this is one of our favorite ways for people to get started just grab an example run it change some things break it and you know make some mistakes and learn along the way yeah i i i couldn't agree more i think i think the the one thing that i recommend to anyone that asks me how to get started with matlab assimilate is just open up an example you know you can click around uh it's actually it's almost fun to open up an example try to break it and then try to fix it yeah you know because like i i feel like that's the best way to learn you learn by doing things so i i'm i'm all for starting from example so so ed we are going to take a look at an example today or are you going to build up a model for us we're going to do both we're going to do both we'll start by following a model step by step and then let's look at an example that comes included with simulink and then another way you can get started with with these on-ramps that are accessible from the start page but let's get to that uh later in the session now let's just start building our model here so that is creating the blank model and here i have the simulink canvas right so this is a simulink interface this blank area is the canvas that's where we're going to build our model and with simulink you have a tool strip very similar to matlab right so this tool tool strip is great because it shows you a lot of the capabilities um in simulink and those capabilities are grouped and organized by workflow right so you have capabilities and options for simulating debugging your model for modeling and configuring the model many things for doing the format so you can for example set the background of your model and things like that ooh matlab block mode yeah right so i just did a control z there and then the last thing is apps and these apps are great because these are user interfaces that make it really convenient to complete tasks or workflows say things like controls tasks or workflows like uh automatically generating code from your models in some other verification and validation workflows too so so i'm just gonna stop it right there because we got a couple of questions in the chat uh the first thing is is simulink online free to use um and is it free for students i guess so it's a couple of questions on that that's a great question so you will need a license for simulink online but the good news is that it's available for most of the student licenses so if you're a student you're most likely going to have access to that it's also available for home use and the standard individual license yeah it's essentially essentially i believe what you need is is a matlab online license which which would which would allow you to do to use that interface a matlab online and a similar online lessons all right so let's build the model okay let's go for it i'm excited to see what happens all right so i want to insert an image here just to show you a picture of where we're trying to go what we're trying to build so you saw there in the left tool in the left tools i grabbed image and here you see my matlab drive so this is all on the cloud and i already have this picture of a dynamic system which is something we talked about when we defined simulink okay so the system we're going to build today step by step is a spring or a mass spring damper system okay you see the picture there and let's you know look at the equations that represent that kind of dynamic system so here i have uh the equation that represents the summation of the forces in this case let's keep it simple uh let's not have an external force and i just substitute it in the second line these formal terms like x double dot and x dot to things that i'm more comfortable with so acceleration and velocity and then in the third line i just rearranged the equation so that's the equation that we're going to implement in simulink to model our system okay so it's essentially when you talk about a simulation you're essentially solving that differential equation right which is it you know it it may sound fancy and it may sound like it's you know it's it's like it's this you know black magic kind of thing that's happening in the back but essentially what you're doing is you're just solving a differential equation right and siblings got these these robust solvers that can help you numerically source all those those those differential equations so um i i guess let's let's let's code up our our differential equation let's do it and so the way to start inserting blocks and elements into our model is from the simulink library browser so you see there i clicked on the button and that's going to bring up all the libraries and blocks that are available to me to build my models so here you see i have libraries for simulink and we're going to stay there today but you see there are also things for more specialized tasks right like aerospace systems autosar systems and and much more so if we look at simulink we're going to stay with the commonly used blocks today right we're going to keep it basic and fundamental and here you see things like constants gains integrators math operations that can help us build these kinds of equations so the first block i want to grab is an integrator that's going to be you know the fundamental building block of the mass spring damper system so you see i dragged and dropped it and we can close the library browser and so at the input side here okay and you also get some suggestions uh if you're new you and you start using simulink so at the input side here let's start with acceleration and you see that when i integrate acceleration we're going to get velocity velocity exactly and so now i could just copy paste this block and integrate velocity again and what's going to be at the output side of that is my displacement so let's call that x and now we need to keep basically building this equation so now what i'm going to do is i want to multiply this x times k and so i could go back to the library browser but if i already know the blocks or the names of the blocks that i'm going to work with i can just click on the canvas and start typing the name of those blocks and you know this will come to you as you use simulink more and more right so here let's grab a gain block i can set it to be k you see that it became red so simulink is giving me a warning that hey this k parameter is not defined yet i don't know what the value is but we'll get to that point uh when we define all the parameters we need to simulate the model okay so now i can rotate this block if i go here to the format options of the tool strip i can rotate it or just flip it okay so let's do that and let's connect k and x can move all of our stuff closer here and kind of help help us out here what is the output of uh of this block here uh k times x exactly there we go right and we're going to do the same for the v signal so another way that i can insert blocks is if i double click on um on a connection that is not complete yet simulink will give me suggestions on what are the blocks that are most likely that i'll connect there and only the blocks are compatible so it's doing some of the filtering for me there you see again again and you know i can change the value here in the in the icon or i can just double click open the block dialog and see a whole lot more properties for that and this is where you can control things like data types and the size of the signal and stuff like that sample times et cetera oh we should talk about sample times at some point uh because i i feel like that's an essential part of simulink so yeah yeah we're going to talk about that after we simulate the model so here now we have basically the building blocks or the right side of the equation right so now we need to add a math operation let's go with the add and what we need to do here is we need to change these signs to be negative or minus and minus right so okay and what we get at the output of this here is going to be now mass times acceleration right and so we're really close to finishing uh the model in the equation of the system so now what we want to insert here is again gain right because what we're going to do with this gain is we're going to define it to be 1 over m and you see that the parameter value there is kind of large so it doesn't fit but simulink gives me the option option to automatically resize the block so that i can show the value so that's pretty nice all right so now we basically implemented the equation and there's one more thing that we need to do you see this xo or this initial condition of one meter well we can implement that here in this integrator so you see the initial condition for it let's set it actually let's set it to x zero and it should you know should be a red highlight because again we haven't defined many of those variables yet yep all right colonel how do we visualize this data that we're going to get out of the system oh that's this is my favorite part so you you you can do something you can use the simulink data inspector or you can use uh things called scopes so if you um if you if you click on a particular signal you have the ability to um um to to log it as as ed's doing in in the in the uh on the screen or you could you can actually add it into into a scope uh logging it means that it's going to open up in the simulink data inspector um view which which we can show to you in a little bit but but it has essentially gone in and added a quick a quick little scope in there which we can visualize our our position or our x term um over time so good stuff exactly so yep we did both we're logging it and we're going to visualize it with a scope and before i go and define my parameters i want to save the model right so let's do that and let's call this mass spring damper underscore model pretty creative there very original name yeah all right and that's going to be saved in our working directory which in this case is my matlab drive so there you see my model and now we can start defining some of those values and i could do it here in the matlab command line or i could just use a script to do that so let's use a like script and actually let's go ahead and save that live script as well so mass spring damper underscore script and let's start defining our parameters so here b was equal to 10 so that's the damping coefficient our k was equal to 400 and that's the spring constant string constant the x 0 for the initial condition we said 1 meter and then we didn't have a value for m which was the mass and that was actually on purpose right because what we want to do is we want to look at the response of the system as we change the value of the mass right and we're going to do that with matlab so let's start with a value of 3 for the mass and if i run this section of the script here you see that my values are populated in the matlab workspace and this is a global data repository where simulink models are going to be able to see the data that i have here in the in the base workspace all right so if we go back now to the model with the parameters defined i can run this so there it compiles and it'll run for 10 seconds but that's 10 seconds of simulation time not like real time yeah you see that it completed already so i did it pretty fast and if i look here at the scope now there is the response of the system right we're looking at the displacement yeah we just sort of expected you know you you started one it'll it'll oscillate a little bit and then the the the damper sort of comes in and damps those oscillations out until it's it's back at rest yeah now i want to take this time here to talk about the sample times right because you see that right now the signal is a little choppy it's not very smooth and that has to do with the solver right so if we go back and take a look at the solver settings here in this model settings button i don't want to get too deep into the details of solvers exactly so you know i just want to let you know that there are options for running variable steps fixed step if you want to run into or run on hardware on hardware simulink is automatically selecting the solver for us but what i want to change here is the maximum step size so um if i were to type one this would be one second and that means that every second simulink would be solving the system and updating the results right so in this case i want to go with 10 milliseconds so if we make that 10 milliseconds let's apply it hit ok and here we can sort of see a comparison if i bring up the scope again here it is and so i can run my simulation from the model or from the scope here and now you will see that when it compiles and runs pretty quickly you see the response looks a little better right it's it's smoother another so i want to show you also the data in the data inspector since we talked about it and the cool thing about data inspector is that it logs uh the different simulations right so here's the data from the latest simulation but then you can compare with previous simulations and overlay the data so you see when it was choppy and yeah when we uh made the sample time really small you see how smooth it got and you can see the comparison there so it's actually interesting because because because now we can go in and change that mass value and sort of compare the different simulations together and and see what our displacement is right side of your mouth yeah yeah there we go now we're going to do that with matlab because i want to take us back to that point that simulink works with matlab right so one of the things that we could do is write a little script where we simulate our model multiple times by changing the value of the mass so let's do that right now and the first thing i want to do is create a model variable that is going to grab my current system and if you're not familiar with this gcs it just grabs whatever model i'm working with and i love this stuff about matlab the command window because i can quickly try code right and so i know if what i'm writing is working or not so that's a quick tip there then we want to try different mass values so here we're going to have a vector from 1 kilogram in increments of 2 until 11 kilograms right then then we're gonna put this stuff in a for loop and our counter is gonna be uh from one to the number of elements in mass values in mass values and you know i also love the the live script because it sort of autocompletes things for me it's like cheating right it's almost like it's it's so easy that all right so now we got the loop and the first thing we want to do in the loop is change the mass value so m is going to change to be mass values of i and then after i've changed the mass value i want to sim my model variable but i do want to get or capture the outputs of that sim in this variable called results so so this the sim command is going to execute that model that that's that that's working right yeah exactly so now since we're capturing the outputs and results we're going to plot results dot i believe it logs out so that's whatever we're logging with the data inspector or we get uh some output here and then we're going to get the signal that we're logging which is x and we're going to get the values of x we'll do a hold on to make sure we overlay the plots on top of each other and then i'm going to create another variable called legend labels of i and this is going to be a cell array that has basically all the strings that show me the mass value that i'm currently running so one cool thing with matlab is that i can actually add strings so there you see the mass value is equal to num to string of m right so that will display the mass value in the legend and i think yep we're good there and then i also want to display the status of my simulation so let's say simulation um to string so simulation one or simulation two so that'll be i is complete right and then outside of the for loop i want to provide a legend label to the plot that i'm creating that uses the whatever i had in this cell array so legend labels oops yeah i might want to correct that spelling there we go thank you live editor all right so this cross fingers this should work but before i run this i want to go back to our model and show you a quick trip or tip since we're going to run this multiple times in iterations uh let's use this fast restart and so what that's going to do is the model is going to compile one time and then the simulation is going to be ready to start you know for the next iteration so it'll just speed things up a little bit okay all right so moment of truth there it is oh so it's updating the status simulation one is complete there's two three four five six and uh there is our plot with the results so i can open that in its own figure and you see how we automate it with matlab all these simulations and you know the analysis of the results so we extended the analysis capabilities that we get with simulink so here you see each one of the lines for each one of the mass values that we're trying in this mass spring damper system um this this this is awesome i mean it's great because like what we saw is you know we essentially essentially you know we we have we have a script with a bunch of code but really what we're calling is that one sim command everything else is really just plotting plotting it out but you can see in this way if you have multiple parameters in your model that you want to sort of test you know test different parameters test different configurations you can sort of step through all of these you know in different permutations and combinations and and do all that for matlab so it's great you have all the results you can analyze them after the fact and um and yeah i i just i just think let's let's stop with some questions real quick but and i also want to add to that point that you were saying that it makes it really scalable right because we just automated running six simulations but at the same time i could run a hundred or a thousand changing the values and i could even run these in parallel but that's a topic for a different day so if you're interested in that kind of topic let us know in the comments below okay awesome uh so so we we've we've got a couple of questions um it talks about so the first one is can you model nuclear particles moving in um in a metric of general relativity with simulink in three oh that's that's that's a bit of a loaded question essentially essentially what i want to say is with simulink if you have the equation if you have the the differential equation for a system um you can put that into simulink and model it so so so technically yes without you know without without sort of going into specifics yes you can as long as you have a differential equation for it um you should be able to model it i'm not sure if we have you it may be a good opportunity to look up file exchanges if someone's already actually built that model before um but but but definitely if you if you have if you have the differential equation you can model it in in simulink um right answer that's the way to put it good way this is the second question about uh does m need initialization before the for loop um uh well it needs needs initialization for the model to run even one time uh yeah basically the answer um i guess maybe the answer is no right yeah yeah technically could be no but uh yeah yeah because we could initialize it here uh before we run the important thing is that you have an embed value before you simulate the model correct correct uh um all right um oh the there there was another interesting question on on on the sort of working of simulink online so someone's asking us hey uh how does how does matlab online execute code where where is all this where is it where is this code running um it's running on the cloud yeah it's so so matlab online runs on on on matlab on on macbook servers um essentially essentially you're you're just spawning up a cloud instance of matlab and everything is happening on the cloud so it's it's pretty awesome you don't have you can use it in a browser you don't need you don't really need to download the whole product uh it's it's really handy you know uh i've seen i've seen people use this on on on tablets which like blows my mind it's crazy yeah exactly matlab is going mobile too there's a version of matlab mobile which is pretty awesome and you know since it's all running on the cloud when you save files it's actually here on your matlab drive so you can access these files from anywhere which makes it really powerful and convenient um yeah awesome so um hey is it is there anything more that we need to cover here before we move on to to to hardware yeah good question let's quickly so we saw how to build that model step by step how it integrates with matlab and let's quickly take a look at um an example that actually comes with simulink so if we look at this example here and we like to call these shipping examples but you get them you know for free included in the product product yep so what we're going to see with this example is what we just built step by step but what i want to show you is a couple of different options that you have to build these kinds of systems okay so here we get some annotations with these examples and resources to get started we're not going to need that for now and then i'm going to move this up here so again what you see here is basically the the model that we just built step by step and we did that by deriving the system equations and implementing those equations but what if you don't know the equations of the system that you're trying to model right or what if those equations are really complex or maybe users you just don't have time to derive the equations for your system so simscape or simulink can still help you with that and the answer to that is with physical modeling and that's the kind of model that you see here to the right and simscape is basically the platform for doing physical modeling within simulink and one of the nice things is that this model looks a lot like a schematic right that you see the spring the mass and the damper but this is a schematic that simulates and gives me results so it's really valuable and another thing that i really like is these models of these physical models are really easy to extend so you know if i wanted to model a double mass spring damper system i could just copy paste connect it and then it simulink is doing doing all the math and the equations under the hood for me yeah right so that's what uh physical modeling uh means so it is essentially essentially you you've sort of got two avenues to go around one is when you know the differential equation um you know all the parameters involved with it um you sort of use simulink and and and and solve that up or if you you know you you're you're more inclined you don't really know the math you're not you're 100 sure you can actually sort of string string up sim scape blocks with so physical physical connections and and and build your model out that way again uh different fidelity levels depending on what your application is you need to pick and choose what works best for you but um as you can see both of them perform in the same way um given the same parameters um yeah it's it's it's it's a pretty quick and easy way to get started yep uh and and then the other thing i want to mention is you know today we covered a really basic example right and and you can extrapolate this kind of system to be the suspension of a car maybe the landing gear of an airplane the airplane itself or a wind turbine maybe a robotic arm and you know so you have an idea of what simulink is used for i want to show you these models for every project section that we have and you can use simulink you see here a model for wireless communications so you can use it for rf design and antenna systems you can use it for power electronic control design for developing control systems and control algorithms simulink for signal processing robotics with physical modeling for adaes and automated driving and even things like digital twins right where you have a physical asset operating on the field and then you're getting real-time data from that asset and feeding it to your model or your digital twin and you can use that for things like predictive maintenance so yep definitely a lot of cool things you can do with simulink all right so now once you have something like this you probably want to develop a controller for it to control its response and maybe you'll end up working uh with hardware and i think that's exactly what connell is going to show us today right yeah let's let's let's go for it so uh let's let's sort of work through some um some technical things as as we get my screen shared um but essentially it's essentially so so simulink sort of works in in a couple of different ways one is we we looked at the modeling and simulation part of it um but simulink can also help you program hardware so we've got a whole a whole host of different different hardware that we can we can we can program i highly recommend that you go and take a look at mathworks.com hardware to see all the supported hardware that we have but uh for today's example um as you can see on my screen we're going to be working with an arduino arduino something that everyone's really familiar with um essentially what happens is simulink is able to program hardware through something called a support package okay or or a hardware support package um and essentially what a hardware support package is if i if i go into my um my library browser up you can from from from the matlab interface um let me just let me just clear the screen real quick uh if you go into the add-ons tab up here you can you can choose get add-ons and you can download such kinds of support package so you've got a simulink support package for arduino hardware i've already i already have it installed but you can do it there's a lot there's also support packages for a bunch of other different kinds of hardware but once you download that that that library essentially what you get is as you can see here um you you get a library of blocks that are specific for that particular hardware so with the arduino we've got arduino blocks for the arduino motor carrier um we've also got some oops so as you can see encoders etc um we've also got some um we also got some some uh i don't know where that went just give me a second there we go uh we also got some common blocks ethernet shields etc let's take a look at the common blocks because that's what we're using so for today's example i've got i've got a little servo motor here as you can see and a little arduino uno um and we're essentially gonna gonna figure out a way to command the the servo motor so the motor that i have is a continuous rotation motor uh which is kind of like it although it's called a servo motor continuous rotation servo motor is kind of like a speed controlled dc mode i guess um but essentially what you can do is you can grab these blocks that'll that'll help you program the hardware so um with the arduino i i i want to give it a signal to to to to to the the control signal port on on on the servo motor so i've gone and grabbed this um this continuous servo block which is which is from here i already have my model so um let's open this up real quick now um essentially what's happening here is i i'm i'm gonna i'm i'm gonna add it i'm i'm gonna show you something called external mode external mode is essentially a way to uh deploy quorum to a hardware but still sort of interact with it as it's running so um again there are two ways of programming hardware you can either deploy the code and it runs standalone so matlab's out of the loop simulinks out of the loop you know your hardware runs on its own or you can run it in what's called external mode or or now called monitor in tune um which is the codes deployed onto the hardware it's still it's still running on the hardware but you can actually control it from simulink so what i'm going to do real quick is i'm going to add a constant block in here and just connect this up so essentially what i'm doing is i'm i'm giving it a pwm signal i'm i'm writing a pwm signal to to pin 4 on my arduino as you can see uh if you click this this guy you could choose a pin number here um it's it's it's it's pretty nice uh yeah and then i'm kinda i wanna say that's one of the cool things about these you know support packages right you don't have to write any low-level device exact drivers so you just grab these blocks and and you just talk to the hardware so it's pretty cool exactly it's because you know more often than not you don't you don't we essentially when we build this this functionality we don't want you to learn a new language we don't want you to you know to sort of reinvent the wheel do something that that that it's probably not in in in your realm of expertise right you you probably are familiar with with simulink as a tool but if you want to program hardware you probably have to use another another programming environment we want to get rid of that for you so we give you these these hardware support packages yeah that speaks to my experience i'm a mechanical engineer by training and you know i'm not alright device drivers i'll be going crazy exactly um exactly so so i i've added a knob in here i can connect this knob to this constant block so um i i i know that my my my motor is expecting a value between negative 90 and uh positive 90 so essentially what one one particular it it'll control which direction the the motor is working in okay so i i've built this up uh let me just go ahead and connect uh connect this to the constant block so i select the constant block um and and it's asking me to connect it apply and we should be good to go so if you if you if you notice this real quick as i move this around um it'll it it'll change that value of the constant log that's being being written to the arduino port all right so let's start this off at zero um the minute you can go to the hardware tab up here to choose hardware settings um uh i you can choose the different boards uh i've got an arduino uno so i'm going to choose that but you've got a whole list of boards that you can and here is that get hardware support package button where you can get more support packages but what we're going to do is i'm going to click the monitor and tune button so essentially what's going to happen is if we um if if once you do this if you can see the bottom left-hand side of your screen it's sort of giving you instructions as to what's happening so right now it's saying that it's building essentially what it's what it's going to do is it's going to convert this simulink model into into c code or whatever code your hardware requires uh and and and compile it and go and dump it onto the hardware so i i've i've got my arduino connected to my computer here um it's still building it it takes it takes it takes a few seconds to build um all right so uh maybe maybe what that while that builds we uh go through some of the questions that are coming in and one of the question is um what what are examples of other hardware that is supported so just just to mention after you let me let me let me just pull up the page mathworks.com slash hardware um so yeah i'm sure we're going to see a lot of them here because yeah you can you can pretty much go through this entire list and there are a bunch of different manufacturers there are a bunch of different kinds but but like you know we support most arm boards uh most arduino boards a lot of national instruments boards um raspberry pi is another one i i really like the raspberry pi support package because you could do things like you know computer vision and and all that kind of fun stuff we've also just got support for the for the nvidia jetsons if anyone's working with that you can actually program nvidia jetsons um with deep learning models directly from siblings maybe we do a live stream on that another time right okay so so uh it looks like the code's built um this is this is the code gen repo the code generation report which sort of shows you the different files that are being being added but arduino server this the arduino server.c this is my this is the file that actually consists of the um of the um the code that that's deployed to the hardware so i'm just going to exit out of this real quick and sort of show you my model um i'm going to hold the servo up here but you'll see as i as as i play around with this knob the servo starts rotating and you can see it rotating yeah in a clockwise direction because i'm giving it a positive value um and then if i flip it over um it's going to go it's going to rotate in the other direction because and then zero means stop so that's what it's going to do um this is a continuous rotation service we're not actually giving it an angle we're sort of giving it a speed value so if i give it a small it's going to rotate slower and then if i go to minus 90 this is like the maximum speed that it can work out but essentially essentially what we wanted to show you is that hey you know without without really like i i don't know like how to write c code i i built a model in simulating a language language that i'm familiar with um and i'm able to program hardware by pretty much by the click of a button um which is great so so yeah so so that's as far as programming hardware is concerned um please populate the questions in the chat uh and we're happy to do another session on this if you if you want to if you want to sort of get more involved with programming hardware i know this is just a little bit of a teaser but but we we're always ready to do more yeah but one of the things i love about this right is that um you know we could probably write some c code and try to do it but it would take us i don't know five hours to figure this out i'm really slow writing c code but with you saw we built this in a matter of minutes and so that's really the benefit that you get um when you use simulink for hardware okay so maybe we take a few questions can you integrate 3d models so you get uh so you get to see the sims and if so what extensions of 3d files does it support so you can include 3d models and the answer to that again is physical modeling so simscape allows you to import um geometries that you can then use in with your simulink models and there are multiple file extensions and also file types that are supported so you can import a whole assembly or you could just a block use a block to import a single component and off off of memory here i think some step files are supported from other software yeah but but there are multiple options you can import import into your simulations yeah uh oh so so we we we have we have another i guess it's more of a comment it's it's sort of sort of in the in in the chat but uh there's a person asking if you can do a full project with matlab and simulink and deployed yes essentially that's what model based design is where you you sort of you know sort of stay in the same environment um you know you can again now we've really only used simulink blocks here but you could just as well integrate matlab code in through a matlab function block uh but yes you you don't really need to go out of the environment to program hardware or perform your entire project so so yes that's that's possible yeah and so this is a little bit of a deep topic here but we we like to refer to simulink as a simulation integration platform where like you said you can bring in existing matlab code that you'll already have and you know run it with your model or maybe c c plus plus code um or maybe even build your own custom functionality and plug it into your simulink model so definitely that is possible yep uh there is a question on could we do simulation of two different controllers like pid and fuzzy using for loop i i guess you could it it essentially is essentially essentially matlab allows you to programmatically control simulink models so you can go down to the point where you're adding blocks in removing blocks out so yes if you have a for loop which sort of you know you can take a look at the documentation for this but you know add in a particular block or subtract a particular block that's definitely possible um i i recommend taking a look at the documentation for that all right conal so how about we jump into the third question for the day which is how do you get started let's do it man let's do it and how do you get your hands dirty with simulink so let's do that all right and i want to show you a few ways to get started right so let's go back to the simulink start page it's called the start page for a reason right a good point to begin and probably one of the best ways are these on-ramps so we have on-ramps for multiple products and these are free interactive tutorials you know they last from two to three hours and you can learn the product by using it and solving problems and working on a project and so we have some for matlab simulink state flow control design with simulink deep learning and a lot more and from simulink online you see you can access the one for simulink and the one for state flow so let's give you a quick or let's take a quick look at the simulink on-ramp here so here you see the multiple sections that it covers so an overview the overview again of the graphical environment working with signals building a basic algorithm and then you get to work on some projects and then you see the integration of matlab and simulink then you cover dynamic systems and discrete time and continuous time systems and a lot more a few other projects so just to give you a quick taste if we click on that running simulations piece here we can take a look if we change the size of these windows and to the left i get this panel here let me resize really quickly to show this in a better way while he's resizing uh there's a question asking about is the on ramp free yes the simulink onramp is free you um you can you can just go uh i i think they've popped a link to the chat uh they've popped a link to it in the chat but you can go to that and it's it is free yep yep and as i said the cool thing is that you get to try the product uh you know with uh step-by-step instructions and so in this case you know you're modeling the velocity of a falling object so sort of similar to what we did where you have a few integrators and gains and the first task is to run the model so you just have to make the connection and when you click submit then it evaluates your answer so it'll compile and run and tell you yup you got it right or maybe try again and it'll give you feedback so you're learning as you're trying the tool and getting immediate feedback there and then you can move on through the multiple tasks there so that's a great way to get started with simulink online and the simulink on-ramp i also want to quickly talk about learning resources online so if we go back to the home page of simulink we have this section here of for getting started right so there again you will see an invitation to the simulink on-ramp but you also have a lot of video resources that we put together for you so you have some getting started videos for controls some getting started videos for signal processing and then there's there's this detailed series that walks you step by step um on how to build a model and it actually gets deeper into the weeds compared to what we did today which was just learning the basics yeah so so there's a question in the chat on asking how does uh um oh i think i lost it oh there we go how does sibling contribute in designing control systems for vehicles i feel like go through this video series it will give you a good idea but essentially what's happening there is like like we built that that plant model of of the mass spring damper you'd have a plant model for your your vehicle it you know again the fidelity level would depend on what type of a controller you're you're you're designing but we've got some pid blocks that you know or blocks that implement different controllers like pid or mpc um and and all of that fun stuff um and you can tune those those those controllers based on whatever plant model you have and then follow that hardware support package code generation process to to deploy the the controller part of your model on onto whatever embedded controller your vehicles using so uh in in in in 30 seconds that's how you use it for control systems for vehicles but if you watch the series i'm sure you'll get more information on that yeah and if you're talking about how simulink is used for control or for control algorithms in production environments you know for uh cars then is the whole process of model-based design where the model you know is at the heart of the design process and as connell said you probably have a plans but you also have an algorithm that you test over and over and over until it's safe to run it in the vehicle and you implement it in production hardware and i feel it's pretty safe to say that many many cars out there are running uh simulink auto-generated code in their uh controllers all right so i wanted to show you also some additional resources just from matlab online so you saw the videos but then here's a big one which is the help and the help you know you get documentation an example so if you click on documentation right from the product here we can see for example if we go to simulink you see all the topics from getting started to really deep topics and what i love about this is the examples are right here we talked about examples as a good way to get started and so there are examples that show you how to use certain features or examples that show you how to go through a workflow or an application okay so definitely try this out and um you know make mistakes and learn from that but this is one of the quickest ways to get started and then the last way that i want to show you is the community and again you can access the community right from the product itself so you've seen this resources if you just click on community whoops it will bring you um to matlab central and so in matlab central's you can see you know matlab answer so many of us will go there and just answer user questions and the community is working together to answer some of these problems and questions and something that connell also mentioned which is file exchange so here you'll see code and entries that are shared by math workers but also by users in the community and you can use all these models so these are pretty cool and you can see some nice applications like aircraft design uh vehicle design input working with hardware yeah and a lot more it's essentially essentially one thing that i'd like to say is there are what what are we two million matlab users some some crazy number like that um everything that you're trying to do has been done before like very very rarely do you come across an application where you know someone hasn't done it before or hasn't made like a video on it on youtube or put it up on the file exchange so um i always like to start writing code i always go to file exchange first and look if someone else has done something and then and then sort of start from there right um yeah so you can find pretty cool entries here you know like vehicle templates and all kinds of uh cool models like backhoe models and walking robots and things that you can just download and try for yourself yep all right so that's that's all i got um do you want to go through maybe some questions let's let's let's do some let's do some more questions uh there's a question on can can you do the simulink on-ramp if you haven't done the matlab on-ramp yes you can i i guess technically you could for me from from a learning perspective i'd do the matlab on-ramp first just because you'd get familiar with the with the end with the interface and stuff like that um but there's no reason why you have to do the matlab on ram first before doing the signaling on that yeah exactly there's no dependencies where you have to complete one first but as conal said it just sometimes makes sense to get familiar with the fundamentals of the platform which is matlab and then move on from there but yep you can go what in whatever order you want um so we have we have a couple questions on code generation uh so i i i know a couple people have asked about uh so so on to the hardware that being said you can also generate so if you if you remember that code gen report that we saw uh you can edit that code so so if you if you don't want to you know if you feel like you can you want to generate the code and maybe integrate it into another code base or something like that that's that's possible as well so uh you know it's it's not only getting deployed onto the hardware you can access those individual code files and and edit it and stuff for that later so so it's it's definitely possible to to to convert it into standalone c code uh or i guess editable c code c c plus plus code uh and then you know do whatever you want to do without that so that's definitely possible um there's one question on on can we get the mathematical equations from the simscape model and do you want to take that yes um most of many of those blocks you can actually see the source code and that source code that is under the simscape blocks is actually based on matlab so the answer for most of those will be yes some components will be protected and you won't be able to get those but for most of them yes um there's one on tips on troubleshooting and debugging when you get errors do you take that one already conno i don't think we did maybe maybe we can actually do a full live stream on on debugging simulink errors i think i think i think that could be something that we could do next uh i love it yeah yeah yeah it's it i i i i'm a simulink user as well and i i you know i i sort of the the sibling the simulink uh uh errors are you you need to you need to use it a little bit to figure out what's going on so so maybe maybe that that's a good next live stream topic for us uh to talk about debugging simulink models yeah and it'll depend on the kind of error that you get right so if you're working with a basic model usually it's pretty easy to debug that but as you get with more complex and complex models it might be good to go into deeper into the details of debugging now please let us know in the comments below what kind of topics you want to see in a future live stream and we'll take a look at those uh yeah [Music] i'm trying to look and see if you've got any more um well if not you know people can always contact us engage with our videos over emails and or in the comments and then we can get answers via that way or again the community with matlab answers uh you'll probably get a response for for yeah this is the there's there's one question i'd like to take uh so it talks about connecting uh vrep and simulink uh i i i think i think a good way to answer this is to is to talk about simulators in general um i believe there is a file exchange entry for vrap if i'm not mistaken um but but with with other with other simulation environments like gazebo or unreal um we've actually got blocks with within our products so i i believe the unreal blocks come up in the the uav toolbox the new uav toolbox uh and the automated driving toolbox um and and and gazebo is another one that that that we ship we ship sort of co-simulation blocks for as part of the robotic systems blue blocks um but but yes you can you can essentially essentially use those those external simulators to either visualize or ah we've got this new core simulation feature now where you can use simulink to control the the sample time that's happening in in in the external uh um in the external simulator so i i recommend you go and take a look at the documentation for that because there's a there's a lot of good information on that um all right so i think we had a pretty fruitful discussion today you saw the basics again the goal was to answer the three questions of what simulink what can you do with it and how do you get started and we want to thank you for your time and for joining us this was great so we'll see you next time yeah okay uh pledge talking to you guys we'll see you soon take care you
Info
Channel: MATLAB
Views: 40,454
Rating: 4.9800797 out of 5
Keywords: work from home live, matlab, simulink, mathworks, matlab tutorial, using matlab remotely, working from home matlab, time series data in matlab, how to plot time series data in matlab, time-series, time-series data
Id: QIAxyLchf4k
Channel Id: undefined
Length: 57min 44sec (3464 seconds)
Published: Thu Oct 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.