Skip to content

Commit 839db5c

Browse files
Jorge Santos SimónDima Dorezyuk
Jorge Santos Simón
and
Dima Dorezyuk
authored
fix segfault at robot-model update (rst-tu-dortmund#255 revisited) (rst-tu-dortmund#393)
Co-authored-by: Dima Dorezyuk <dorezyuk@magazino.eu>
1 parent 9462016 commit 839db5c

11 files changed

+64
-150
lines changed

include/teb_local_planner/g2o_types/edge_dynamic_obstacle.h

+5-19
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class EdgeDynamicObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexPo
8080
}
8181

8282
/**
83-
* @brief Construct edge and specify the time for its associated pose (neccessary for computeError).
83+
* @brief Construct edge and specify the time for its associated pose (necessary for computeError).
8484
* @param t_ Estimated time until current pose is reached
8585
*/
8686
EdgeDynamicObstacle(double t) : t_(t)
@@ -92,10 +92,10 @@ class EdgeDynamicObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexPo
9292
*/
9393
void computeError()
9494
{
95-
ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeDynamicObstacle()");
95+
ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeDynamicObstacle()");
9696
const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
9797

98-
double dist = robot_model_->estimateSpatioTemporalDistance(bandpt->pose(), _measurement, t_);
98+
double dist = cfg_->robot_model->estimateSpatioTemporalDistance(bandpt->pose(), _measurement, t_);
9999

100100
_error[0] = penaltyBoundFromBelow(dist, cfg_->obstacles.min_obstacle_dist, cfg_->optim.penalty_epsilon);
101101
_error[1] = penaltyBoundFromBelow(dist, cfg_->obstacles.dynamic_obstacle_inflation_dist, 0.0);
@@ -113,40 +113,26 @@ class EdgeDynamicObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexPo
113113
_measurement = obstacle;
114114
}
115115

116-
/**
117-
* @brief Set pointer to the robot model
118-
* @param robot_model Robot model required for distance calculation
119-
*/
120-
void setRobotModel(const BaseRobotFootprintModel* robot_model)
121-
{
122-
robot_model_ = robot_model;
123-
}
124-
125116
/**
126117
* @brief Set all parameters at once
127118
* @param cfg TebConfig class
128-
* @param robot_model Robot model required for distance calculation
129119
* @param obstacle 2D position vector containing the position of the obstacle
130120
*/
131-
void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
121+
void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
132122
{
133123
cfg_ = &cfg;
134-
robot_model_ = robot_model;
135124
_measurement = obstacle;
136125
}
137126

138127
protected:
139128

140-
const BaseRobotFootprintModel* robot_model_; //!< Store pointer to robot_model
141129
double t_; //!< Estimated time until current pose is reached
142130

143131
public:
144132
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
145133

146134
};
147-
148-
149-
135+
150136

151137
} // end namespace
152138

include/teb_local_planner/g2o_types/edge_obstacle.h

+7-41
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ class EdgeObstacle : public BaseTebUnaryEdge<1, const Obstacle*, VertexPose>
8484
*/
8585
void computeError()
8686
{
87-
ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeObstacle()");
87+
ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeObstacle()");
8888
const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
8989

90-
double dist = robot_model_->calculateDistance(bandpt->pose(), _measurement);
90+
double dist = cfg_->robot_model->calculateDistance(bandpt->pose(), _measurement);
9191

9292
// Original obstacle cost.
9393
_error[0] = penaltyBoundFromBelow(dist, cfg_->obstacles.min_obstacle_dist, cfg_->optim.penalty_epsilon);
@@ -159,35 +159,18 @@ class EdgeObstacle : public BaseTebUnaryEdge<1, const Obstacle*, VertexPose>
159159
_measurement = obstacle;
160160
}
161161

