Connect and Deploy to a ROS/ROS2 Network from Simulink | AUV Deep Dive, Part 4
From the series: AUV Deep Dive
This video demonstrates how you can connect your MATLAB® scripts and models to an existing ROS/ROS2 network. It shows how to subscribe and publish sensor and actuator data to other ROS nodes from MATLAB and Simulink®.
Today, I'd like to talk to you about how you can connect to an external ROS master or a ROS network using MATLAB and Simulink.
So I have launched my external ROS master. I'm going to define my ROS Master IP here in MATLAB. And I'm going to use a ROS init command to connect to the ROS master.
You can see I can also run ROS command, such as ROS node list, and ROS topic list. So let's run one.
You'll see I have initialized a global node. So MATLAB is connected to my network as a node. And I can see what are my other nodes and the topics that the nodes are publishing.
Of course, I can also go ahead and do other topic commands. Just Type, Info, or echo. But what I want to show is we can create a subscriber that reads from one of these topics. This being a specific laser scan topic. And we have specialized functions to be able to visualize that laser scan. As you can see, I can see a clear indication of what my platform is visualizing.
Now this was in MATLAB. We can have the same be done in Simulink. So here you can see I have a Simulink model. I have three subscribed blocks, each one from a scan, which is a laser scan topic. One bringing in an image frame, and one bringing odometry data. I do some processing on that data, and finally publish to another topic.
So let's go ahead and run this model. But before we do, in MATLAB I had to run a ROS init command. In Simulink, I have to go up to my ROS tab, which if you don't see, you can go into your apps, hit down, and you'll see it as ROS. So you can just click on that, and it'll open up the same tab.
You can go into hardware settings. Make sure that you've selected the right operating system, ROS1 or ROS2. Come down into target hardware resources. Go to our device parameters. Hit edit. And you'll see what we have to do to connect to our ROS network.
I'm specifying my device address, the username and password, and the ROS folder and catkin workspace. And I'll tell you why this is important. You can hit test here to make sure all your connections are correct. If they are, you can hit OK and OK. And before going to monitor and tune, we'll go and just run.
As soon as I hit run, you'll see that I'm able to get LiDAR readings. These change as my vehicle moves. I also get image data of what the camera is seeing currently. And I can also get the odometry data of how my robot has moved in this environment.
Great. So this is just hitting the play button. What happens here is Simulink compiles the model, attaches as a global node, and communicates with the ROS network through the topics that are specified.
We have two other modes that we can connect to our ROS network through Simulink. First, being monitor and tune. Second, being build and run. The main difference here is that when we run monitor and tune, we are still connected to our external node through our Simulink interface. So you can change parameters, such as the range limits, the vehicle radius. You're able to tune all of that.
So the difference between running monitor and tune or build and run from just hitting the play button is Simulink compiles this code and moves this entire generated code onto your target device. This is best
for performance. You'll have your node working in that targeted environment without having the overhead of an OS.
So if I were to click monitor and tune, you will see that Simulink will go ahead and start building this model. Let's take about 20 seconds to build, based on the complexity of your actual model.
And once the build is completed, you'll see that we are still able to get our camera data directly from the model. Now the model is running on our target hardware. So if I minimize this, you can see that I still have access to go and tune these parameters with the model actually running on my target hardware.
If I were to go ahead and hit build and run, we would generate C++ code for this, and it would deploy to the target. But we won't be able to tune any of my parameters from Simulink anymore.
I hope that was able to give you an idea of how you can connect to your ROS network or ROS2 network using MATLAB and Simulink.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)