tracker_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 
40 using namespace MatrixWrapper;
41 using namespace BFL;
42 using namespace tf;
43 using namespace std;
44 using namespace ros;
45 
46 
47 
48 
49 namespace estimation
50 {
51 // constructor
52 TrackerParticle::TrackerParticle(const string& name, unsigned int num_particles, const StatePosVel& sysnoise):
53  Tracker(name),
54  prior_(num_particles),
55  filter_(NULL),
56  sys_model_(sysnoise),
57  meas_model_(tf::Vector3(0.1, 0.1, 0.1)),
58  tracker_initialized_(false),
59  num_particles_(num_particles)
60 {};
61 
62 
63 
64 // destructor
66 {
67  if (filter_) delete filter_;
68 };
69 
70 
71 // initialize prior density of filter
72 void TrackerParticle::initialize(const StatePosVel& mu, const StatePosVel& sigma, const double time)
73 {
74  cout << "Initializing tracker with " << num_particles_ << " particles, with covariance "
75  << sigma << " around " << mu << endl;
76 
77 
78  GaussianPosVel gauss_pos_vel(mu, sigma);
79  vector<Sample<StatePosVel> > prior_samples(num_particles_);
80  gauss_pos_vel.SampleFrom(prior_samples, num_particles_, CHOLESKY, NULL);
81  prior_.ListOfSamplesSet(prior_samples);
82  filter_ = new BootstrapFilter<StatePosVel, tf::Vector3>(&prior_, &prior_, 0, num_particles_ / 4.0);
83 
84  // tracker initialized
85  tracker_initialized_ = true;
86  quality_ = 1;
87  filter_time_ = time;
88  init_time_ = time;
89 }
90 
91 
92 
93 
94 // update filter prediction
95 bool TrackerParticle::updatePrediction(const double time)
96 {
97  bool res = true;
98  if (time > filter_time_)
99  {
100  // set dt in sys model
101  sys_model_.SetDt(time - filter_time_);
102  filter_time_ = time;
103 
104  // update filter
105  res = filter_->Update(&sys_model_);
106  if (!res) quality_ = 0;
107  }
108  return res;
109 };
110 
111 
112 
113 // update filter correction
114 bool TrackerParticle::updateCorrection(const tf::Vector3& meas, const MatrixWrapper::SymmetricMatrix& cov)
115 {
116  assert(cov.columns() == 3);
117 
118  // set covariance
119  ((MeasPdfPos*)(meas_model_.MeasurementPdfGet()))->CovarianceSet(cov);
120 
121  // update filter
122  bool res = filter_->Update(&meas_model_, meas);
123  if (!res) quality_ = 0;
124 
125  return res;
126 };
127 
128 
129 // get evenly spaced particle cloud
130 void TrackerParticle::getParticleCloud(const tf::Vector3& step, double threshold, sensor_msgs::PointCloud& cloud) const
131 {
132  ((MCPdfPosVel*)(filter_->PostGet()))->getParticleCloud(step, threshold, cloud);
133 };
134 
135 
136 // get most recent filter posterior
138 {
139  est = ((MCPdfPosVel*)(filter_->PostGet()))->ExpectedValueGet();
140 };
141 
142 
143 void TrackerParticle::getEstimate(people_msgs::PositionMeasurement& est) const
144 {
145  StatePosVel tmp = filter_->PostGet()->ExpectedValueGet();
146 
147  est.pos.x = tmp.pos_[0];
148  est.pos.y = tmp.pos_[1];
149  est.pos.z = tmp.pos_[2];
150 
151  est.header.stamp.fromSec(filter_time_);
152  est.object_id = getName();
153 }
154 
155 
156 
157 
158 
160 Matrix TrackerParticle::getHistogramPos(const tf::Vector3& min, const tf::Vector3& max, const tf::Vector3& step) const
161 {
162  return ((MCPdfPosVel*)(filter_->PostGet()))->getHistogramPos(min, max, step);
163 };
164 
165 
166 Matrix TrackerParticle::getHistogramVel(const tf::Vector3& min, const tf::Vector3& max, const tf::Vector3& step) const
167 {
168  return ((MCPdfPosVel*)(filter_->PostGet()))->getHistogramVel(min, max, step);
169 };
170 
171 
173 {
175  return filter_time_ - init_time_;
176  else
177  return 0;
178 }
179 
180 
182 {
184  return filter_time_;
185  else
186  return 0;
187 }
188 }; // namespace
189 
190 
191 
const std::string & getName() const
return the name of the tracker
Definition: tracker.h:59
void SetDt(double dt)
virtual double getLifetime() const
return the lifetime of the tracker
virtual void getEstimate(BFL::StatePosVel &est) const
get filter posterior
Class representing state with pos and vel.
Definition: state_pos_vel.h:46
virtual ~TrackerParticle()
destructor
virtual void initialize(const BFL::StatePosVel &mu, const BFL::StatePosVel &sigma, const double time)
initialize tracker
BFL::BootstrapFilter< BFL::StatePosVel, tf::Vector3 > * filter_
virtual bool updatePrediction(const double time)
update tracker
virtual bool updateCorrection(const tf::Vector3 &meas, const MatrixWrapper::SymmetricMatrix &cov)
Class representing gaussian pos_vel.
TFSIMD_FORCE_INLINE const tfScalar & z() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
MatrixWrapper::Matrix getHistogramVel(const tf::Vector3 &min, const tf::Vector3 &max, const tf::Vector3 &step) const
void getParticleCloud(const tf::Vector3 &step, double threshold, sensor_msgs::PointCloud &cloud) const
MatrixWrapper::Matrix getHistogramPos(const tf::Vector3 &min, const tf::Vector3 &max, const tf::Vector3 &step) const
Get histogram from certain area.
BFL::SysModelPosVel sys_model_
virtual double getTime() const
return the time of the tracker
tf::Vector3 pos_
Definition: state_pos_vel.h:49
bool SampleFrom(vector< Sample< StatePosVel > > &list_samples, const int num_samples, int method=DEFAULT, void *args=NULL) const
Class representing a posvel mcpdf.
Definition: mcpdf_pos_vel.h:48


people_tracking_filter
Author(s): Caroline Pantofaru
autogenerated on Fri Jun 7 2019 22:07:49