162-
/**
163-
* @brief Set pointer to the robot model
164-
* @param robot_model Robot model required for distance calculation
165-
*/
166-
void setRobotModel(const BaseRobotFootprintModel* robot_model)
167-
{
168-
robot_model_ = robot_model;
169-
}
170-
171162
/**
172163
* @brief Set all parameters at once
173164
* @param cfg TebConfig class
174-
* @param robot_model Robot model required for distance calculation
175165
* @param obstacle 2D position vector containing the position of the obstacle
176166
*/
177-
void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
167+
void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
178168
{
179169
cfg_ = &cfg;
180-
robot_model_ = robot_model;
181170
_measurement = obstacle;
182171
}
183172

184-
protected:
185-
186-
const BaseRobotFootprintModel* robot_model_; //!< Store pointer to robot_model
187-
188-
public:
189173
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
190-
191174
};
192175

193176

@@ -223,10 +206,10 @@ class EdgeInflatedObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexP
223206
*/
224207
void computeError()
225208
{
226-
ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeInflatedObstacle()");
209+
ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeInflatedObstacle()");
227210
const VertexPose* bandpt = static_cast<const VertexPose*>(_vertices[0]);
228211

229-
double dist = robot_model_->calculateDistance(bandpt->pose(), _measurement);
212+
double dist = cfg_->robot_model->calculateDistance(bandpt->pose(), _measurement);
230213

231214
// Original "straight line" obstacle cost. The max possible value
232215
// before weighting is min_obstacle_dist
@@ -257,36 +240,19 @@ class EdgeInflatedObstacle : public BaseTebUnaryEdge<2, const Obstacle*, VertexP
257240
{
258241
_measurement = obstacle;
259242
}
260-
261-
/**
262-
* @brief Set pointer to the robot model
263-
* @param robot_model Robot model required for distance calculation
264-
*/
265-
void setRobotModel(const BaseRobotFootprintModel* robot_model)
266-
{
267-
robot_model_ = robot_model;
268-
}
269-
243+
270244
/**
271245
* @brief Set all parameters at once
272246
* @param cfg TebConfig class
273-
* @param robot_model Robot model required for distance calculation
274247
* @param obstacle 2D position vector containing the position of the obstacle
275248
*/
276-
void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
249+
void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
277250
{
278251
cfg_ = &cfg;
279-
robot_model_ = robot_model;
280252
_measurement = obstacle;
281253
}
282254

283-
protected:
284-
285-
const BaseRobotFootprintModel* robot_model_; //!< Store pointer to robot_model
286-
287-
public:
288255
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
289-
290256
};
291257

292258

include/teb_local_planner/g2o_types/edge_velocity_obstacle_ratio.h

+4-22
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ class EdgeVelocityObstacleRatio : public BaseTebMultiEdge<2, const Obstacle*>
7070
/**
7171
* @brief Construct edge.
7272
*/
73-
EdgeVelocityObstacleRatio() :
74-
robot_model_(nullptr)
73+
EdgeVelocityObstacleRatio()
7574
{
7675
// The three vertices are two poses and one time difference
7776
this->resize(3); // Since we derive from a g2o::BaseMultiEdge, set the desired number of vertices
@@ -82,7 +81,7 @@ class EdgeVelocityObstacleRatio : public BaseTebMultiEdge<2, const Obstacle*>
8281
*/
8382
void computeError()
8483
{
85-
ROS_ASSERT_MSG(cfg_ && _measurement && robot_model_, "You must call setTebConfig(), setObstacle() and setRobotModel() on EdgeVelocityObstacleRatio()");
84+
ROS_ASSERT_MSG(cfg_ && _measurement, "You must call setTebConfig() and setObstacle() on EdgeVelocityObstacleRatio()");
8685
const VertexPose* conf1 = static_cast<const VertexPose*>(_vertices[0]);
8786
const VertexPose* conf2 = static_cast<const VertexPose*>(_vertices[1]);
8887
const VertexTimeDiff* deltaT = static_cast<const VertexTimeDiff*>(_vertices[2]);
@@ -102,7 +101,7 @@ class EdgeVelocityObstacleRatio : public BaseTebMultiEdge<2, const Obstacle*>
102101

103102
const double omega = angle_diff / deltaT->estimate();
104103

105-
double dist_to_obstacle = robot_model_->calculateDistance(conf1->pose(), _measurement);
104+
double dist_to_obstacle = cfg_->robot_model->calculateDistance(conf1->pose(), _measurement);
106105

107106
double ratio;
108107
if (dist_to_obstacle < cfg_->obstacles.obstacle_proximity_lower_bound)
@@ -131,36 +130,19 @@ class EdgeVelocityObstacleRatio : public BaseTebMultiEdge<2, const Obstacle*>
131130
_measurement = obstacle;
132131
}
133132

134-
/**
135-
* @brief Set pointer to the robot model
136-
* @param robot_model Robot model required for distance calculation
137-
*/
138-
void setRobotModel(const BaseRobotFootprintModel* robot_model)
139-
{
140-
robot_model_ = robot_model;
141-
}
142-
143133
/**
144134
* @brief Set all parameters at once
145135
* @param cfg TebConfig class
146-
* @param robot_model Robot model required for distance calculation
147136
* @param obstacle 2D position vector containing the position of the obstacle
148137
*/
149-
void setParameters(const TebConfig& cfg, const BaseRobotFootprintModel* robot_model, const Obstacle* obstacle)
138+
void setParameters(const TebConfig& cfg, const Obstacle* obstacle)
150139
{
151140
cfg_ = &cfg;
152-
robot_model_ = robot_model;
153141
_measurement = obstacle;
154142
}
155143

156-
protected:
157-
158-
const BaseRobotFootprintModel* robot_model_; //!< Store pointer to robot_model
159-
160-
public:
161144
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
162145

163146
};
164147

