I want the listener to stop listening to the topic from bag after 5 seconds even though the bag is running for 20seconds

asked 2021-10-19 09:20:04 -0500

santK gravatar image

updated 2021-10-19 18:11:47 -0500

Geoff gravatar image

std::deque<int> theta; // Method_1: Ros_queue std::deque<sensor_msgs::pointcloud2::constptr> queue_pc2; pcl::PointCloud<pcl::pointxyz> merged_cloud; // To publish inliers and coefts pcl::ModelCoefficients coefficients; pcl::PointIndices plane_inliers; //std::deque<sensor_msgs::pointfield[]&gt; queue_pc2;="" std::deque<int=""> queue_pc2; ros::Time initial_time; ros::Time current_time; int count=0; double min_z_overall = 10000; double max_z_overall = -10000; //RANSAC_speed_check ros::WallTime RANSAC_start_, RANSAC_end_; void chatterCallback(const sensor_msgs::PointCloud2::ConstPtr& msg) { ROS_INFO("I heard: [%i]", msg->height);// works queue_pc2.push_back(msg);

     //getting sensor msgs as input_pointcloud
     sensor_msgs::PointCloud2 input_pointcloud = *msg;

     //Conversion from sensor_msgs::PointCloud2 to pcl::PCLPointCloud2
     pcl::PCLPointCloud2 pcl_pc2;
     pcl_conversions::toPCL(*msg,pcl_pc2);
     //Conversion from pcl::PCLPointCloud2 to pcl::PointCloud<pcl::PointXYZ>
     pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
     pcl::fromPCLPointCloud2(pcl_pc2,*temp_cloud);
     std::cout<<*temp_cloud<<std::endl;

      std::cout<<"In CAll Back "<<std::endl;   
  }

int main(int argc, char **argv)
  {
      ros::init(argc, argv, "listener");
      ros::NodeHandle n;
      ros::Subscriber sub = n.subscribe("/velodyne_points", 1000, chatterCallback);
      ros::Publisher chatter_pub = n.advertise<pcl_msgs::ModelCoefficients>("chatter", 1000);
      ros::Rate loop_rate(10);

      int count1 = 0;

      ros::Time end_time = initial_time + ros::Duration(5);

      while(current_time<= (initial_time + ros::Duration(5))){

        ros::spinOnce(); 

      }

      if(current_time>(initial_time + ros::Duration(5))){



        std::cout<<"DONE! "<<std::endl;

        return 0;
      }

         pcl_msgs::ModelCoefficients ros_coefficients;
        pcl_conversions::fromPCL(coefficients, ros_coefficients);
        chatter_pub.publish (ros_coefficients);
     ros::spin();

     return 0;
  }
edit retag flag offensive close merge delete