Communicate and Simulate using ROS Documentation

This documentation shows how to use ROS in MATLAB and Simulink to communicate with hardware and simulate in Gazebo

Contents

Introduction

Robot Operating System (ROS) is a communication interface that enables different parts of a robot system to discover, send, and receive data. MATLAB® and Simulink support for ROS is a library of functions that allows you to exchange data with ROS-enabled sensors, physical robots, or robot simulators (i.e. Gazebo).

ROS Connectivity is provided by the Robotics System Toolbox. There are many tutorials and examples in the Robotics System Toolbox's documentation which show how to use MATLAB and Simulink to communicate with ROS based robotic systems and simulators.

Use the "Getting Started with MATLAB and Simulink" module to learn how to deploy and schedule robotics algorithms. Instead of using basic communication methods like udp, tcpip, and serial, we can use ROS publishing and subscribing to communicate with ROS hardware and simulators.

To get started with MATLAB and Simulink ROS, take a look at the following documentation:

Getting Started with ROS

Overview

This documentation will show some of the examples and functionality available through MATLAB and Simulink ROS.

Communication

Publishing and Subscribing with MATLAB

To communicate in MATLAB, the commands are rospublisher, send, rossubscriber and receive. Instead of using receive to get data, you can also specify a function to be called when a new message is received. This allows other MATLAB code to execute while the subscriber is waiting for new messages.

The following example shows how to use MATLAB ROS publishers and subscribers to receive and send data:

Open Example: Exchanging Data with ROS Publishers and Subscribers

Publishing and Subscribing with Simulink To communicate in Simulink, use the Publish and Subscribe blocks.

Open Example: Getting Started with ROS in Simulink

Deployment

The primary method of deployment of Robotics Algorithms is to simulate or run the algorithms directly in MATLAB or Simulink. Executable deployment as shown in the Deploying Executable to the Desktop Documentation does not work when using ROS functionality. However, Simulink does provide the ability to generate C++ code for a standalone ROS node from a Simulink model. The generated C++ code can be transferred and run in a Linux ROS environment, and built and run independent of Simulink.

Deployment in MATLAB

To deploy MATLAB ROS algorithms, simply run MATLAB code directly from the MATLAB IDE in simulation as shown in the Getting Started with MATLAB and Simulink module.

Deployment in Simulink

There are two options for deployment with Simulink ROS algorithms.

Simulating with Gazebo

In MATLAB and Simulink, you can develop robotic algorithms and then simulate the algorithms in Gazebo. In order to switch between deployment and the simulation, the user only has to change the IP Address used to communicate with the real hardware to the IP Addresses used by the hardware in the simulation.

The available functionality is as follows:

Send data to and from Gazebo using ROS publishers and subscribers

This example shows how to communicate with a Turtlebot in the Gazebo Simulator:

Open Example: Communicating with the Turtlebot

Read Model and Simulation Properties from Gazebo

This example shows how to read simulation properties from Gazebo, such as the physics settings.

Open Example: Reading Model and Simulation Properties from Gazebo

Adding, Building and Removing Objects from Gazebo

Obstacles, robots and other objects can be added and removed from the the Gazebo Simulation Environment using MATLAB Commands. This is useful to add obstacles, robots and other objects to the simulation environment.

For instance, to add a sphere to a Gazebo Model, use the addLink and spawnModel commands:

Open Example: Adding, building, and removing objects in Gazebo