HectorSlamProcessor.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Stefan Kohlbrecher, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef _hectorslamprocessor_h__
30 #define _hectorslamprocessor_h__
31 
32 #include "../map/GridMap.h"
33 #include "../map/OccGridMapUtilConfig.h"
34 #include "../matcher/ScanMatcher.h"
35 #include "../scan/DataPointContainer.h"
36 
37 #include "../util/UtilFunctions.h"
38 #include "../util/DrawInterface.h"
39 #include "../util/HectorDebugInfoInterface.h"
40 #include "../util/MapLockerInterface.h"
41 
43 #include "MapRepMultiMap.h"
44 
45 
46 #include <float.h>
47 
48 namespace hectorslam{
49 
51 {
52 public:
53 
54  HectorSlamProcessor(float mapResolution, int mapSizeX, int mapSizeY , const Eigen::Vector2f& startCoords, int multi_res_size, DrawInterface* drawInterfaceIn = 0, HectorDebugInfoInterface* debugInterfaceIn = 0)
55  : drawInterface(drawInterfaceIn)
56  , debugInterface(debugInterfaceIn)
57  {
58  mapRep = new MapRepMultiMap(mapResolution, mapSizeX, mapSizeY, multi_res_size, startCoords, drawInterfaceIn, debugInterfaceIn);
59 
60  this->reset();
61 
62  this->setMapUpdateMinDistDiff(0.4f *1.0f);
63  this->setMapUpdateMinAngleDiff(0.13f * 1.0f);
64  }
65 
67  {
68  delete mapRep;
69  }
70 
71  void update(const DataContainer& dataContainer, const Eigen::Vector3f& poseHintWorld, bool map_without_matching = false)
72  {
73  //std::cout << "\nph:\n" << poseHintWorld << "\n";
74 
75  Eigen::Vector3f newPoseEstimateWorld;
76 
77  if (!map_without_matching){
78  newPoseEstimateWorld = (mapRep->matchData(poseHintWorld, dataContainer, lastScanMatchCov));
79  }else{
80  newPoseEstimateWorld = poseHintWorld;
81  }
82 
83  lastScanMatchPose = newPoseEstimateWorld;
84 
85  //std::cout << "\nt1:\n" << newPoseEstimateWorld << "\n";
86 
87  //std::cout << "\n1";
88  //std::cout << "\n" << lastScanMatchPose << "\n";
90 
91  mapRep->updateByScan(dataContainer, newPoseEstimateWorld);
92 
94  lastMapUpdatePose = newPoseEstimateWorld;
95  }
96 
97  if(drawInterface){
98  const GridMap& gridMapRef (mapRep->getGridMap());
99  drawInterface->setColor(1.0, 0.0, 0.0);
100  drawInterface->setScale(0.15);
101 
102  drawInterface->drawPoint(gridMapRef.getWorldCoords(Eigen::Vector2f::Zero()));
103  drawInterface->drawPoint(gridMapRef.getWorldCoords((gridMapRef.getMapDimensions().array()-1).cast<float>()));
104  drawInterface->drawPoint(Eigen::Vector2f(1.0f, 1.0f));
105 
107  }
108 
109  if (debugInterface)
110  {
112  }
113  }
114 
115  void reset()
116  {
117  lastMapUpdatePose = Eigen::Vector3f(FLT_MAX, FLT_MAX, FLT_MAX);
118  lastScanMatchPose = Eigen::Vector3f::Zero();
119  //lastScanMatchPose.x() = -10.0f;
120  //lastScanMatchPose.y() = -15.0f;
121  //lastScanMatchPose.z() = M_PI*0.15f;
122 
123  mapRep->reset();
124  }
125 
126  const Eigen::Vector3f& getLastScanMatchPose() const { return lastScanMatchPose; };
127  const Eigen::Matrix3f& getLastScanMatchCovariance() const { return lastScanMatchCov; };
128  float getScaleToMap() const { return mapRep->getScaleToMap(); };
129 
130  int getMapLevels() const { return mapRep->getMapLevels(); };
131  const GridMap& getGridMap(int mapLevel = 0) const { return mapRep->getGridMap(mapLevel); };
132 
133  void addMapMutex(int i, MapLockerInterface* mapMutex) { mapRep->addMapMutex(i, mapMutex); };
135 
136  void setUpdateFactorFree(float free_factor) { mapRep->setUpdateFactorFree(free_factor); };
137  void setUpdateFactorOccupied(float occupied_factor) { mapRep->setUpdateFactorOccupied(occupied_factor); };
138  void setMapUpdateMinDistDiff(float minDist) { paramMinDistanceDiffForMapUpdate = minDist; };
139  void setMapUpdateMinAngleDiff(float angleChange) { paramMinAngleDiffForMapUpdate = angleChange; };
140 
141 protected:
142 
144 
145  Eigen::Vector3f lastMapUpdatePose;
146  Eigen::Vector3f lastScanMatchPose;
147  Eigen::Matrix3f lastScanMatchCov;
148 
151 
154 };
155 
156 }
157 
158 #endif
void setMapUpdateMinDistDiff(float minDist)
virtual void setUpdateFactorFree(float free_factor)=0
HectorDebugInfoInterface * debugInterface
f
virtual void setColor(double r, double g, double b, double a=1.0)=0
virtual void drawPoint(const Eigen::Vector2f &pointWorldFrame)=0
virtual void sendAndResetData()=0
virtual void sendAndResetData()=0
const Eigen::Vector3f & getLastScanMatchPose() const
MapLockerInterface * getMapMutex(int i)
const Eigen::Matrix3f & getLastScanMatchCovariance() const
virtual Eigen::Vector3f matchData(const Eigen::Vector3f &beginEstimateWorld, const DataContainer &dataContainer, Eigen::Matrix3f &covMatrix)=0
void setMapUpdateMinAngleDiff(float angleChange)
virtual void setScale(double scale)=0
virtual void addMapMutex(int i, MapLockerInterface *mapMutex)=0
void addMapMutex(int i, MapLockerInterface *mapMutex)
virtual float getScaleToMap() const =0
void setUpdateFactorOccupied(float occupied_factor)
MapRepresentationInterface * mapRep
virtual const GridMap & getGridMap(int mapLevel=0) const =0
virtual void updateByScan(const DataContainer &dataContainer, const Eigen::Vector3f &robotPoseWorld)=0
static bool poseDifferenceLargerThan(const Eigen::Vector3f &pose1, const Eigen::Vector3f &pose2, float distanceDiffThresh, float angleDiffThresh)
Definition: UtilFunctions.h:72
void setUpdateFactorFree(float free_factor)
const GridMap & getGridMap(int mapLevel=0) const
virtual MapLockerInterface * getMapMutex(int i)=0
virtual void setUpdateFactorOccupied(float occupied_factor)=0
HectorSlamProcessor(float mapResolution, int mapSizeX, int mapSizeY, const Eigen::Vector2f &startCoords, int multi_res_size, DrawInterface *drawInterfaceIn=0, HectorDebugInfoInterface *debugInterfaceIn=0)
void update(const DataContainer &dataContainer, const Eigen::Vector3f &poseHintWorld, bool map_without_matching=false)
virtual int getMapLevels() const =0


hector_mapping
Author(s): Stefan Kohlbrecher
autogenerated on Sun Nov 3 2019 03:18:33