ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I think that you forgot to add the header files
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
2 | No.2 Revision |
Ok...
Here is the code that is working for me...and I hope that it will come for you.
Add these lines in CMakeLists.txt
FIND_PACKAGE(PCL 1.5)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
rosbuild_add_executable(test_file src/test_file.cpp)
rosbuild_link_boost(test_file signals)
target_link_libraries(test_file ${PCL_LIBRARIES} ${BOOST_LIBRARIES})
I dont think that you forgot there is need to add the header filesPCL..Just added to test if my file is working here...
Next in create a new package and try this thing..
/********************************* Header Files ***************************/
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
// PCL specific includes
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/transforms.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
/************************************ End of Header Files **************************/
using namespace sensor_msgs;
using namespace message_filters;
ros::Publisher pub_sub1_sub2;
void cloud_cb ( const sensor_msgs::PointCloud2ConstPtr& sub2_input,
const sensor_msgs::PointCloud2ConstPtr& sub1_input)
{
//processing
std::cout<< " I am here! " <<std::endl;
pub_sub1_sub2.publish (*sub2_input);
}
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "testing");
ros::NodeHandle nh;
ROS_INFO("Starting ");
message_filters::Subscriber<sensor_msgs::PointCloud2> sub2(nh, "topic1", 5);
message_filters::Subscriber<sensor_msgs::PointCloud2> sub1(nh, "topic2", 5);
typedef sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub2, sub1);
sync.registerCallback(boost::bind(&cloud_cb, _1, _2));
pub_sub1_sub2 = nh.advertise<sensor_msgs::PointCloud2> ("/cloud", 1);
// Spin
ros::spin ();
return 0;
}
3 | No.3 Revision |
Ok...
Here is the code that is working for me...and I hope that it will come for you.
Add these lines in CMakeLists.txt
FIND_PACKAGE(PCL 1.5)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
rosbuild_add_executable(test_file src/test_file.cpp)
rosbuild_link_boost(test_file signals)
target_link_libraries(test_file ${PCL_LIBRARIES} ${BOOST_LIBRARIES})
I dont think that there is need to add PCL..Just added to test if my file is working here...
Next in create a new package and try this thing..
/********************************* Header Files ***************************/
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
// PCL specific includes
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/transforms.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
/************************************ End of Header Files **************************/
using namespace sensor_msgs;
using namespace message_filters;
ros::Publisher pub_sub1_sub2;
void cloud_cb ( const sensor_msgs::PointCloud2ConstPtr& sub2_input,
const sensor_msgs::PointCloud2ConstPtr& sub1_input)
{
//processing
std::cout<< " I am here! " <<std::endl;
pub_sub1_sub2.publish (*sub2_input);
}
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "testing");
ros::NodeHandle nh;
ROS_INFO("Starting ");
message_filters::Subscriber<sensor_msgs::PointCloud2> sub2(nh, "topic1", 5);
message_filters::Subscriber<sensor_msgs::PointCloud2> sub1(nh, "topic2", 5);
typedef sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub2, sub1);
sync.registerCallback(boost::bind(&cloud_cb, _1, _2));
pub_sub1_sub2 = nh.advertise<sensor_msgs::PointCloud2> ("/cloud", 1);
// Spin
ros::spin ();
return 0;
}
4 | No.4 Revision |
Ok...
Here is the code that is working for me...and I hope that it will come for you.
Add these lines in CMakeLists.txt
FIND_PACKAGE(PCL 1.5)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
rosbuild_add_executable(test_file src/test_file.cpp)
rosbuild_link_boost(test_file signals)
target_link_libraries(test_file ${PCL_LIBRARIES} ${BOOST_LIBRARIES})
I dont think that there is need to add PCL..Just added to test if my file is working here...
Next in create a new package and try this thing..
/********************************* Header Files ***************************/
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
// PCL specific includes
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/transforms.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
/************************************ End of Header Files **************************/
using namespace sensor_msgs;
using namespace message_filters;
ros::Publisher pub_sub1_sub2;
void cloud_cb ( const sensor_msgs::PointCloud2ConstPtr& sub2_input,
const sensor_msgs::PointCloud2ConstPtr& sub1_input)
{
//processing
std::cout<< " I am here! " <<std::endl;
pub_sub1_sub2.publish (*sub2_input);
}
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "testing");
ros::NodeHandle nh;
ROS_INFO("Starting ");
message_filters::Subscriber<sensor_msgs::PointCloud2> sub2(nh, "topic1", 5);
message_filters::Subscriber<sensor_msgs::PointCloud2> sub1(nh, "topic2", 5);
typedef sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub2, sub1);
sync.registerCallback(boost::bind(&cloud_cb, _1, _2));
pub_sub1_sub2 = nh.advertise<sensor_msgs::PointCloud2> ("/cloud", 1);
// Spin
ros::spin ();
return 0;
}
UPDATE
Two suggestions to try.
i think you have to declare it in a different way, try something like this in declaring subscribers." message_filters::Subscriber<std_msgs::Float32<std::allocator<void> > > sub1
Look at this http://wiki.ros.org/roscpp/Overview/MessagesCustomAllocators
5 | No.5 Revision |
Ok...
Here is the code that is working for me...and I hope that it will come for you.
Add these lines in CMakeLists.txt
FIND_PACKAGE(PCL 1.5)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
rosbuild_add_executable(test_file src/test_file.cpp)
rosbuild_link_boost(test_file signals)
target_link_libraries(test_file ${PCL_LIBRARIES} ${BOOST_LIBRARIES})
I dont think that there is need to add PCL..Just added to test if my file is working here...
Next in create a new package and try this thing..
/********************************* Header Files ***************************/
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
// PCL specific includes
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/transforms.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
/************************************ End of Header Files **************************/
using namespace sensor_msgs;
using namespace message_filters;
ros::Publisher pub_sub1_sub2;
void cloud_cb ( const sensor_msgs::PointCloud2ConstPtr& sub2_input,
const sensor_msgs::PointCloud2ConstPtr& sub1_input)
{
//processing
std::cout<< " I am here! " <<std::endl;
pub_sub1_sub2.publish (*sub2_input);
}
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "testing");
ros::NodeHandle nh;
ROS_INFO("Starting ");
message_filters::Subscriber<sensor_msgs::PointCloud2> sub2(nh, "topic1", 5);
message_filters::Subscriber<sensor_msgs::PointCloud2> sub1(nh, "topic2", 5);
typedef sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub2, sub1);
sync.registerCallback(boost::bind(&cloud_cb, _1, _2));
pub_sub1_sub2 = nh.advertise<sensor_msgs::PointCloud2> ("/cloud", 1);
// Spin
ros::spin ();
return 0;
}
UPDATE
Two suggestions to try.
i think you have to declare it in a different way, try something like this in declaring subscribers." message_filters::Subscriber<std_msgs::Float32<std::allocator<void> > > sub1
Look at this http://wiki.ros.org/roscpp/Overview/MessagesCustomAllocators