How to subscribe to openni topics inside a package
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:
- 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.
- 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?
- 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?
- 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?
- 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; }
#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; }