Difference between revisions of "ROS"
(→Topics) |
(→Topics) |
||
Line 33: | Line 33: | ||
'''How can I interact with topics from the command line?''' | '''How can I interact with topics from the command line?''' | ||
You can interact with topics from the command line using <code>rostopic</code>. This tool can be used to display active topics, the publishers and subscribers of a specific topic, the publishing rate of a topic, the bandwidth of a topic, and messages published to a topic. Here is a list of supported commands: <br> | You can interact with topics from the command line using <code>rostopic</code>. This tool can be used to display active topics, the publishers and subscribers of a specific topic, the publishing rate of a topic, the bandwidth of a topic, and messages published to a topic. Here is a list of supported commands: <br> | ||
− | <pre>rostopic bw display bandwidth used by topic | + | <pre>rostopic bw display bandwidth used by topic |
− | rostopic delay display delay for topic which has header | + | rostopic delay display delay for topic which has header |
− | rostopic echo print messages to screen | + | rostopic echo print messages to screen |
− | rostopic find find topics by type | + | rostopic find find topics by type |
− | rostopic hz display publishing rate of topic | + | rostopic hz display publishing rate of topic |
− | rostopic info print information about active topic | + | rostopic info print information about active topic |
− | rostopic list print information about active topics | + | rostopic list print information about active topics |
− | rostopic pub publish data to topic | + | rostopic pub publish data to topic |
rostopic type print topic type</pre> | rostopic type print topic type</pre> | ||
Revision as of 03:37, 11 May 2019
We use ROS to send messages between the Pi and the Due. As of April 2019, we use the Indigo Igloo version, released in 2014, on the Pi.
Starting ROS and roscore
What is roscore? roscore is a collection of nodes and programs that are prerequisites of a ROS-based system. You must have a roscore running in order for ROS nodes to communicate. For more information on ROS nodes, see below.
Nodes
A node is a process that performs computation. Each node is an independent part of your application, and they can be combined together into a graph. A robot control system will usually comprise many nodes.
Nodes can communicate with other nodes through ROS communication tools (topics, services, and actions).
Nodes provide several benefits. For one, there is fault tolerance - crashes are isolated to individual nodes. Code complexity is also reduced compared to monolithic systems. Finally, implementation details are well hidden as the nodes expose a minimal API to the rest of the graph.
How do I start a new node?
There are two levels of initialization for a roscpp Node.
First, you can initialize a node through a call to one of the ros::init()
functions.
Second, the node is started through the creation of a ros::NodeHandle
.
How do I interact with nodes? Nodes can communicate with each other through messages, a data structure comprising of typed fields such as integers, floating points, and booleans. Nodes can publish messages to a topic or subscribe to a topic to receive messages. For more information about topics, see the section below.
How do I shut down a node?
At any time, you can call the ros::shutdown()
function to shut down your node. This function will shut down all open subscriptions, publications, service calls, and service servers. You can also check the various states of shut down using ros::ok
which returns false once the node has finished shutting down, or ros::isShuttingDown()
which returns true as soon as ros::shutdown()
is called.
How do I shut down all nodes?
Typing rosnode kill -a
in the terminal will terminate all your nodes. However, this will only work if your roscore
is still running. Otherwise, it will not be able to find the running nodes.
rosserial_arduino
rosserial is a protocol for wrapping ROS services over a device like a serial port or network socket. In particular, we use rosserial_arduino because it allows us to easily get ROS nodes running on Arduino.
Topics
A topic is a name that is used to identify the contents of a message. Messages are routed using a publish/subscribe model. A node sends out messages by publishing it to a given topic, and a node that is interested in the specific kind of data will subscribe to the appropriate topic.
How can I interact with topics from the command line?
You can interact with topics from the command line using rostopic
. This tool can be used to display active topics, the publishers and subscribers of a specific topic, the publishing rate of a topic, the bandwidth of a topic, and messages published to a topic. Here is a list of supported commands:
rostopic bw display bandwidth used by topic rostopic delay display delay for topic which has header rostopic echo print messages to screen rostopic find find topics by type rostopic hz display publishing rate of topic rostopic info print information about active topic rostopic list print information about active topics rostopic pub publish data to topic rostopic type print topic type
(how can I interact with topics using nodes?)
Messages
(what's a message (aka a data type for a topic, service, etc)?)
(what are the most helpful available message types?)
(how do I work with Float32MultiArrays in Python and C++, since that's the most frequently used message?)
(how do I create my own message?)