提交 759d203f 编写于 作者: D Dong Li 提交者: lianglia-apollo

move ObjectTable out of DataCenter

* prepare for further refactor ObjectTable and DataCenter
上级 dd23004e
......@@ -23,14 +23,9 @@ cc_library(
)
cc_library(
name = "object_table",
name = "indexed_queue",
hdrs = [
"object_table.h",
],
deps = [
":indexed_list",
":obstacle",
":planning_gflags",
"indexed_queue.h",
],
)
......@@ -106,6 +101,7 @@ cc_library(
"frame.h",
],
deps = [
":indexed_list",
"//modules/common:log",
"//modules/common/adapters:adapter_manager",
"//modules/common/vehicle_state",
......@@ -146,20 +142,13 @@ cc_library(
cc_library(
name = "data_center",
srcs = [
"data_center.cc",
],
hdrs = [
"data_center.h",
],
deps = [
":frame",
":object_table",
":planning_gflags",
":indexed_queue",
"//modules/common",
"//modules/common/adapters:adapter_manager",
"//modules/common/status",
"//modules/map/hdmap",
],
)
......
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file:
**/
#include "modules/planning/common/data_center.h"
#include <fstream>
#include <utility>
#include <vector>
#include "modules/map/proto/map_id.pb.h"
#include "google/protobuf/text_format.h"
#include "modules/common/adapters/adapter_manager.h"
#include "modules/common/log.h"
#include "modules/common/util/util.h"
#include "modules/planning/common/planning_gflags.h"
namespace apollo {
namespace planning {
using apollo::common::Status;
using apollo::common::math::Vec2d;
using apollo::common::adapter::AdapterManager;
DataCenter::DataCenter() {
_object_table.reset(new ObjectTable());
AINFO << "Data Center is ready!";
}
Frame *DataCenter::frame(const uint32_t sequence_num) const {
std::unordered_map<uint32_t, std::unique_ptr<Frame>>::const_iterator it =
_frames.find(sequence_num);
if (it != _frames.end()) {
return it->second.get();
}
return nullptr;
}
void DataCenter::save_frame() {
_sequence_queue.push_back(_frame->sequence_num());
_frames[_frame->sequence_num()] = std::move(_frame);
if (_sequence_queue.size() >
static_cast<std::size_t>(FLAGS_max_history_result)) {
_frames.erase(_sequence_queue.front());
_sequence_queue.pop_front();
}
}
const Frame *DataCenter::last_frame() const {
if (_sequence_queue.empty()) {
return nullptr;
}
uint32_t sequence_num = _sequence_queue.back();
return _frames.find(sequence_num)->second.get();
}
ObjectTable *DataCenter::mutable_object_table() const {
return _object_table.get();
}
const ObjectTable &DataCenter::object_table() const {
return *(_object_table.get());
}
} // namespace planning
} // namespace apollo
......@@ -26,37 +26,13 @@
#include <unordered_map>
#include "modules/common/macro.h"
#include "modules/common/status/status.h"
#include "modules/map/hdmap/hdmap.h"
#include "modules/map/pnc_map/pnc_map.h"
#include "modules/planning/common/frame.h"
#include "modules/planning/common/object_table.h"
#include "modules/planning/common/indexed_queue.h"
namespace apollo {
namespace planning {
class DataCenter {
public:
~DataCenter() = default;
Frame *frame(const uint32_t sequence_num) const;
public:
void save_frame();
const Frame *last_frame() const;
const ObjectTable &object_table() const;
ObjectTable *mutable_object_table() const;
private:
std::unordered_map<uint32_t, std::unique_ptr<Frame>> _frames;
std::list<uint32_t> _sequence_queue;
std::unique_ptr<Frame> _frame = nullptr;
std::unique_ptr<ObjectTable> _object_table = nullptr;
private:
DECLARE_SINGLETON(DataCenter);
};
using DataCenter = IndexedQueue<uint32_t, Frame>;
} // namespace planning
} // namespace apollo
......
......@@ -176,6 +176,9 @@ bool Frame::SmoothReferenceLine() {
return true;
}
const ObstacleTable &Frame::GetObstacleTable() const { return obstacle_table_; }
ObstacleTable *Frame::MutableObstacleTable() { return &obstacle_table_; }
std::string Frame::DebugString() const {
return "Frame: " + std::to_string(sequence_num_);
}
......
......@@ -30,12 +30,16 @@
#include "modules/map/hdmap/hdmap.h"
#include "modules/map/pnc_map/pnc_map.h"
#include "modules/map/proto/routing.pb.h"
#include "modules/planning/common/indexed_list.h"
#include "modules/planning/common/obstacle.h"
#include "modules/planning/common/planning_data.h"
#include "modules/prediction/proto/prediction_obstacle.pb.h"
namespace apollo {
namespace planning {
using ObstacleTable = IndexedList<uint32_t, Obstacle>;
class Frame {
public:
Frame(const uint32_t sequence_num);
......@@ -56,6 +60,9 @@ class Frame {
PlanningData *mutable_planning_data();
std::string DebugString() const;
const ObstacleTable &GetObstacleTable() const;
ObstacleTable *MutableObstacleTable();
void set_computed_trajectory(const PublishableTrajectory &trajectory);
const PublishableTrajectory &computed_trajectory() const;
......@@ -70,6 +77,7 @@ class Frame {
hdmap::RoutingResult routing_result_;
prediction::PredictionObstacles prediction_;
ObstacleTable obstacle_table_;
uint32_t sequence_num_ = 0;
hdmap::Path hdmap_path_;
localization::Pose init_pose_;
......
......@@ -31,9 +31,13 @@ namespace planning {
template <typename I, typename T>
class IndexedList {
public:
void Add(const I id, std::unique_ptr<T> ptr) {
bool Add(const I id, std::unique_ptr<T> ptr) {
if (Find(id)) {
return false;
}
_object_list.push_back(ptr.get());
_object_dict[id] = std::move(ptr);
return true;
}
T* Find(const I id) {
auto iter = _object_dict.find(id);
......
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file object_table.h
**/
#ifndef MODULES_PLANNING_COMMON_OBJECT_TABLE_H
#define MODULES_PLANNING_COMMON_OBJECT_TABLE_H
#include <memory>
#include <string>
#include <unordered_map>
#include "modules/planning/common/indexed_list.h"
#include "modules/planning/common/obstacle.h"
#include "modules/planning/common/planning_gflags.h"
namespace apollo {
namespace planning {
using ObjectTable = IndexedList<uint32_t, Obstacle>;
} // namespace planning
} // namespace apollo
#endif // MODULES_PLANNING_COMMON_OBJECT_TABLE_H
......@@ -32,6 +32,7 @@ cc_library(
"//modules/common/configs/proto:vehicle_config_proto",
"//modules/common/proto:common_proto",
"//modules/common/proto:pnc_point_proto",
"//modules/common/status",
"//modules/planning/common:data_center",
"//modules/planning/common:decision_data",
"//modules/planning/common/speed:speed_data",
......
......@@ -41,7 +41,7 @@ DpStGraph::DpStGraph(const DpStSpeedConfig& dp_config)
Status DpStGraph::Search(const StGraphData& st_graph_data,
DecisionData* const decision_data,
SpeedData* const speed_data) {
SpeedData* const speed_data, ObstacleTable* table) {
init_point_ = st_graph_data.init_point();
if (st_graph_data.path_data_length() <
......@@ -69,7 +69,7 @@ Status DpStGraph::Search(const StGraphData& st_graph_data,
return Status(ErrorCode::PLANNING_ERROR, msg);
}
if (!get_object_decision(st_graph_data, *speed_data).ok()) {
if (!get_object_decision(st_graph_data, *speed_data, table).ok()) {
const std::string msg = "Get object decision by speed profile failed.";
AERROR << msg;
return Status(ErrorCode::PLANNING_ERROR, msg);
......@@ -283,7 +283,8 @@ Status DpStGraph::retrieve_speed_profile(SpeedData* const speed_data) const {
}
Status DpStGraph::get_object_decision(const StGraphData& st_graph_data,
const SpeedData& speed_profile) const {
const SpeedData& speed_profile,
ObstacleTable* obstacles) const {
if (speed_profile.speed_vector().size() < 2) {
const std::string msg = "dp_st_graph failed to get speed profile.";
AERROR << msg;
......@@ -299,8 +300,7 @@ Status DpStGraph::get_object_decision(const StGraphData& st_graph_data,
boundary_it != obs_boundaries.end(); ++boundary_it) {
CHECK_EQ(boundary_it->points().size(), 4);
Obstacle* object_ptr =
DataCenter::instance()->mutable_object_table()->Find(boundary_it->id());
Obstacle* object_ptr = obstacles->Find(boundary_it->id());
if (!object_ptr) {
AERROR << "Failed to find object " << boundary_it->id();
return Status(ErrorCode::PLANNING_ERROR,
......
......@@ -29,6 +29,7 @@
#include "modules/common/status/status.h"
#include "modules/planning/common/decision_data.h"
#include "modules/planning/common/frame.h"
#include "modules/planning/common/speed/speed_data.h"
#include "modules/planning/common/speed/st_point.h"
#include "modules/planning/optimizer/dp_st_speed/dp_st_cost.h"
......@@ -43,7 +44,8 @@ class DpStGraph {
apollo::common::Status Search(const StGraphData& st_graph_data,
DecisionData* const decision_data,
SpeedData* const speed_data);
SpeedData* const speed_data,
ObstacleTable* table);
private:
apollo::common::Status InitCostTable();
......@@ -53,8 +55,9 @@ class DpStGraph {
apollo::common::Status retrieve_speed_profile(
SpeedData* const speed_data) const;
apollo::common::Status get_object_decision(
const StGraphData& st_graph_data, const SpeedData& speed_profile) const;
apollo::common::Status get_object_decision(const StGraphData& st_graph_data,
const SpeedData& speed_profile,
ObstacleTable* obstacles) const;
apollo::common::Status CalculateTotalCost(const StGraphData& st_graph_data);
void CalculateCostAt(const StGraphData& st_graph_data, const uint32_t r,
......
......@@ -101,7 +101,10 @@ Status DpStSpeedOptimizer::Process(const PathData& path_data,
StGraphData st_graph_data(boundaries, init_point, speed_limit, path_length);
DpStGraph st_graph(dp_st_speed_config_);
if (!st_graph.Search(st_graph_data, decision_data, speed_data).ok()) {
if (!st_graph
.Search(st_graph_data, decision_data, speed_data,
frame_->MutableObstacleTable())
.ok()) {
const std::string msg = "Failed to search graph with dynamic programming.";
AERROR << msg;
return Status(ErrorCode::PLANNING_ERROR, msg);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册