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 #include <string>
40 #include <vector>
41 
42 namespace estimation
43 {
44 using MatrixWrapper::Matrix;
45 
46 // constructor
47 TrackerParticle::TrackerParticle(const std::string& name, unsigned int num_particles, const BFL::StatePosVel& sysnoise):
48  Tracker(name),
49  prior_(num_particles),
50  filter_(NULL),
51  sys_model_(sysnoise),
52  meas_model_(tf::Vector3(0.1, 0.1, 0.1)),
53  tracker_initialized_(false),
54  num_particles_(num_particles)
55 {}
56 
57 // destructor
59 {
60  if (filter_) delete filter_;
61 }
62 
63 // initialize prior density of filter
64 void TrackerParticle::initialize(const BFL::StatePosVel& mu, const BFL::StatePosVel& sigma, const double time)
65 {
66  std::cout << "Initializing tracker with " << num_particles_ << " particles, with covariance "
67  << sigma << " around " << mu << std::endl;
68 
69  BFL::GaussianPosVel gauss_pos_vel(mu, sigma);
70  std::vector<BFL::Sample<BFL::StatePosVel> > prior_samples(num_particles_);
71  gauss_pos_vel.SampleFrom(prior_samples, num_particles_, CHOLESKY, NULL);
72  prior_.ListOfSamplesSet(prior_samples);
74 
75  // tracker initialized
76  tracker_initialized_ = true;
77  quality_ = 1;
78  filter_time_ = time;
79  init_time_ = time;
80 }
81 
82 // update filter prediction
83 bool TrackerParticle::updatePrediction(const double time)
84 {
85  bool res = true;
86  if (time > filter_time_)
87  {
88  // set dt in sys model
90  filter_time_ = time;
91 
92  // update filter
93  res = filter_->Update(&sys_model_);
94  if (!res) quality_ = 0;
95  }
96  return res;
97 };
98 
99 // update filter correction
100 bool TrackerParticle::updateCorrection(const tf::Vector3& meas, const MatrixWrapper::SymmetricMatrix& cov)
101 {
102  assert(cov.columns() == 3);
103 
104  // set covariance
105  static_cast<BFL::MeasPdfPos*>(meas_model_.MeasurementPdfGet())->CovarianceSet(cov);
106 
107  // update filter
108  bool res = filter_->Update(&meas_model_, meas);
109  if (!res) quality_ = 0;
110 
111  return res;
112 };
113 
114 // get evenly spaced particle cloud
115 void TrackerParticle::getParticleCloud(const tf::Vector3& step, double threshold, sensor_msgs::PointCloud& cloud) const
116 {
117  static_cast<BFL::MCPdfPosVel*>(filter_->PostGet())->getParticleCloud(step, threshold, cloud);
118 };
119 
120 // get most recent filter posterior
122 {
123  est = static_cast<BFL::MCPdfPosVel*>(filter_->PostGet())->ExpectedValueGet();
124 };
125 
126 void TrackerParticle::getEstimate(people_msgs::PositionMeasurement& est) const
127 {
128  BFL::StatePosVel tmp = filter_->PostGet()->ExpectedValueGet();
129 
130  est.pos.x = tmp.pos_[0];
131  est.pos.y = tmp.pos_[1];
132  est.pos.z = tmp.pos_[2];
133 
134  est.header.stamp.fromSec(filter_time_);
135  est.object_id = getName();
136 }
137 
139 Matrix TrackerParticle::getHistogramPos(const tf::Vector3& min, const tf::Vector3& max, const tf::Vector3& step) const
140 {
141  return static_cast<BFL::MCPdfPosVel*>(filter_->PostGet())->getHistogramPos(min, max, step);
142 };
143 
144 Matrix TrackerParticle::getHistogramVel(const tf::Vector3& min, const tf::Vector3& max, const tf::Vector3& step) const
145 {
146  return static_cast<BFL::MCPdfPosVel*>(filter_->PostGet())->getHistogramVel(min, max, step);
147 };
148 
150 {
152  return filter_time_ - init_time_;
153  else
154  return 0;
155 }
156 
158 {
160  return filter_time_;
161  else
162  return 0;
163 }
164 } // namespace estimation
const std::string & getName() const
return the name of the tracker
Definition: tracker.h:59
virtual MCPdf< StateVar > * PostGet()
void SetDt(double dt)
virtual double getLifetime() const
return the lifetime of the tracker
bool ListOfSamplesSet(const vector< WeightedSample< T > > &list_of_samples)
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_
TrackerParticle(const std::string &name, unsigned int num_particles, const BFL::StatePosVel &sysnoise)
constructor
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 Vector3()
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.
ConditionalPdf< MeasVar, StateVar > * MeasurementPdfGet()
#define CHOLESKY
BFL::SysModelPosVel sys_model_
virtual double getTime() const
return the time of the tracker
tf::Vector3 pos_
Definition: state_pos_vel.h:49
virtual bool Update(SystemModel< StateVar > *const sysmodel, const StateVar &u, MeasurementModel< MeasVar, StateVar > *const measmodel, const MeasVar &z, const StateVar &s)
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 Sun Feb 21 2021 03:56:47