rosinit

Connect to ROS network

Description

example

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.

example

rosinit(hostname) tries to connect to the ROS master at the host name or IP address specified by hostname. This syntax uses 11311 as the default port number.

rosinit(hostname,port) tries to connect to the host name or IP address specified by hostname and the port number specified by port.

rosinit(URI) tries to connect to the ROS master at the given resource identifier, URI, for example, "http://192.168.1.1:11311".

example

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.

Examples

collapse all

rosinit
Initializing ROS master on http://bat584805glnxa64:39297/.
Initializing global node /matlab_global_node_42483 with NodeURI http://bat584805glnxa64:43431/

When you are finished, shut down the ROS network.

rosshutdown
Shutting down global node /matlab_global_node_42483 with NodeURI http://bat584805glnxa64:43431/
Shutting down ROS master on http://bat584805glnxa64:39297/.

rosinit('192.168.17.128')
Initializing global node /matlab_global_node_57409 with NodeURI http://192.168.17.1:57782/

Shut down the ROS network when you are finished.

rosshutdown
Shutting down global node /matlab_global_node_57409 with NodeURI http://192.168.17.1:57782/
rosinit('192.168.17.128', 'NodeHost','192.168.17.1','NodeName','/test_node')
Initializing global node /test_node with NodeURI http://192.168.17.1:57633/

Shut down the ROS network when you are finished.

rosshutdown
Shutting down global node /test_node with NodeURI http://192.168.17.1:57633/

Input Arguments

collapse all

Host name or IP address, specified as a string scalar or character vector.

Port number used to connect to the ROS master, specified as a numeric scalar.

URI for ROS master, specified as a string scalar or character vector. Standard format for URIs is either http://ipaddress:port or http://hostname:port

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: "NodeHost","192.168.1.1"

Host name or IP address under which the node advertises itself to the ROS network, specified as the comma-separated pair consisting of "NodeHost" and a character vector.

Example: "comp-home"

Global node name, specified as the comma-separated pair consisting of "NodeName" and a character vector. The node that is created through rosinit is registered on the ROS network with this name.

Example: "NodeName","/test_node"

Introduced in R2019b