39 #include <pcl/point_types.h> 41 #include <pcl/conversions.h> 42 #include <pcl/PCLPointCloud2.h> 51 ObservationBuffer::ObservationBuffer(
string topic_name,
double observation_keep_time,
double expected_update_rate,
52 double min_obstacle_height,
double max_obstacle_height,
double obstacle_range,
54 string sensor_frame,
double tf_tolerance) :
55 tf_(tf), observation_keep_time_(observation_keep_time), expected_update_rate_(expected_update_rate),
56 last_updated_(
ros::Time::now()), global_frame_(global_frame), sensor_frame_(sensor_frame), topic_name_(topic_name),
57 min_obstacle_height_(min_obstacle_height), max_obstacle_height_(max_obstacle_height),
58 obstacle_range_(obstacle_range), raytrace_range_(raytrace_range), tf_tolerance_(tf_tolerance)
74 ROS_ERROR(
"Transform between %s and %s with tolerance %.2f failed: %s.", new_global_frame.c_str(),
79 list<Observation>::iterator obs_it;
86 geometry_msgs::PointStamped origin;
88 origin.header.stamp = transform_time;
101 new_global_frame.c_str(), ex.what());
115 pcl::PCLPointCloud2 pcl_pc2;
118 pcl::PointCloud < pcl::PointXYZ > pcl_cloud;
119 pcl::fromPCLPointCloud2(pcl_pc2, pcl_cloud);
122 catch (pcl::PCLException& ex)
124 ROS_ERROR(
"Failed to convert a message to a pcl type, dropping observation: %s", ex.what());
154 pcl::PointCloud < pcl::PointXYZ > global_frame_cloud;
158 global_frame_cloud.header.stamp = cloud.header.stamp;
161 pcl::PointCloud < pcl::PointXYZ > &observation_cloud = *(
observation_list_.front().cloud_);
162 unsigned int cloud_size = global_frame_cloud.points.size();
163 observation_cloud.points.resize(cloud_size);
164 unsigned int point_count = 0;
167 for (
unsigned int i = 0; i < cloud_size; ++i)
172 observation_cloud.points[point_count++] = global_frame_cloud.points[i];
177 observation_cloud.points.resize(point_count);
178 observation_cloud.header.stamp = cloud.header.stamp;
179 observation_cloud.header.frame_id = global_frame_cloud.header.frame_id;
185 ROS_ERROR(
"TF Exception that should never happen for sensor frame: %s, cloud frame: %s, %s",
sensor_frame_.c_str(),
186 cloud.header.frame_id.c_str(), ex.what());
204 list<Observation>::iterator obs_it;
207 observations.push_back(*obs_it);
247 "The %s observation buffer has not been updated for %.2f seconds, and it should be updated every %.2f seconds.",
geometry_msgs::Point origin_
void getObservations(std::vector< Observation > &observations)
Pushes copies of all current observations onto the end of the vector passed in.
pcl::PointCloud< pcl::PointXYZ > * cloud_
double max_obstacle_height_
tf::TransformListener & tf_
std::string global_frame_
std::string sensor_frame_
Stores an observation in terms of a point cloud and the origin of the source.
void fromPCL(const pcl::uint64_t &pcl_stamp, ros::Time &stamp)
bool setGlobalFrame(const std::string new_global_frame)
Sets the global frame of an observation buffer. This will transform all the currently cached observat...
void bufferCloud(const sensor_msgs::PointCloud2 &cloud)
Transforms a PointCloud to the global frame and buffers it Note: The burden is on the user to make su...
~ObservationBuffer()
Destructor... cleans up.
void resetLastUpdated()
Reset last updated timestamp.
void purgeStaleObservations()
Removes any stale observations from the buffer list.
const ros::Duration expected_update_rate_
std::list< Observation > observation_list_
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const tf::Transform &transform)
const ros::Duration observation_keep_time_
double min_obstacle_height_
bool isCurrent() const
Check if the observation buffer is being update at its expected rate.
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)