logging.cpp
Go to the documentation of this file.
2 
3 namespace toposens_pointcloud
4 {
6 {
7  int pcd_save_interval = 0;
8  std::string target_frame;
9  private_nh.param<int>("pcd_save_interval", pcd_save_interval, 0);
10  private_nh.param<std::string>("target_frame", target_frame, "toposens");
11  private_nh.param<std::string>("pcd_path", pcd_path_, "");
12 
16  if (pcd_path_ == "") pcd_path_ = std::string(get_current_dir_name()) + "/" + "toposens.pcd";
17 
19 
20  timer_ = nh.createTimer(ros::Duration(pcd_save_interval), &Logging::save,
21  this); // continuous timer
22 
23  store_ = boost::make_shared<XYZINCloud>();
25  store_->header.frame_id = target_frame;
26  store_->height = 1;
27 }
28 
30 
31 void Logging::save(const ros::TimerEvent &event)
32 {
33  boost::mutex::scoped_lock lock(store_mutex_);
34 
35  if (!store_->width)
36  {
37  ROS_WARN("No pointcloud data to save.");
38  return;
39  }
41  try
42  {
44  {
45  ROS_INFO("Saved latest point cloud data (%s)", pcd_path_.c_str());
46  }
47  }
48  catch (pcl::io::IOException &e)
49  {
50  ROS_ERROR("%s", e.what());
51  }
52 }
53 
54 void Logging::_accumulate(const XYZINCloud::ConstPtr &msg)
55 {
56  boost::mutex::scoped_lock lock(store_mutex_);
57 
58  for (auto it = msg->points.begin(); it != msg->points.end(); ++it)
59  {
60  pcl::PointXYZINormal pt = *it;
61  store_->points.push_back(pt);
62  }
63 
64  store_->width = store_->points.size();
65 }
66 
67 } // namespace toposens_pointcloud
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void stop()
#define ROS_WARN(...)
void _accumulate(const XYZINCloud::ConstPtr &msg)
Definition: logging.cpp:54
bool param(const std::string &param_name, T &param_val, const T &default_val) const
#define ROS_INFO(...)
void toPCL(const ros::Time &stamp, std::uint64_t &pcl_stamp)
ros::Subscriber cloud_sub_
Definition: logging.h:96
XYZINCloud::Ptr store_
Definition: logging.h:93
static const std::string kPointCloudTopic
static Time now()
Logging(ros::NodeHandle nh, ros::NodeHandle private_nh)
Definition: logging.cpp:5
#define ROS_ERROR(...)
void save(const ros::TimerEvent &event)
Definition: logging.cpp:31
int savePCDFile(const std::string &file_name, const sensor_msgs::PointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary_mode=false)
boost::mutex store_mutex_
Definition: logging.h:99


toposens_pointcloud
Author(s): Adi Singh, Sebastian Dengler, Christopher Lang, Inshal Uddin
autogenerated on Mon Feb 28 2022 23:57:49