0
$\begingroup$

Rosanswers logo

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/ros/fuerte/stacks/openni_camera/include/openni_camera/openni_depth_image.h>

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; }


Originally posted by Latif Anjum on ROS Answers with karma: 79 on 2014-01-27

Post score: 0


Original comments

Comment by Latif Anjum on 2014-01-27:
#include "ros/ros.h" #include "std_msgs/String.h" #include </opt/ros/fuerte/stacks/openni_camera/include/openni_camera/openni_depth_image.h>

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; }

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by jarvisschultz with karma: 9031 on 2014-01-27

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Latif Anjum on 2014-01-27:
Thank you sir. You did solve the problem. Looking forward to your guidance in future as well.

Comment by Latif Anjum on 2014-01-27:
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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.