target.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2020 Northwestern University
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 are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *********************************************************************/
39 #include <cmath>
40 
43 
44 namespace ergodic_exploration
45 {
46 using arma::distr_param;
47 using arma::ivec;
48 using arma::randi;
49 
51 {
52 }
53 
54 Target::Target(const GaussianList& gaussians) : gaussians_(gaussians)
55 {
56 }
57 
59 {
60  gaussians_.emplace_back(g);
61 }
62 
63 void Target::deleteGaussian(unsigned int idx)
64 {
65  gaussians_.erase(gaussians_.begin() + idx);
66 }
67 
68 double Target::evaluate(const vec& pt, const vec& trans) const
69 {
70  auto val = 0.0;
71  for (const auto& gaussian : gaussians_)
72  {
73  val += gaussian(pt, trans);
74  }
75  return val;
76 }
77 
78 vec Target::fill(const vec& trans, const mat& phi_grid) const
79 {
80  vec phi_vals(phi_grid.n_cols);
81  for (unsigned int i = 0; i < phi_grid.n_cols; i++)
82  {
83  phi_vals(i) = evaluate(phi_grid.col(i), trans);
84  }
85 
86  // normalize distribution values to sum to 1
87  phi_vals /= sum(phi_vals);
88  return phi_vals;
89 }
90 
91 visualization_msgs::MarkerArray Target::markers(const std::string& frame) const
92 {
93  visualization_msgs::MarkerArray marker_array;
94  marker_array.markers.resize(gaussians_.size());
95 
96  for (unsigned int i = 0; i < gaussians_.size(); i++)
97  {
98  const vec eigval = eig_sym(gaussians_.at(i).cov);
99 
100  marker_array.markers.at(i).header.frame_id = frame;
101  marker_array.markers.at(i).id = i;
102  marker_array.markers.at(i).type = visualization_msgs::Marker::SPHERE;
103  marker_array.markers.at(i).action = visualization_msgs::Marker::ADD;
104  marker_array.markers.at(i).pose.position.x = gaussians_.at(i).mu(0);
105  marker_array.markers.at(i).pose.position.y = gaussians_.at(i).mu(1);
106  marker_array.markers.at(i).pose.orientation.w = 1.0;
107  marker_array.markers.at(i).scale.x = 2.0 * eigval(0);
108  marker_array.markers.at(i).scale.y = 2.0 * eigval(1);
109  marker_array.markers.at(i).scale.z = 0.01;
110  marker_array.markers.at(i).lifetime = ros::Duration(0.0);
111  ;
112  marker_array.markers.at(i).color.r = 1.0;
113  marker_array.markers.at(i).color.g = 1.0;
114  marker_array.markers.at(i).color.b = 0.6;
115  marker_array.markers.at(i).color.a = 0.5;
116  }
117 
118  return marker_array;
119 }
120 } // namespace ergodic_exploration
target.hpp
Target distribution.
ergodic_exploration::Target::markers
visualization_msgs::MarkerArray markers(const std::string &frame) const
Visualize target distribution.
Definition: target.cpp:91
ergodic_exploration::Target::gaussians_
GaussianList gaussians_
Definition: target.hpp:160
ergodic_exploration::Target::evaluate
double evaluate(const vec &pt, const vec &trans) const
Evaluate the list of gaussians.
Definition: target.cpp:68
ergodic_exploration::Target::Target
Target()
Constructor.
Definition: target.cpp:50
ergodic_exploration::Target::addGaussian
void addGaussian(const Gaussian &g)
Adds gaussian to list.
Definition: target.cpp:58
ergodic_exploration
Definition: basis.hpp:43
ergodic_exploration::Target::deleteGaussian
void deleteGaussian(unsigned int idx)
Remove gaussian from list.
Definition: target.cpp:63
ergodic_exploration::Gaussian
2D gaussian
Definition: target.hpp:56
numerics.hpp
Useful numerical utilities.
ergodic_exploration::Target::fill
vec fill(const vec &trans, const mat &phi_grid) const
Evaluate the target distribution.
Definition: target.cpp:78
ergodic_exploration::GaussianList
std::vector< Gaussian > GaussianList
Definition: target.hpp:52
ros::Duration


ergodic_exploration
Author(s): bostoncleek
autogenerated on Wed Mar 2 2022 00:17:13