ROS Network Setup
Setting up a ROS network enables communication between different devices. These participants, or nodes, all register with a ROS master to share information. Each ROS network has only one, unique master. Each node is usually a separate device, although one device can have multiple nodes running. MATLAB® acts as one of these nodes when communicating on an existing ROS Network.
All devices must be connected to the same actual or virtual network for ROS connections to
work. You can create a new ROS master in MATLAB, or you can connect to an existing ROS master that is running on a
different device. If you connect to an external master, you have to know the IP address
or hostname of the device. The initial ROS master connection is created by calling
rosinit. For more information on setting
up and using the ROS network, see Network Connection and Exploration.
Nodes communicate by sending messages using entities called publishers, subscribers, and services. Publishers send data using topic names, which subscribers then receive over the network. Services use clients to request information from a server. For more information on sending messages, see Publishers and Subscribers.
Network Connection Layout
The ROS network is a collection of nodes that are all connected to the ROS master. The number of nodes can be quite large depending on your application and devices. Nodes that are registered with the master can communicate with all other registered nodes. Each node registers different publishers, subscribers, and services on the ROS master to send and receive information between nodes. Even though all nodes in the ROS network are registered with the master, data is exchanged directly between nodes. The following figure shows the layout of a ROS network with two ROS nodes. All nodes must have bidirectional connectivity to share data across the network. Verifying these connections is important during setup.
Each node registers its own Node URI with the master. Other participants
in the ROS network will use this URI to contact the node. Again, this URI must be
reachable by every other node in the ROS network. To create a node in MATLAB, call
rosinit. If a ROS master is already set
up, MATLAB detects it and sets the Node URI appropriately. Otherwise, it creates both
a ROS master and node that are connected.
By default, each MATLAB instance has a single global node. The node has a randomly generated name assigned to it for uniqueness. All publishers, subscribers, service clients, and service servers operate on this global node.