Connect to ROS network
rosinit
starts the global ROS node with
a default MATLAB® name and tries to connect to a ROS master running
on localhost
and port 11311
.
If the global ROS node cannot connect to the ROS master, rosinit
also
starts a ROS core in MATLAB, which consists of a ROS master,
a ROS parameter server, and a rosout logging node.
Note
The first time you connect to a ROS network, you must install and setup
Python 2.7. To check your Python® version in MATLAB, use the pyenv
function. For more information, see ROS System Requirements.
rosinit(
tries
to connect to the ROS master at the host name or IP address specified
by hostname
)hostname
. This syntax uses 11311
as
the default port number.
rosinit(
tries to connect to the ROS master at
the given resource identifier, URI
)URI
, for example,
"http://192.168.1.1:11311"
.
rosinit(___,Name,Value)
provides additional options specified
by one or more Name,Value
pair arguments.
Using rosinit
is a prerequisite for most
ROS-related tasks in MATLAB because:
Communicating with a ROS network requires a ROS node connected to a ROS master.
By default, ROS functions in MATLAB operate on the global ROS node, or they operate on objects that depend on the global ROS node.
For example, after creating a global ROS node with rosinit
,
you can subscribe to a topic on the global ROS node. When another
node on the ROS network publishes messages on that topic, the global
ROS node receives the messages.
If a global ROS node already exists, then rosinit
restarts
the global ROS node based on the new set of arguments.
For more advanced ROS networks, connecting to multiple ROS nodes or masters is
possible using the Node
object.