edge_obstacle.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2016,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the institute nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Notes:
37  * The following class is derived from a class defined by the
38  * g2o-framework. g2o is licensed under the terms of the BSD License.
39  * Refer to the base class source for detailed licensing information.
40  *
41  * Author: Christoph Rösmann
42  *********************************************************************/
43 #ifndef EDGE_OBSTACLE_H_
44 #define EDGE_OBSTACLE_H_
45 
52 
53 
54 
55 namespace teb_local_planner
56 {
57 
70 class EdgeObstacle : public BaseTebUnaryEdge<1, const Obstacle*, VertexPose>
71 {
72 public:
73 
78  {
79  _measurement = NULL;
80  }
81 
85  void computeError()
86  {
87  ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeObstacle()");
88  const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
89 
90  double dist = robot_model_->calculateDistance(bandpt->pose(), _measurement);
91 
92  // Original obstacle cost.
94 
96  {
97  // Optional non-linear cost. Note the max cost (before weighting) is
98  // the same as the straight line version and that all other costs are
99  // below the straight line (for positive exponent), so it may be
100  // necessary to increase weight_obstacle and/or the inflation_weight
101  // when using larger exponents.
103  }
104 
105  ROS_ASSERT_MSG(std::isfinite(_error[0]), "EdgeObstacle::computeError() _error[0]=%f\n",_error[0]);
106  }
107 
108 #ifdef USE_ANALYTIC_JACOBI
109 #if 0
110 
114  void linearizeOplus()
115  {
116  ROS_ASSERT_MSG(cfg_, "You must call setTebConfig on EdgePointObstacle()");
117  const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
118 
119  Eigen::Vector2d deltaS = *_measurement - bandpt->position();
120  double angdiff = atan2(deltaS[1],deltaS[0])-bandpt->theta();
121 
122  double dist_squared = deltaS.squaredNorm();
123  double dist = sqrt(dist_squared);
124 
125  double aux0 = sin(angdiff);
126  double dev_left_border = penaltyBoundFromBelowDerivative(dist*fabs(aux0),cfg_->obstacles.min_obstacle_dist,cfg_->optim.penalty_epsilon);
127 
128  if (dev_left_border==0)
129  {
130  _jacobianOplusXi( 0 , 0 ) = 0;
131  _jacobianOplusXi( 0 , 1 ) = 0;
132  _jacobianOplusXi( 0 , 2 ) = 0;
133  return;
134  }
135 
136  double aux1 = -fabs(aux0) / dist;
137  double dev_norm_x = deltaS[0]*aux1;
138  double dev_norm_y = deltaS[1]*aux1;
139 
140  double aux2 = cos(angdiff) * g2o::sign(aux0);
141  double aux3 = aux2 / dist_squared;
142  double dev_proj_x = aux3 * deltaS[1] * dist;
143  double dev_proj_y = -aux3 * deltaS[0] * dist;
144  double dev_proj_angle = -aux2;
145 
146  _jacobianOplusXi( 0 , 0 ) = dev_left_border * ( dev_norm_x + dev_proj_x );
147  _jacobianOplusXi( 0 , 1 ) = dev_left_border * ( dev_norm_y + dev_proj_y );
148  _jacobianOplusXi( 0 , 2 ) = dev_left_border * dev_proj_angle;
149  }
150 #endif
151 #endif
152 
157  void setObstacle(const Obstacle* obstacle)
158  {
159  _measurement = obstacle;
160  }
161 
166  void setRobotModel(const BaseRobotFootprintModel* robot_model)
167  {
168  robot_model_ = robot_model;
169  }
170 
177  void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
178  {
179  cfg_ = &cfg;
180  robot_model_ = robot_model;
181  _measurement = obstacle;
182  }
183 
184 protected:
185 
187 
188 public:
189  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
190 
191 };
192 
193 
194 
209 class EdgeInflatedObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexPose>
210 {
211 public:
212 
217  {
218  _measurement = NULL;
219  }
220 
225  {
226  ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeInflatedObstacle()");
227  const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
228 
229  double dist = robot_model_->calculateDistance(bandpt->pose(), _measurement);
230 
231  // Original "straight line" obstacle cost. The max possible value
232  // before weighting is min_obstacle_dist
234 
236  {
237  // Optional non-linear cost. Note the max cost (before weighting) is
238  // the same as the straight line version and that all other costs are
239  // below the straight line (for positive exponent), so it may be
240  // necessary to increase weight_obstacle and/or the inflation_weight
241  // when using larger exponents.
243  }
244 
245  // Additional linear inflation cost
246  _error[1] = penaltyBoundFromBelow(dist, cfg_->obstacles.inflation_dist, 0.0);
247 
248 
249  ROS_ASSERT_MSG(std::isfinite(_error[0]) && std::isfinite(_error[1]), "EdgeInflatedObstacle::computeError() _error[0]=%f, _error[1]=%f\n",_error[0], _error[1]);
250  }
251 
256  void setObstacle(const Obstacle* obstacle)
257  {
258  _measurement = obstacle;
259  }
260 
265  void setRobotModel(const BaseRobotFootprintModel* robot_model)
266  {
267  robot_model_ = robot_model;
268  }
269 
276  void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
277  {
278  cfg_ = &cfg;
279  robot_model_ = robot_model;
280  _measurement = obstacle;
281  }
282 
283 protected:
284 
286 
287 public:
288  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
289 
290 };
291 
292 
293 } // end namespace
294 
295 #endif
double penaltyBoundFromBelow(const double &var, const double &a, const double &epsilon)
Linear penalty function for bounding var from below: .
Definition: penalties.h:107
const BaseRobotFootprintModel * robot_model_
Store pointer to robot_model.
PoseSE2 & pose()
Access the pose.
Definition: vertex_pose.h:126
void setRobotModel(const BaseRobotFootprintModel *robot_model)
Set pointer to the robot model.
double min_obstacle_dist
Minimum desired separation from obstacles.
Definition: teb_config.h:119
Config class for the teb_local_planner and its components.
Definition: teb_config.h:61
Abstract class that defines the interface for robot footprint/contour models.
void setParameters(const TebConfig &cfg, const BaseRobotFootprintModel *robot_model, const Obstacle *obstacle)
Set all parameters at once.
const TebConfig * cfg_
Store TebConfig class for parameters.
void setRobotModel(const BaseRobotFootprintModel *robot_model)
Set pointer to the robot model.
void setObstacle(const Obstacle *obstacle)
Set pointer to associated obstacle for the underlying cost function.
Edge defining the cost function for keeping a minimum distance from obstacles.
Definition: edge_obstacle.h:70
void computeError()
Actual cost function.
void setObstacle(const Obstacle *obstacle)
Set pointer to associated obstacle for the underlying cost function.
double & theta()
Access the orientation part (yaw angle) of the pose.
Definition: vertex_pose.h:178
const BaseRobotFootprintModel * robot_model_
Store pointer to robot_model.
Edge defining the cost function for keeping a minimum distance from inflated obstacles.
#define ROS_ASSERT_MSG(cond,...)
void computeError()
Actual cost function.
Definition: edge_obstacle.h:85
void setParameters(const TebConfig &cfg, const BaseRobotFootprintModel *robot_model, const Obstacle *obstacle)
Set all parameters at once.
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
double penaltyBoundFromBelowDerivative(const double &var, const double &a, const double &epsilon)
Derivative of the linear penalty function for bounding var from below: .
Definition: penalties.h:177
double penalty_epsilon
Add a small safety margin to penalty functions for hard-constraint approximations.
Definition: teb_config.h:144
Eigen::Vector2d & position()
Access the 2D position part.
Definition: vertex_pose.h:141
double obstacle_cost_exponent
Exponent for nonlinear obstacle cost (cost = linear_cost * obstacle_cost_exponent). Set to 1 to disable nonlinear cost (default)
Definition: teb_config.h:165
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
EdgeObstacle()
Construct edge.
Definition: edge_obstacle.h:77
This class stores and wraps a SE2 pose (position and orientation) into a vertex that can be optimized...
Definition: vertex_pose.h:63
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
struct teb_local_planner::TebConfig::Optimization optim
Optimization related parameters.
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
double inflation_dist
buffer zone around obstacles with non-zero penalty costs (should be larger than min_obstacle_dist in ...
Definition: teb_config.h:120
Base edge connecting a single vertex in the TEB optimization problem.
struct teb_local_planner::TebConfig::Obstacles obstacles
Obstacle related parameters.
Abstract class that defines the interface for modelling obstacles.
Definition: obstacles.h:67
def sign(number)
virtual double calculateDistance(const PoseSE2 &current_pose, const Obstacle *obstacle) const =0
Calculate the distance between the robot and an obstacle.


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Wed Jun 3 2020 04:03:08