Copyright 2017-2019 The MathWorks, Inc.
This repository contains resources for getting started with MATLAB and Simulink and the Robot Operating System (ROS). This functionality is provided by ROS Toolbox.
To learn more, refer to our blog post and the following videos.
- Getting Started with MATLAB and ROS
- Getting Started with Simulink and ROS
- Deploying Standalone ROS Nodes from Simulink
- Distributed Computing with MATLAB, Simulink, and ROS
Contains files provide a basic structure for creating your own MATLAB and Simulink files.
- loopTemplate: Algorithm runs in a simple loop, with an optional pause between iterations
- rateTemplate: Algorithm runs in a simple loop, which runs at a fixed rate dictated by either the wall clock or the global ROS node clock
- async/asyncTemplate: Algorithm runs asynchronously, whenever a new ROS message is received
- timer/timerTemplate: Algorithm is scheduled to run on a timer in the background
- simulationTemplate: Model is slowed down using the wall clock, to run approximately in real time
- codeGenerationTemplate: Model is configured to generate a standalone C++ ROS node using Embedded Coder
- multirateTemplate: Model contains multiple subscribe and algorithm rates, as well as displays the color-coded rates in the model
- architecture/mdlArchTemplate: Model contains MATLAB, Simulink, and Stateflow elements. Links to reusable MATLAB files and Simulink block library in the architecture folder
- paramServerGetterTemplate + paramServerSetterTemplate: The "getter" model can run on the desktop or deployed standalone, and receives parameters from the ROS parameter server. To modify the parameter value, you can either run the "setter" model, or use rosparam in MATLAB or a Terminal window.
Contains filled out versions of the templates above, that will run on several platforms.
- Uses camera information to detect a blue object and return its position and size
- MATLAB code can be found in Algorithms\detectCircle.m
- The same function is called in the Simulink examples using a MATLAB Function block
- Uses the output of the object detection algorithm to assign linear and angular velocities such that the object is centered in the field of vision and has a certain pixel size (or distance)
- MATLAB code can be found in Algorithms\trackCircle.m
- Simulink and Stateflow versions of the same algorithm can be found in Algorithms\controlLib.slx
These examples have been tested on Windows using the MATLAB Support Package for USB Webcams at https://www.mathworks.com/matlabcentral/fileexchange/45182-matlab-support-package-for-usb-webcams
These examples have been tested using the Linux virtual machine at https://www.mathworks.com/support/product/robotics/v3-installation-instructions.html.
When you open the virtual machine, you can track blue objects in either the Gazebo Playground or Gazebo TurtleBot World worlds. To test the tracking algorithm, you can use Gazebo to move the robot and/or the blue objects in the world.
These examples have been tested using the TurtleBot 2.
You can find a printable blue circle in the Images folder.
The MATLAB subfolder contains loop examples, as well as a timer subfolder showing the timer object and handle class approach.
The Simulink subfolder contains examples with Simulink blocks, with Simulink blocks and a Stateflow chart, and using External Mode and the ROS Parameter Server (see the paramServer subfolder).
In addition, the distributed subfolder contains examples of the perception, control, and visualization components broken into multiple tasks and separate models. The models can communicate with each other with a standard ROS message or with a custom message which can be found in the custom_robot_msgs folder. To get the latter example working, you will need to use the ROS Toolbox Interface for ROS Custom Messages add-on and follow the steps shown at https://www.mathworks.com/help/ros/ug/ros-custom-message-support.html