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

How to subscribe to openni topics inside a package

asked 2014-01-27 01:42:17 -0500

Latif Anjum gravatar image

updated 2016-10-24 09:02:19 -0500

ngrennan gravatar image

Hi all,

I have ros-fuerte, ros-fuerte-openni-camera, ros-fuerte-openni-launch installed. I can launch openni from terminal and using rostopic echo /topic_name, I can get all data. The data is also visible on rviz.

Now, I need to use this data inside a program (for example in a cpp file) and I am unable to find out how. Here is what I did:

  1. I created a package using roscreate-pkg, and tried putting some cpp files inside src and all compiled and run successfully after amending my CMakeLists.txt. I successfully subscribed to some turtlesim topics inside the cpp file.
  2. Now I tried to subscribe to an openni topic (cpp file attached). My first question is: Why openni-camera is located at ros/stack/openni rather than ros/include/... just like other packages (opencv and pcl)? Does it make any difference where actually openni is installed?
  3. Because openni is installed at ros/stacks/ I have to manually give path to include its .h files (see #include in cpp file). Is it right approach?
  4. The cpp file just does not compile with the error (fatal error: XnCppWrapper.h: No such file or directory). I tried to search my computer and couldnt find XnCppWrapper.h. Where is that file located and why my program cant find it?
  5. Do I need to set a path for ros to use openni while compiling a cpp file inside a package

I am pretty confused and have spent a lot of time on it without any success. Any help to clarify will be appreciated a lot.

#include "ros/ros.h" #include "std_msgs/String.h" #include </opt>

void OpenniCallback(const sensor_msgs::PointCloud2::ConstPtr& msg) { ROS_INFO("I heard")//: [%f]", msg->linear, msg->angular); //ROS_INFO("I heard"); }

int main(int argc, char **argv) {

ros::init(argc, argv, "openni_subscriber"); ros::NodeHandle n;

ros::Subscriber sub = n.subscribe("/camera/depth/points", 1000, OpenniCallback); ros::spin();

return 0; }

edit retag flag offensive close merge delete

Comments

#include "ros/ros.h" #include "std_msgs/String.h" #include </opt> void OpenniCallback(const sensor_msgs::PointCloud2::ConstPtr& msg) { ROS_INFO("I heard")//: [%f]", msg->linear, msg->angular); //ROS_INFO("I heard"); } int main(int argc, char **argv) { ros::init(argc, argv, "openni_subscriber"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/camera/depth/points", 1000, OpenniCallback); ros::spin(); return 0; }

Latif Anjum gravatar image Latif Anjum  ( 2014-01-27 01:43:14 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-01-27 05:07:24 -0500

It doesn't really matter where openni is installed. As long as your manifest, CMakeLists, and ROS environment variables are correct, you shouldn't have a problem. Also, you should not be having to include paths to get things to compile.

What you are trying to do doesn't really have much to do with the openni package. The openni package will connect to your depth camera and produce the topic /camera/depth/points. It seems that you are trying to subscribe to that topic. So your package should depend on packages like sensor_msgs, pcl, and maybe pcl_ros.

Here is a manifest.xml

<package>
  <depend package="roscpp"/>    
  <depend package="sensor_msgs"/>
</package>

Here is a CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

set(ROS_BUILD_TYPE Release)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_add_executable(openni_subscriber src/openni_subscriber.cpp)

Here is a slightly modified version of your code that compiles and works correctly:

#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>

void OpenniCallback(const sensor_msgs::PointCloud2ConstPtr &msg)
{
    ROS_INFO("I heard");
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "openni_subscriber");
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("/camera/depth/points", 1, OpenniCallback);
    ros::spin();
    return 0;
}

Check out this page to see examples of how to subscribe to Point Cloud messages, and this page for more complete examples on using PCL with ROS.

edit flag offensive delete link more

Comments

Thank you sir. You did solve the problem. Looking forward to your guidance in future as well.

Latif Anjum gravatar image Latif Anjum  ( 2014-01-27 21:30:08 -0500 )edit

The statement #include <pcl_ros point_cloud.h=""> gives an error. It says no such file. This file is actually located in my case at pcl-1.5/pcl/point_cloud.h. I gave this path but there are now other errors. Same is the case with #include <pcl point_types.h="">. Any guidance?

Latif Anjum gravatar image Latif Anjum  ( 2014-01-27 22:30:23 -0500 )edit
0

answered 2014-01-27 22:33:29 -0500

Latif Anjum gravatar image

The statement #include <pcl_ros/point_cloud.h> gives an error. It says no such file. This file is actually located in my case at pcl-1.5/pcl/point_cloud.h. I gave this path but there are now other errors. Same is the case with #include <pcl/point_types.h>. Any guidance?

edit flag offensive delete link more

Comments

You should not create a new answer. It is much preferred to edit your original question. You won't be able to include pcl or pcl_ros header files unless they are included in the manifest.xml. I'm guessing this is your problem.

jarvisschultz gravatar image jarvisschultz  ( 2014-01-28 04:33:13 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-27 01:42:17 -0500

Seen: 611 times

Last updated: Jan 27 '14