ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Where to find what to include in C++?

asked 2016-10-09 11:50:59 -0500

Almost gravatar image

Hi everyone

In every piece of code, be it on the wiki or forums, everyone seems to automatically know what .h files to include for whatever ROS functionality they are using, be it some special nodes, services, messages, functions, whatever. I have no idea how to find what I should include. What is the key??

Say I want to write code such as in Writing a tf listener (C++)) tutorial. How do I deduce that "tf/transform_listener.h" exists and I want to use it? Or what should I include if I want to use code from an answer relevant to what I currently do:

tf::Pose pose;
tf::poseMsgToTF(odom->pose.pose, pose);
double yaw_angle = tf::getYaw(pose.getRotation());

The only principle I have found so far is to include exact message type with .h, e.g.

#include "nav_msgs/OccupancyGrid.h"

So how does everyone do it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-10-09 13:35:30 -0500

ahendrix gravatar image

For ROS message types, your observation is correct; the include file name is the package name and the message name.

Most packages will put their functions in a C++ namespace that matches the package name, so the namespace that a function is in can often guide you to the right package. (moveit is a common exception to this, but there are also a few others)

Most packages have a "Code API" link on the right sidebar of the wiki page (see: Navigating the ROS Wiki ). These docs usually include the header name for each function, and more detailed information about how to use each function.

Some packages also have API usage examples directly on their wiki page, or under their Tutorials pages, or on their own website.

You can also use google to search for the function name, which will usually find the Code API docs, or you can search your local disk with the grep command-line tool. (Keep in mind that grep is a simple string-matching program, so you'll have to search for the function name without the namespace, like: grep -r poseToMsgTf /opt/ros/indigo/include , and then you'll have to look through each match to find the one that actually defines the function)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-10-09 11:50:59 -0500

Seen: 195 times

Last updated: Oct 09 '16