dds blockset with rti connext using shapes demo video -凯发k8网页登录
this example shows how to import, configure, and deploy the shapes demo provided by rti to introduce dds concepts. you can subscribe to various shapes such as circles, squares, and triangles and watch their location as they move around a canvas. in this version of the demo, dds blockset provides an application that subscribes to a square and then publishes the location of a circle.
hello, my name is mark mcbroom. i'm an application engineer at the mathworks. today, i'll be going through a demonstration of the new dds blockset, which was released in r2021a. in this demonstration, i'll be going through a typical workflow in which a user begins with an xml file. this xml file defines the dds topic types, the quality of service, profiles, and the domains on which the topic types and quality of service profiles will be used. this xml file can be created by a text editor or through a third party authoring tools such as rti system designer.
in either case, once this xml file is available it can be imported into the simulink data dictionary using a dds wizard. and at this point the contents of the data dictionary can be viewed and edited as needed to make any adjustments needed as far as types, domains, or profiles are concerned.
the next step is to construct the simulink model. the simulink model would contain one or more dds block set blocks for subscribing and publishing the two dds topics. in addition, any necessary processing that would be done on the dds messages before sending them out. each dds published and subscribe block is then mapped using the code mappings gui to one of the topics defined in the data dictionary.
once the algorithm in the simulink model is determined to be executing properly by various simulation tests, you can deploy the simulink model by generating c code. the c code links to libraries provided by your dds vendor. and then that application can be deployed to any system that has library support from your dds vendor.
in my case, i'll be deploying to my same windows computer that i'm running simulink on. and i'll actually be running that deployed application which sends received messages to the rti dds shapes demo. with that, i'll open up simulink.
first, we'll take a quick look at the xml file we're going to be using today. this xml file has three main sections. the first defines the types that will be sending or receiving. in this case, we just have one type to find that has an x and y position and a size.
that's followed by a large section that defines a number of quality of service profiles. if you're familiar with dds, you know that these profiles define the overall operation of each publisher and subscriber. lots of different parameters that you can adjust to get the desired performance.
that's followed by a section that defines the domains on which we'll be sending our receiving topics. in this case, we just have one domain. it's on domain id zero. and there are three topics to find, all using the one topic type to find at the beginning. and then lastly, there is a section that defines each of the publishers and subscribers on this domain and which of the three topics they'll be sending or receiving.
with that, we'll open up simulink. create a blank model. and the first thing i want to do is import that xml file we just looked at. we'll do that by using the dds app. so the dds app can be found by opening up the app tab, and then picking from the code generation section the dds app.
tool strip in wizard. this will walk us through the process of importing the xml file into simulink. you have the option of two different dds implementations. i'll be using rti connext. and i'll be using the xml file we previously looked at.
you do have the option of using the default xml file that mathworks provides or using an already existing data dictionary. we'll be importing from our xml file. and we're finished.
so the next step is to look at the xml information that was imported, make sure it all looks right, and possibly supplement with additional content. the data dictionary has three tabs-- one for types, domains, and quality of service. on the types tab, if we expand, you'll see that we have one topic type to find. this type has three elements to it-- x, y, and shape size.
again, notice this user interface looks very much like the simulink bus editor in simulink, if you're familiar with simulink buses, because that is the mapping we made between dds structures, topic types, and simulink. you can define additional structures here, if you like-- additional topic types. you can also define constants or enumerated types that might be used in one of your structure type definitions. i won't add any here.
the second tab defines the domains. in this case, we just have one domain, assigned domain id 0. and on that domain we have three topics to find-- circle, square, and triangle. all using the same topic type.
if desired, you can add additional domains, or to the existing domains, you can add additional topics. and the editing would be done over here, on the right-hand side, where you associate topics with the types that you've defined on the types tab.
and finally, there's a quality of service tab that defines the quality of service profiles. in this case, we've got four defined. you can browse through and look at the various settings and make any necessary adjustments. for example, for this data reader we have the history setting set to keeping all history, but the depth is only 1. you could change either the kind of history and/or the depth of the queue that you'd like to specify.
so once you've gone through the data dictionary and confirmed proper settings or made any adjustments, it's time to actually construct the simulink model. first, let's open up the library browser. and you'll see we have a new section here for dds, with two blocks available.
we're going to have a simple model here that's just going to take in one dds topic type-- or one dds topic, i should say. and then publish a topic with the same type, but a different topic. we're just going to do some simple processing on the topic after we receive it.
the first thing we need to do is tell simulink what the simulink type is of this. so we have a corresponding simulink bus that was created for that dds topic type that we just viewed in the data dictionary. we go and turn on the overlays and show data type. be able to see that we've got just one type propagating through the model.
this is showing a simulink message coming in that's carrying the dds sample. it's unpacked by the dds take block and converted into a bus. this bus is then processed by the subsystem, then packaged back up into a dds message, and sent out as a simulink message on the network.
so let's add some basic processing to this so our model has some simple meaning to it. so we're just going to pull out the x and y positions of this bus and offset them by a value of 10.
so i'll quickly draw this model.
so we're going to strip off the x and y elements from the bus, and write them back. let's connect this up first. and write back the x and y.
so we're taking off the x and y position from our sample that comes in, we're offsetting it by 10, then writing it back out. so make sure everything's still updates, which it does. so now we've got a functioning simulink model that updates and runs. at this point you could construct additional tests with simulink test to verify proper behavior of the content of your model. at this point, we'll assume the model's correct and we're ready to generate code.
so there's one final step before we actually generate code, and that is to associate each dds block-- and you could have, by the way, multiple dds take and receive blocks here. we have to map each input port or output port, each input message, each output message to a sample that we defined in the data dictionary.
so just to refresh your memory, for our domain here we defined three topics-- a circle, a square, and a triangle-- all with the same shape type. so what we're going to do for this example is we're going to read in a square. so we're going to subscribe, or take, a square topic, do some processing on it, and then publish a circle topic.
so we do that by associating one of the topics to each of the input ports and output ports. so for input port, we're going to select one of the three available topics. we're going to pick the square topic coming in. and for the output port we're going to publish a circle.
so now we've completed the simulink model. we'll just make sure it updates again. at this point, we're ready to actually generate code. so you do that by just clicking the build button on the dds tool strip.
it's now completed code generation and producing the code generation report. if you're not familiar with embedded coder, we produce this nice standalone browser of the generated code, but we'll also placed a generated code in the simulink canvas, side-by-side with the model. that allows us to do side-by-side inspection of the c code associated with each block in the simulink model.
so that view is being prepared. there it is. let's make this a little bit bigger so you can see it. so we can click on a particular block in the simulink model and see the resulting code. so here's the code for our take block.
so it's calling a method that encapsulates all of the dds apis for receiving a sample. it is returning that sample on a local variable. the local variable then gets copied to another local variable, if a valid topic was received.
so then if we dive inside our subsystem here, we'll see some of the processing that's being performed on the bus that we unpacked from the dds sample. so we're taking the x and y positions and offsetting them by 10, then associating them back with the bus, and then back at the top level, we're sending our sample back out. and again, there's another method here that's used to encapsulate the dds apis.
we'll just look at two other files here. the first is the source files called rti adapters. so these have the bulk of the apis in them for actually communicating with the dds libraries. if you're familiar with dds, you'll recognize some of these. but the first is registering our topic type. in this case, we just have one type called shape type 1.
then further down, you'll see code that's creating our participant. this is creating the participant using the xml file we imported with all it's necessary types, publishers, and subscribers. and finally, we'll see the methods here that are responsible for reading and writing. so here's our method for taking a sample. so here you see we're taking a sample off the dds network. and then finally, here is the code for publishing a sample on the network.
two other things i'll point out quickly-- two other source files. one is our main. so we do produce a fully functional executable. and the main shows you all that necessary calls needed to actually create instances of the publishers and subscribers. so see where we're making calls here to the methods i just showed you for registering our types, creating the participants, and then setting up a timer that's going to run the c code at the rate specified in the simulink model.
and finally, one more last thing i'll show, as far as code generation goes, is that all of these c code produced in the model is placed in one directory. it has the name of the model with the rtw appended to
the end of the model name. and inside, you'll see all the c code that was produced, including code from rtiddsgen.
if you're familiar with rtiddsgen, you know that that's a tool provided by rti. it takes in the xml file we looked at earlier and produces a streaming code needed for sending and receiving each topic type that's defined. and lastly, in this directory we have the executable that was produced from our simulink model called untitled.exe, which is the name of the simulink model.
so at this point, we're ready to actually run our executable with the shapes demo. so open up the shapes demo. we're going to publish a square and subscribe to a circle, which is the opposite of what the simulink model is doing. so i also have just a shell that's opened up pointing to the same directory where my executable is located. i'm going to just run the executable.
and we see in the shapes demo window that our simulink model is, in fact, running. just refresh your memory the simulink model is taking in. it's taking a circle-- i'm sorry-- it's taking a square and publishing a circle. so let's take in the square and publishing the circle back out.
finally, we can look at the admin console and see that we've got circles being published by the shapes demo and subscribed by the simulink model.
that concludes my demonstration for today showing you a workflow from an xml file, importing that into simulink , building the simulink model, and deploying the c application.
featured product
dds blockset
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 mathworks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- (español)
- (english)
- (english)
欧洲
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
亚太
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)