Go to the documentation of this file.00001 #include <gtest/gtest.h>
00002
00003
00004
00005 #include <message_filters/subscriber.h>
00006 #include <message_filters/time_synchronizer.h>
00007 #include <ros/ros.h>
00008 #include <sensor_msgs/Image.h>
00009
00010 class MultiCameraTest : public testing::Test
00011 {
00012 protected:
00013 virtual void SetUp()
00014 {
00015 has_new_image_ = false;
00016 }
00017
00018 ros::NodeHandle nh_;
00019
00020
00021 message_filters::Subscriber<sensor_msgs::Image> cam_left_sub_;
00022 message_filters::Subscriber<sensor_msgs::Image> cam_right_sub_;
00023
00024 bool has_new_image_;
00025 ros::Time image_left_stamp_;
00026 ros::Time image_right_stamp_;
00027
00028
00029
00030
00031
00032
00033
00034 public:
00035 void imageCallback(
00036 const sensor_msgs::ImageConstPtr& left_msg,
00037 const sensor_msgs::ImageConstPtr& right_msg)
00038 {
00039 image_left_stamp_ = left_msg->header.stamp;
00040 image_right_stamp_ = right_msg->header.stamp;
00041 has_new_image_ = true;
00042 }
00043 };
00044
00045
00046
00047 TEST_F(MultiCameraTest, cameraSubscribeTest)
00048 {
00049
00050
00051
00052
00053
00054 cam_left_sub_.subscribe(nh_, "stereo/camera/left/image_raw", 1);
00055 cam_right_sub_.subscribe(nh_, "stereo/camera/right/image_raw", 1);
00056 message_filters::TimeSynchronizer<sensor_msgs::Image, sensor_msgs::Image> sync(
00057 cam_left_sub_, cam_right_sub_, 4);
00058 sync.registerCallback(boost::bind(&MultiCameraTest::imageCallback,
00059 dynamic_cast<MultiCameraTest*>(this), _1, _2));
00060 #if 0
00061
00062
00063
00064 bool wait_for_topic = true;
00065 while (wait_for_topic)
00066 {
00067
00068
00069
00070
00071 if (cam_sub_.getNumPublishers() > 0)
00072 wait_for_topic = false;
00073 ros::Duration(0.5).sleep();
00074 }
00075 #endif
00076
00077 while (!has_new_image_)
00078 {
00079 ros::spinOnce();
00080 ros::Duration(0.1).sleep();
00081 }
00082
00083 double sync_diff = (image_left_stamp_ - image_right_stamp_).toSec();
00084 EXPECT_EQ(sync_diff, 0.0);
00085
00086
00087
00088
00089
00090 double time_diff = (ros::Time::now() - image_left_stamp_).toSec();
00091 ROS_INFO_STREAM(time_diff);
00092 EXPECT_LT(time_diff, 1.0);
00093
00094 }
00095
00096 int main(int argc, char** argv)
00097 {
00098 ros::init(argc, argv, "gazebo_multicamera_test");
00099 testing::InitGoogleTest(&argc, argv);
00100 return RUN_ALL_TESTS();
00101 }