165-
166148
} // end namespace

include/teb_local_planner/homotopy_class_planner.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ class HomotopyClassPlanner : public PlannerInterface
120120
* @brief Construct and initialize the HomotopyClassPlanner
121121
* @param cfg Const reference to the TebConfig class for internal parameters
122122
* @param obstacles Container storing all relevant obstacles (see Obstacle)
123-
* @param robot_model Shared pointer to the robot shape model used for optimization (optional)
124123
* @param visualization Shared pointer to the TebVisualization class (optional)
125124
* @param via_points Container storing via-points (optional)
126125
*/
127-
HomotopyClassPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
126+
HomotopyClassPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL,
128127
TebVisualizationPtr visualization = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
129128

130129
/**
@@ -136,16 +135,13 @@ class HomotopyClassPlanner : public PlannerInterface
136135
* @brief Initialize the HomotopyClassPlanner
137136
* @param cfg Const reference to the TebConfig class for internal parameters
138137
* @param obstacles Container storing all relevant obstacles (see Obstacle)
139-
* @param robot_model Shared pointer to the robot shape model used for optimization (optional)
140138
* @param visualization Shared pointer to the TebVisualization class (optional)
141139
* @param via_points Container storing via-points (optional)
142140
*/
143-
void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
141+
void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL,
144142
TebVisualizationPtr visualization = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
145143

146144

147-
void updateRobotModel(RobotFootprintModelPtr robot_model );
148-
149145
/** @name Plan a trajectory */
150146
//@{
151147

@@ -553,7 +549,6 @@ class HomotopyClassPlanner : public PlannerInterface
553549
TebVisualizationPtr visualization_; //!< Instance of the visualization class (local/global plan, obstacles, ...)
554550
TebOptimalPlannerPtr best_teb_; //!< Store the current best teb.
555551
EquivalenceClassPtr best_teb_eq_class_; //!< Store the equivalence class of the current best teb
556-
RobotFootprintModelPtr robot_model_; //!< Robot model shared instance
557552

558553
const std::vector<geometry_msgs::PoseStamped>* initial_plan_; //!< Store the initial plan if available for a better trajectory initialization
559554
EquivalenceClassPtr initial_plan_eq_class_; //!< Store the equivalence class of the initial plan

