提交 f5f3efb7 编写于 作者: Z Zhang Liangliang 提交者: Jiangtao Hu

Planning: (1) fixed a bug in dp_st_graph. (2) used array instead of map in dp_st_cost.

上级 03a24eea
...@@ -36,9 +36,10 @@ DpStCost::DpStCost(const DpStSpeedConfig& config, ...@@ -36,9 +36,10 @@ DpStCost::DpStCost(const DpStSpeedConfig& config,
: config_(config), : config_(config),
obstacles_(obstacles), obstacles_(obstacles),
init_point_(init_point), init_point_(init_point),
unit_s_(config_.total_path_length() / config_.matrix_dimension_s()), unit_t_(config_.total_time() / config_.matrix_dimension_t()) {
unit_t_(config_.total_time() / config_.matrix_dimension_t()), accel_cost_.fill(-1.0);
unit_v_(unit_s_ / unit_t_) {} jerk_cost_.fill(-1.0);
}
double DpStCost::GetObstacleCost(const StGraphPoint& st_graph_point) { double DpStCost::GetObstacleCost(const StGraphPoint& st_graph_point) {
const double s = st_graph_point.point().s(); const double s = st_graph_point.point().s();
...@@ -123,9 +124,14 @@ double DpStCost::GetSpeedCost(const STPoint& first, const STPoint& second, ...@@ -123,9 +124,14 @@ double DpStCost::GetSpeedCost(const STPoint& first, const STPoint& second,
double DpStCost::GetAccelCost(const double accel) { double DpStCost::GetAccelCost(const double accel) {
double cost = 0.0; double cost = 0.0;
constexpr double kEpsilon = 0.1; constexpr double kEpsilon = 0.1;
const int accel_key = static_cast<int>(accel / kEpsilon + 0.5); constexpr int kShift = 100;
auto p_val = accel_cost_map_.find(accel_key); const int accel_key = static_cast<int>(accel / kEpsilon + 0.5) + kShift;
if (p_val == accel_cost_map_.end()) { DCHECK_LT(accel_key, accel_cost_.size());
if (accel_key < 0 || accel_key >= accel_cost_.size()) {
return kInf;
}
if (accel_cost_.at(accel_key) < 0.0) {
const double accel_sq = accel * accel; const double accel_sq = accel * accel;
double max_acc = config_.max_acceleration(); double max_acc = config_.max_acceleration();
double max_dec = config_.max_deceleration(); double max_dec = config_.max_deceleration();
...@@ -141,9 +147,9 @@ double DpStCost::GetAccelCost(const double accel) { ...@@ -141,9 +147,9 @@ double DpStCost::GetAccelCost(const double accel) {
(1 + std::exp(1.0 * (accel - max_dec))) + (1 + std::exp(1.0 * (accel - max_dec))) +
accel_sq * accel_penalty * accel_penalty / accel_sq * accel_penalty * accel_penalty /
(1 + std::exp(-1.0 * (accel - max_acc))); (1 + std::exp(-1.0 * (accel - max_acc)));
accel_cost_map_[accel_key] = cost; accel_cost_.at(accel_key) = cost;
} else { } else {
cost = p_val->second; cost = accel_cost_.at(accel_key);
} }
return cost * unit_t_; return cost * unit_t_;
} }
...@@ -166,18 +172,23 @@ double DpStCost::GetAccelCostByTwoPoints(const double pre_speed, ...@@ -166,18 +172,23 @@ double DpStCost::GetAccelCostByTwoPoints(const double pre_speed,
double DpStCost::JerkCost(const double jerk) { double DpStCost::JerkCost(const double jerk) {
double cost = 0.0; double cost = 0.0;
constexpr double kEpsilon = 0.1; constexpr double kEpsilon = 0.1;
const int jerk_key = static_cast<int>(jerk / kEpsilon + 0.5); constexpr int kShift = 200;
auto p_val = jerk_cost_map_.find(jerk_key); const int jerk_key = static_cast<int>(jerk / kEpsilon + 0.5) + kShift;
if (p_val == jerk_cost_map_.end()) { DCHECK_LT(jerk_key, jerk_cost_.size());
if (jerk_key < 0 || jerk_key >= jerk_cost_.size()) {
return kInf;
}
if (jerk_cost_.at(jerk_key) < 0.0) {
double jerk_sq = jerk * jerk; double jerk_sq = jerk * jerk;
if (jerk > 0) { if (jerk > 0) {
cost = config_.positive_jerk_coeff() * jerk_sq * unit_t_; cost = config_.positive_jerk_coeff() * jerk_sq * unit_t_;
} else { } else {
cost = config_.negative_jerk_coeff() * jerk_sq * unit_t_; cost = config_.negative_jerk_coeff() * jerk_sq * unit_t_;
} }
jerk_cost_map_[jerk_key] = cost; jerk_cost_.at(jerk_key) = cost;
} else { } else {
cost = p_val->second; cost = jerk_cost_.at(jerk_key);
} }
// TODO(All): normalize to unit_t_ // TODO(All): normalize to unit_t_
......
...@@ -74,14 +74,13 @@ class DpStCost { ...@@ -74,14 +74,13 @@ class DpStCost {
const DpStSpeedConfig& config_; const DpStSpeedConfig& config_;
const std::vector<const PathObstacle*>& obstacles_; const std::vector<const PathObstacle*>& obstacles_;
const common::TrajectoryPoint& init_point_; const common::TrajectoryPoint& init_point_;
double unit_s_ = 0.0;
double unit_t_ = 0.0; double unit_t_ = 0.0;
double unit_v_ = 0.0;
std::unordered_map<std::string, std::pair<double, double>> std::unordered_map<std::string, std::pair<double, double>>
boundary_range_map_; boundary_range_map_;
std::unordered_map<int, double> accel_cost_map_; std::array<double, 200> accel_cost_;
std::unordered_map<int, double> jerk_cost_map_; std::array<double, 400> jerk_cost_;
}; };
} // namespace planning } // namespace planning
......
...@@ -40,6 +40,7 @@ using apollo::common::math::Vec2d; ...@@ -40,6 +40,7 @@ using apollo::common::math::Vec2d;
using apollo::common::VehicleParam; using apollo::common::VehicleParam;
namespace { namespace {
constexpr double kInf = std::numeric_limits<double>::infinity();
bool CheckOverlapOnDpStGraph(const std::vector<const StBoundary*>& boundaries, bool CheckOverlapOnDpStGraph(const std::vector<const StBoundary*>& boundaries,
const StGraphPoint& p1, const StGraphPoint& p2) { const StGraphPoint& p1, const StGraphPoint& p2) {
...@@ -232,6 +233,12 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) { ...@@ -232,6 +233,12 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) {
double speed_limit = double speed_limit =
st_graph_data_.speed_limit().GetSpeedLimitByS(unit_s_ * r); st_graph_data_.speed_limit().GetSpeedLimitByS(unit_s_ * r);
if (c == 1) { if (c == 1) {
const double acc = (r * unit_s_ / unit_t_ - init_point_.v()) / unit_t_;
if (acc < dp_st_speed_config_.max_deceleration() ||
acc > dp_st_speed_config_.max_acceleration()) {
return;
}
if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr, if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr,
cost_init)) { cost_init)) {
return; return;
...@@ -252,6 +259,13 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) { ...@@ -252,6 +259,13 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) {
if (c == 2) { if (c == 2) {
for (uint32_t r_pre = r_low; r_pre <= r; ++r_pre) { for (uint32_t r_pre = r_low; r_pre <= r; ++r_pre) {
const double acc =
(static_cast<int>(r - 2 * r_pre)) * unit_s_ / (unit_t_ * unit_t_);
if (acc < dp_st_speed_config_.max_deceleration() ||
acc > dp_st_speed_config_.max_acceleration()) {
continue;
}
if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr, if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr,
pre_col[r_pre])) { pre_col[r_pre])) {
continue; continue;
...@@ -282,41 +296,31 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) { ...@@ -282,41 +296,31 @@ void DpStGraph::CalculateCostAt(const uint32_t c, const uint32_t r) {
curr_a < vehicle_param_.max_deceleration()) { curr_a < vehicle_param_.max_deceleration()) {
continue; continue;
} }
uint32_t lower_bound = 0;
uint32_t upper_bound = 0;
if (!CalculateFeasibleAccelRange(static_cast<double>(r_pre),
static_cast<double>(r), &lower_bound,
&upper_bound)) {
continue;
}
if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr, if (CheckOverlapOnDpStGraph(st_graph_data_.st_boundaries(), cost_cr,
pre_col[r_pre])) { pre_col[r_pre])) {
continue; continue;
} }
for (uint32_t r_prepre = lower_bound; r_prepre <= upper_bound; ++r_prepre) { uint32_t r_prepre = pre_col[r_pre].pre_point()->index_s();
const StGraphPoint& prepre_graph_point = cost_table_[c - 2][r_prepre]; const StGraphPoint& prepre_graph_point = cost_table_[c - 2][r_prepre];
if (std::isinf(prepre_graph_point.total_cost())) { if (std::isinf(prepre_graph_point.total_cost())) {
continue; continue;
} }
if (!prepre_graph_point.pre_point()) {
continue;
}
const STPoint& triple_pre_point = prepre_graph_point.pre_point()->point();
const STPoint& prepre_point = prepre_graph_point.point();
const STPoint& pre_point = pre_col[r_pre].point();
const STPoint& curr_point = cost_cr.point();
double cost = cost_cr.obstacle_cost() + pre_col[r_pre].total_cost() +
CalculateEdgeCost(triple_pre_point, prepre_point, pre_point,
curr_point, speed_limit);
if (cost < cost_cr.total_cost()) { if (!prepre_graph_point.pre_point()) {
cost_cr.SetTotalCost(cost); continue;
cost_cr.SetPrePoint(pre_col[r_pre]); }
} const STPoint& triple_pre_point = prepre_graph_point.pre_point()->point();
const STPoint& prepre_point = prepre_graph_point.point();
const STPoint& pre_point = pre_col[r_pre].point();
const STPoint& curr_point = cost_cr.point();
double cost = cost_cr.obstacle_cost() + pre_col[r_pre].total_cost() +
CalculateEdgeCost(triple_pre_point, prepre_point, pre_point,
curr_point, speed_limit);
if (cost < cost_cr.total_cost()) {
cost_cr.SetTotalCost(cost);
cost_cr.SetPrePoint(pre_col[r_pre]);
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册