detector_particle.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Wim Meeussen */
36 
39 #include <vector>
40 
41 namespace estimation
42 {
43 using MatrixWrapper::Matrix;
44 
45 // constructor
46 DetectorParticle::DetectorParticle(unsigned int num_particles):
47  prior_(num_particles),
48  filter_(NULL),
49  sys_model_(tf::Vector3(0.1, 0.1, 0.1)),
50  meas_model_(tf::Vector3(0.1, 0.1, 0.1)),
51  detector_initialized_(false),
52  num_particles_(num_particles)
53 {}
54 
55 // destructor
57 {
58  if (filter_) delete filter_;
59 }
60 
61 // initialize prior density of filter
62 void DetectorParticle::initialize(const tf::Vector3& mu, const tf::Vector3& size, const double time)
63 {
64  std::cout << "Initializing detector with " << num_particles_ << " particles, with uniform size "
65  << size << " around " << mu << std::endl;
66 
67  BFL::UniformVector uniform_vector(mu, size);
68  std::vector<BFL::Sample<tf::Vector3> > prior_samples(num_particles_);
69  uniform_vector.SampleFrom(prior_samples, num_particles_, CHOLESKY, NULL);
70  prior_.ListOfSamplesSet(prior_samples);
72 
73  // detector initialized
74  detector_initialized_ = true;
75  quality_ = 1;
76  filter_time_ = time;
77 }
78 
79 // update filter prediction
81 {
82  // set de in sys model
83  sys_model_.SetDt(dt);
84 
85  // update filter
86  bool res = filter_->Update(&sys_model_);
87  if (!res) quality_ = 0;
88 
89  return res;
90 }
91 
92 // update filter correction
93 bool DetectorParticle::updateCorrection(const tf::Vector3& meas, const MatrixWrapper::SymmetricMatrix& cov,
94  const double time)
95 {
96  assert(cov.columns() == 3);
97 
98  // set filter time
99  filter_time_ = time;
100 
101  // set covariance
102  static_cast<BFL::MeasPdfVector*>(meas_model_.MeasurementPdfGet())->CovarianceSet(cov);
103 
104  // update filter
105  bool res = filter_->Update(&meas_model_, meas);
106  if (!res) quality_ = 0;
107 
108  return res;
109 }
110 
111 // get evenly spaced particle cloud
112 void DetectorParticle::getParticleCloud(const tf::Vector3& step, double threshold, sensor_msgs::PointCloud& cloud) const
113 {
114  static_cast<BFL::MCPdfVector*>(filter_->PostGet())->getParticleCloud(step, threshold, cloud);
115 }
116 
117 // get most recent filter posterior
119 {
120  est = static_cast<BFL::MCPdfVector*>(filter_->PostGet())->ExpectedValueGet();
121 }
122 
123 void DetectorParticle::getEstimate(people_msgs::PositionMeasurement& est) const
124 {
125  tf::Vector3 tmp = filter_->PostGet()->ExpectedValueGet();
126 
127  est.pos.x = tmp[0];
128  est.pos.y = tmp[1];
129  est.pos.z = tmp[2];
130 
131  est.header.stamp.fromSec(filter_time_);
132  est.header.frame_id = "base_link";
133 }
134 
136 Matrix DetectorParticle::getHistogram(const tf::Vector3& min, const tf::Vector3& max, const tf::Vector3& step) const
137 {
138  return static_cast<BFL::MCPdfVector*>(filter_->PostGet())->getHistogram(min, max, step);
139 }
140 } // namespace estimation
void getParticleCloud(const tf::Vector3 &step, double threshold, sensor_msgs::PointCloud &cloud) const
virtual MCPdf< StateVar > * PostGet()
bool ListOfSamplesSet(const vector< WeightedSample< T > > &list_of_samples)
Class representing uniform vector.
void getEstimate(tf::Vector3 &est) const
get filter posterior
DetectorParticle(unsigned int num_particles)
constructor
bool SampleFrom(vector< Sample< tf::Vector3 > > &list_samples, const int num_samples, int method=DEFAULT, void *args=NULL) const
void SetDt(double dt)
TFSIMD_FORCE_INLINE const tfScalar & z() const
BFL::BootstrapFilter< tf::Vector3, tf::Vector3 > * filter_
TFSIMD_FORCE_INLINE Vector3()
TFSIMD_FORCE_INLINE const tfScalar & y() const
Class representing a vector mcpdf.
Definition: mcpdf_vector.h:47
BFL::MeasModelVector meas_model_
bool updatePrediction(const double dt)
update detector
MatrixWrapper::Matrix getHistogram(const tf::Vector3 &min, const tf::Vector3 &max, const tf::Vector3 &step) const
Get histogram from certain area.
ConditionalPdf< MeasVar, StateVar > * MeasurementPdfGet()
#define CHOLESKY
virtual bool Update(SystemModel< StateVar > *const sysmodel, const StateVar &u, MeasurementModel< MeasVar, StateVar > *const measmodel, const MeasVar &z, const StateVar &s)
bool updateCorrection(const tf::Vector3 &meas, const MatrixWrapper::SymmetricMatrix &cov, const double time)
void initialize(const tf::Vector3 &mu, const tf::Vector3 &size, const double time)
initialize detector
BFL::SysModelVector sys_model_


people_tracking_filter
Author(s): Caroline Pantofaru
autogenerated on Sun Feb 21 2021 03:56:47