include/teb_local_planner/homotopy_class_planner.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ EquivalenceClassPtr HomotopyClassPlanner::calculateEquivalenceClass(BidirIter pa
6565
template<typename BidirIter, typename Fun>
6666
TebOptimalPlannerPtr HomotopyClassPlanner::addAndInitNewTeb(BidirIter path_start, BidirIter path_end, Fun fun_position, double start_orientation, double goal_orientation, const geometry_msgs::Twist* start_velocity, bool free_goal_vel)
6767
{
68-
TebOptimalPlannerPtr candidate = TebOptimalPlannerPtr( new TebOptimalPlanner(*cfg_, obstacles_, robot_model_));
68+
TebOptimalPlannerPtr candidate = TebOptimalPlannerPtr( new TebOptimalPlanner(*cfg_, obstacles_));
6969

7070
candidate->teb().initTrajectoryToGoal(path_start, path_end, fun_position, cfg_->robot.max_vel_x, cfg_->robot.max_vel_theta,
7171
cfg_->robot.acc_lim_x, cfg_->robot.acc_lim_theta, start_orientation, goal_orientation, cfg_->trajectory.min_samples,

include/teb_local_planner/optimal_planner.h

+3-11
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ class TebOptimalPlanner : public PlannerInterface
110110
* @brief Construct and initialize the TEB optimal planner.
111111
* @param cfg Const reference to the TebConfig class for internal parameters
112112
* @param obstacles Container storing all relevant obstacles (see Obstacle)
113-
* @param robot_model Shared pointer to the robot shape model used for optimization (optional)
114113
* @param visual Shared pointer to the TebVisualization class (optional)
115114
* @param via_points Container storing via-points (optional)
116115
*/
117-
TebOptimalPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
116+
TebOptimalPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL,
118117
TebVisualizationPtr visual = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
119118

120119
/**
@@ -126,18 +125,12 @@ class TebOptimalPlanner : public PlannerInterface
126125
* @brief Initializes the optimal planner
127126
* @param cfg Const reference to the TebConfig class for internal parameters
128127
* @param obstacles Container storing all relevant obstacles (see Obstacle)
129-
* @param robot_model Shared pointer to the robot shape model used for optimization (optional)
130128
* @param visual Shared pointer to the TebVisualization class (optional)
131129
* @param via_points Container storing via-points (optional)
132130
*/
133-
void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
131+
void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL,
134132
TebVisualizationPtr visual = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
135-
136-
/**
137-
* @param robot_model Shared pointer to the robot shape model used for optimization (optional)
138-
*/
139-
void updateRobotModel(RobotFootprintModelPtr robot_model );
140-
133+
141134
/** @name Plan a trajectory */
142135
//@{
143136

@@ -690,7 +683,6 @@ class TebOptimalPlanner : public PlannerInterface
690683
// internal objects (memory management owned)
691684
TebVisualizationPtr visualization_; //!< Instance of the visualization class
692685
TimedElasticBand teb_; //!< Actual trajectory object
693-
RobotFootprintModelPtr robot_model_; //!< Robot model
694686
boost::shared_ptr<g2o::SparseOptimizer> optimizer_; //!< g2o optimizer for trajectory optimization
695687
std::pair<bool, geometry_msgs::Twist> vel_start_; //!< Store the initial velocity at the start pose
696688
std::pair<bool, geometry_msgs::Twist> vel_goal_; //!< Store the final velocity at the goal pose

include/teb_local_planner/teb_config.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <Eigen/StdVector>
4646

4747
#include <teb_local_planner/TebLocalPlannerReconfigureConfig.h>
48+
#include <teb_local_planner/robot_footprint_model.h>
4849

4950

5051
// Definitions
@@ -65,6 +66,8 @@ class TebConfig
6566
std::string odom_topic; //!< Topic name of the odometry message, provided by the robot driver or simulator
6667
std::string map_frame; //!< Global planning frame
6768

69+
RobotFootprintModelPtr robot_model; //!< model of the robot's footprint
70+
6871
//! Trajectory related parameters
6972
struct Trajectory
7073
{
@@ -244,6 +247,7 @@ class TebConfig
244247

245248
odom_topic = "odom";
246249
map_frame = "odom";
250+
robot_model = boost::make_shared<PointRobotFootprint>();
247251

248252
// Trajectory
249253

0 commit comments

Comments
 (0)