EndpointModel.cpp
Go to the documentation of this file.
1 // SVN $HeadURL$
2 // SVN $Id$
3 
4 /*
5  * 6D localization for humanoid robots
6  *
7  * Copyright 2009-2012 Armin Hornung, University of Freiburg
8  * http://www.ros.org/wiki/humanoid_localization
9  *
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, version 3.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 namespace humanoid_localization{
27 
29 : ObservationModel(nh, mapModel, rngEngine), m_sigma(0.2), m_maxObstacleDistance(0.5)
30 {
31  ROS_INFO("Using Endpoint observation model (precomputing...)");
32 
33  nh->param("endpoint/sigma", m_sigma, m_sigma);
34  nh->param("endpoint/max_obstacle_distance", m_maxObstacleDistance, m_maxObstacleDistance);
35 
36  if (m_sigma <= 0.0){
37  ROS_ERROR("Sigma (std.dev) needs to be > 0 in EndpointModel");
38  }
39 
41 
42 
43 }
44 
46 
47 }
48 
49 void EndpointModel::integrateMeasurement(Particles& particles, const PointCloud& pc, const std::vector<float>& ranges, float max_range, const tf::Transform& baseToSensor){
50 
51  // iterate over samples, multithreaded:
52 #pragma omp parallel for
53  for (unsigned i=0; i < particles.size(); ++i){
54  Eigen::Matrix4f globalLaserOrigin;
55  pcl_ros::transformAsMatrix(particles[i].pose * baseToSensor, globalLaserOrigin);
56  PointCloud pc_transformed;
57  pcl::transformPointCloud(pc, pc_transformed, globalLaserOrigin);
58 
59  std::vector<float>::const_iterator ranges_it = ranges.begin();
60  // iterate over beams:
61  for (PointCloud::const_iterator it = pc_transformed.begin(); it != pc_transformed.end(); ++it, ++ranges_it){
62  // search only for endpoint in tree
63  octomap::point3d endPoint(it->x, it->y, it->z);
64  float dist = m_distanceMap->getDistance(endPoint);
65  float sigma_scaled = m_sigma;
67  sigma_scaled = (*ranges_it) * (*ranges_it) * (m_sigma);
68  if (dist > 0.0){ // endpoint is inside map:
69  particles[i].weight += logLikelihood(dist, sigma_scaled);
70  } else { //assign weight of max.distance:
71  particles[i].weight += logLikelihood(m_maxObstacleDistance, sigma_scaled);
72  }
73  }
74  // TODO: handle max range measurements
75  //std::cout << "\n";
76  }
77 
78 }
79 
80 bool EndpointModel::getHeightError(const Particle& p, const tf::StampedTransform& footprintToBase, double& heightError) const{
81  tf::Vector3 xyz = p.pose.getOrigin();
82  double poseHeight = footprintToBase.getOrigin().getZ();
83  std::vector<double> heights;
84  m_mapModel->getHeightlist(xyz.getX(), xyz.getY(), 0.6, heights);
85  if (heights.size() == 0)
86  return false;
87 
88 
89  // TODO: verify this!
90  // find nearest z-level:
91  heightError = std::numeric_limits<double>::max();
92  for (unsigned i = 0; i< heights.size(); i++){
93  double dist = std::abs((heights[i] + poseHeight) - xyz.getZ());
94  if (dist < heightError)
95  heightError = dist;
96 
97  }
98 
99  return true;
100 }
101 
103  m_map = map;
104  initDistanceMap();
105 }
106 
108  double x,y,z;
109  m_map->getMetricMin(x,y,z);
110  octomap::point3d min(x,y,z);
111  m_map->getMetricMax(x,y,z);
112  octomap::point3d max(x,y,z);
114  m_distanceMap->update();
115  ROS_INFO("Distance map for endpoint model completed");
116 }
117 
118 }
119 
boost::shared_ptr< octomap::OcTree > m_map
bool getHeightError(const Particle &p, const tf::StampedTransform &footprintToBase, double &heightError) const
boost::mt19937 EngineT
Boost RNG engine:
void transformAsMatrix(const tf::Transform &bt, Eigen::Matrix4f &out_mat)
Particle consists of a pose and a weight.
TFSIMD_FORCE_INLINE const tfScalar & getY() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
static double logLikelihood(double x, double sigma)
Helper function to compute the log likelihood.
boost::shared_ptr< MapModel > m_mapModel
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
TFSIMD_FORCE_INLINE const tfScalar & z() const
int min(int a, int b)
TFSIMD_FORCE_INLINE const tfScalar & getX() const
virtual void setMap(boost::shared_ptr< octomap::OcTree > map)
EndpointModel(ros::NodeHandle *nh, boost::shared_ptr< MapModel > mapModel, EngineT *rngEngine)
std::vector< Particle > Particles
boost::shared_ptr< DynamicEDTOctomap > m_distanceMap
Definition: EndpointModel.h:55
pcl::PointCloud< pcl::PointXYZ > PointCloud
virtual void integrateMeasurement(Particles &particles, const PointCloud &pc, const std::vector< float > &ranges, float max_range, const tf::Transform &baseToSensor)
#define ROS_ERROR(...)


humanoid_localization
Author(s): Armin Hornung, Stefan Osswald, Daniel Maier
autogenerated on Mon Jun 10 2019 13:38:31