48 ObservationBuffer::ObservationBuffer(
string topic_name,
double observation_keep_time,
double expected_update_rate,
49 double min_obstacle_height,
double max_obstacle_height,
double obstacle_range,
50 double raytrace_range,
tf2_ros::Buffer& tf2_buffer,
string global_frame,
51 string sensor_frame,
double tf_tolerance) :
52 tf2_buffer_(tf2_buffer), observation_keep_time_(observation_keep_time), expected_update_rate_(expected_update_rate),
53 last_updated_(
ros::Time::now()), global_frame_(global_frame), sensor_frame_(sensor_frame), topic_name_(topic_name),
54 min_obstacle_height_(min_obstacle_height), max_obstacle_height_(max_obstacle_height),
55 obstacle_range_(obstacle_range), raytrace_range_(raytrace_range), tf_tolerance_(tf_tolerance)
68 geometry_msgs::TransformStamped transformStamped;
71 ROS_ERROR(
"Transform between %s and %s with tolerance %.2f failed: %s.", new_global_frame.c_str(),
76 list<Observation>::iterator obs_it;
83 geometry_msgs::PointStamped origin;
85 origin.header.stamp = transform_time;
98 new_global_frame.c_str(), ex.what());
110 geometry_msgs::PointStamped global_origin;
121 geometry_msgs::PointStamped local_origin;
122 local_origin.header.stamp = cloud.header.stamp;
123 local_origin.header.frame_id = origin_frame;
124 local_origin.point.x = 0;
125 local_origin.point.y = 0;
126 local_origin.point.z = 0;
134 sensor_msgs::PointCloud2 global_frame_cloud;
138 global_frame_cloud.header.stamp = cloud.header.stamp;
141 sensor_msgs::PointCloud2& observation_cloud = *(
observation_list_.front().cloud_);
142 observation_cloud.height = global_frame_cloud.height;
143 observation_cloud.width = global_frame_cloud.width;
144 observation_cloud.fields = global_frame_cloud.fields;
145 observation_cloud.is_bigendian = global_frame_cloud.is_bigendian;
146 observation_cloud.point_step = global_frame_cloud.point_step;
147 observation_cloud.row_step = global_frame_cloud.row_step;
148 observation_cloud.is_dense = global_frame_cloud.is_dense;
150 unsigned int cloud_size = global_frame_cloud.height*global_frame_cloud.width;
152 modifier.
resize(cloud_size);
153 unsigned int point_count = 0;
157 std::vector<unsigned char>::const_iterator iter_global = global_frame_cloud.data.begin(), iter_global_end = global_frame_cloud.data.end();
158 std::vector<unsigned char>::iterator iter_obs = observation_cloud.data.begin();
159 for (; iter_global != iter_global_end; ++iter_z, iter_global += global_frame_cloud.point_step)
164 std::copy(iter_global, iter_global + global_frame_cloud.point_step, iter_obs);
165 iter_obs += global_frame_cloud.point_step;
171 modifier.
resize(point_count);
172 observation_cloud.header.stamp = cloud.header.stamp;
173 observation_cloud.header.frame_id = global_frame_cloud.header.frame_id;
179 ROS_ERROR(
"TF Exception that should never happen for sensor frame: %s, cloud frame: %s, %s",
sensor_frame_.c_str(),
180 cloud.header.frame_id.c_str(), ex.what());
198 list<Observation>::iterator obs_it;
201 observations.push_back(*obs_it);
240 "The %s observation buffer has not been updated for %.2f seconds, and it should be updated every %.2f seconds.",
geometry_msgs::Point origin_
T & transform(const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0)) const
void getObservations(std::vector< Observation > &observations)
Pushes copies of all current observations onto the end of the vector passed in.
double max_obstacle_height_
std::string global_frame_
std::string sensor_frame_
Stores an observation in terms of a point cloud and the origin of the source.
bool isCurrent() const
Check if the observation buffer is being update at its expected rate.
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &target_time, const ros::Duration timeout, std::string *errstr=NULL) const
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.
sensor_msgs::PointCloud2 * cloud_
const ros::Duration expected_update_rate_
std::list< Observation > observation_list_
const ros::Duration observation_keep_time_
double min_obstacle_height_
void convert(const A &a, B &b)
tf2_ros::Buffer & tf2_buffer_