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 
77  EdgeObstacle()
78  {
79  _measurement = NULL;
80  }
81 
85  void computeError()
86  {
87  ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeObstacle()");
88  const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
89 
90  double dist = cfg_->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);
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 
167  void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
168  {
169  cfg_ = &cfg;
170  _measurement = obstacle;
171  }
172 
173  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
174 };
175 
176 
177 
192 class EdgeInflatedObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexPose>
193 {
194 public:
195 
200  {
201  _measurement = NULL;
202  }
203 
207  void computeError()
208  {
209  ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeInflatedObstacle()");
210  const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
211 
212  double dist = cfg_->robot_model->calculateDistance(bandpt->pose(), _measurement);
213 
214  // Original "straight line" obstacle cost. The max possible value
215  // before weighting is min_obstacle_dist
217 
219  {
220  // Optional non-linear cost. Note the max cost (before weighting) is
221  // the same as the straight line version and that all other costs are
222  // below the straight line (for positive exponent), so it may be
223  // necessary to increase weight_obstacle and/or the inflation_weight
224  // when using larger exponents.
226  }
227 
228  // Additional linear inflation cost
229  _error[1] = penaltyBoundFromBelow(dist, cfg_->obstacles.inflation_dist, 0.0);
230 
231 
232  ROS_ASSERT_MSG(std::isfinite(_error[0]) && std::isfinite(_error[1]), "EdgeInflatedObstacle::computeError() _error[0]=%f, _error[1]=%f\n",_error[0], _error[1]);
233  }
234 
239  void setObstacle(const Obstacle* obstacle)
240  {
241  _measurement = obstacle;
242  }
243 
249  void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
250  {
251  cfg_ = &cfg;
252  _measurement = obstacle;
253  }
254 
255  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
256 };
257 
258 
259 } // end namespace
260 
261 #endif
teb_local_planner::penaltyBoundFromBelow
double penaltyBoundFromBelow(const double &var, const double &a, const double &epsilon)
Linear penalty function for bounding var from below: .
Definition: penalties.h:143
teb_local_planner::TebConfig::Obstacles::inflation_dist
double inflation_dist
buffer zone around obstacles with non-zero penalty costs (should be larger than min_obstacle_dist in ...
Definition: teb_config.h:130
teb_local_planner::VertexPose::pose
PoseSE2 & pose()
Access the pose.
Definition: vertex_pose.h:162
teb_local_planner::TebConfig::Optimization::penalty_epsilon
double penalty_epsilon
Add a small safety margin to penalty functions for hard-constraint approximations.
Definition: teb_config.h:157
teb_local_planner::Obstacle
Abstract class that defines the interface for modelling obstacles.
Definition: obstacles.h:103
teb_local_planner::EdgeObstacle::computeError
void computeError()
Actual cost function.
Definition: edge_obstacle.h:126
teb_local_planner::BaseTebUnaryEdge< 1, const Obstacle *, VertexPose >::cfg_
const TebConfig * cfg_
Store TebConfig class for parameters.
Definition: base_teb_edges.h:160
obstacles.h
teb_config.h
teb_local_planner::TebConfig::Obstacles::min_obstacle_dist
double min_obstacle_dist
Minimum desired separation from obstacles.
Definition: teb_config.h:129
penalties.h
robot_footprint_model.h
teb_local_planner::TebConfig::Optimization::obstacle_cost_exponent
double obstacle_cost_exponent
Exponent for nonlinear obstacle cost (cost = linear_cost * obstacle_cost_exponent)....
Definition: teb_config.h:179
teb_local_planner::penaltyBoundFromBelowDerivative
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:213
ROS_ASSERT_MSG
#define ROS_ASSERT_MSG(cond,...)
teb_local_planner::EdgeObstacle::setParameters
void setParameters(const TebConfig &cfg, const Obstacle *obstacle)
Set all parameters at once.
Definition: edge_obstacle.h:208
teb_local_planner::TebConfig
Config class for the teb_local_planner and its components.
Definition: teb_config.h:62
teb_local_planner::EdgeInflatedObstacle::setParameters
void setParameters(const TebConfig &cfg, const Obstacle *obstacle)
Set all parameters at once.
Definition: edge_obstacle.h:290
teb_local_planner::TebConfig::obstacles
struct teb_local_planner::TebConfig::Obstacles obstacles
Obstacle related parameters.
teb_local_planner::EdgeObstacle::EdgeObstacle
EdgeObstacle()
Construct edge.
Definition: edge_obstacle.h:118
teb_local_planner::EdgeInflatedObstacle::setObstacle
void setObstacle(const Obstacle *obstacle)
Set pointer to associated obstacle for the underlying cost function.
Definition: edge_obstacle.h:280
vertex_pose.h
teb_local_planner::TebConfig::robot_model
RobotFootprintModelPtr robot_model
model of the robot's footprint
Definition: teb_config.h:69
base_teb_edges.h
teb_local_planner::EdgeInflatedObstacle::EdgeInflatedObstacle
EdgeInflatedObstacle()
Construct edge.
Definition: edge_obstacle.h:240
teb_local_planner::EdgeObstacle::setObstacle
void setObstacle(const Obstacle *obstacle)
Set pointer to associated obstacle for the underlying cost function.
Definition: edge_obstacle.h:198
teb_local_planner
Definition: distance_calculations.h:46
teb_local_planner::VertexPose
This class stores and wraps a SE2 pose (position and orientation) into a vertex that can be optimized...
Definition: vertex_pose.h:104
teb_local_planner::TebConfig::optim
struct teb_local_planner::TebConfig::Optimization optim
Optimization related parameters.
teb_local_planner::EdgeInflatedObstacle::computeError
void computeError()
Actual cost function.
Definition: edge_obstacle.h:248


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Sun Jan 7 2024 03:45:15