GridMapLogOdds.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 __GridMapLogOdds_h_
30 #define __GridMapLogOdds_h_
31 
32 #include <cmath>
33 
38 {
39 public:
40 
41  /*
42  void setOccupied()
43  {
44  logOddsVal += 0.7f;
45  };
46 
47  void setFree()
48  {
49  logOddsVal -= 0.4f;
50  };
51  */
52 
53 
58  void set(float val)
59  {
60  logOddsVal = val;
61  }
62 
67  float getValue() const
68  {
69  return logOddsVal;
70  }
71 
76  bool isOccupied() const
77  {
78  return logOddsVal > 0.0f;
79  }
80 
81  bool isFree() const
82  {
83  return logOddsVal < 0.0f;
84  }
85 
90  {
91  logOddsVal = 0.0f;
92  updateIndex = -1;
93  }
94 
95  //protected:
96 
97 public:
98 
99  float logOddsVal;
101 
102 
103 };
104 
109 {
110 public:
111 
116  {
117  this->setUpdateFreeFactor(0.4f);
118  this->setUpdateOccupiedFactor(0.6f);
119  /*
120  //float probOccupied = 0.6f;
121  float probOccupied = 0.9f;
122  float oddsOccupied = probOccupied / (1.0f - probOccupied);
123  logOddsOccupied = log(oddsOccupied);
124 
125  float probFree = 0.4f;
126  float oddsFree = probFree / (1.0f - probFree);
127  logOddsFree = log(oddsFree);
128  */
129  }
130 
135  void updateSetOccupied(LogOddsCell& cell) const
136  {
137  if (cell.logOddsVal < 50.0f){
138  cell.logOddsVal += logOddsOccupied;
139  }
140  }
141 
146  void updateSetFree(LogOddsCell& cell) const
147  {
148 
149  cell.logOddsVal += logOddsFree;
150 
151  }
152 
153  void updateUnsetFree(LogOddsCell& cell) const
154  {
155  cell.logOddsVal -= logOddsFree;
156  }
157 
163  float getGridProbability(const LogOddsCell& cell) const
164  {
165  float odds = exp(cell.logOddsVal);
166  return odds / (odds + 1.0f);
167 
168  /*
169  float val = cell.logOddsVal;
170 
171  //prevent #IND when doing exp(large number).
172  if (val > 50.0f) {
173  return 1.0f;
174  } else {
175  float odds = exp(val);
176  return odds / (odds + 1.0f);
177  }
178  */
179  //return 0.5f;
180  }
181 
182  //void getGridValueMap( const LogOddsCell& cell) const{};
183  //void isOccupied(LogOddsCell& cell) {};
184 
185  //void resetGridCell() {};
186 
187  void setUpdateFreeFactor(float factor)
188  {
189  logOddsFree = probToLogOdds(factor);
190  }
191 
192  void setUpdateOccupiedFactor(float factor)
193  {
194  logOddsOccupied = probToLogOdds(factor);
195  }
196 
197 protected:
198 
199  float probToLogOdds(float prob)
200  {
201  float odds = prob / (1.0f - prob);
202  return log(odds);
203  }
204 
206  float logOddsFree;
207 
208 
209 };
210 
211 
212 #endif
float probToLogOdds(float prob)
f
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
void resetGridCell()
bool isFree() const
void setUpdateFreeFactor(float factor)
void updateSetOccupied(LogOddsCell &cell) const
void updateUnsetFree(LogOddsCell &cell) const
void setUpdateOccupiedFactor(float factor)
float getGridProbability(const LogOddsCell &cell) const
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
float logOddsFree
< The log odds representation of probability used for updating cells as occupied
bool isOccupied() const
void updateSetFree(LogOddsCell &cell) const
float logOddsVal
The log odds representation of occupancy probability.
float getValue() const


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