36 : ptr_obstacles_(FLAGS_max_num_obstacles),
40 : ptr_obstacles_(FLAGS_max_num_obstacles),
44 std::unique_ptr<Obstacle> ptr_obstacle(
new Obstacle(obstacle));
45 ptr_obstacle->SetJunctionAnalyzer(&junction_analyzer_);
46 ptr_obstacles_.Put(obstacle.id(), std::move(ptr_obstacle));
50 std::unique_ptr<Obstacle> ptr_ego_vehicle(
51 new Obstacle(std::move(ego_vehicle)));
52 ptr_ego_vehicle->SetJunctionAnalyzer(&junction_analyzer_);
53 ptr_obstacles_.Put(ego_vehicle.
id(), std::move(ptr_ego_vehicle));
55 curr_frame_movable_obstacle_ids_ =
57 curr_frame_unmovable_obstacle_ids_ =
59 curr_frame_considered_obstacle_ids_ =
66 curr_frame_movable_obstacle_ids_.clear();
67 curr_frame_unmovable_obstacle_ids_.clear();
68 curr_frame_considered_obstacle_ids_.clear();
75 perception_obstacles.CopyFrom(
84 if (perception_obstacles.has_header() &&
85 perception_obstacles.
header().has_timestamp_sec()) {
88 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap) {
89 ptr_obstacles_.Clear();
90 ADEBUG <<
"Replay mode is enabled.";
93 << timestamp_ <<
"].";
97 switch (FLAGS_prediction_offline_mode) {
99 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap ||
106 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap ||
108 FLAGS_max_num_dump_dataforlearn) {
114 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap ||
116 FLAGS_max_num_dump_feature) {
122 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap ||
129 if (std::fabs(
timestamp - timestamp_) > FLAGS_replay_timestamp_gap ||
143 ADEBUG <<
"Current timestamp is [" << std::fixed << std::setprecision(6)
144 << timestamp_ <<
"]";
150 ADEBUG <<
"Perception obstacle [" << perception_obstacle.id() <<
"] "
153 ADEBUG <<
"Perception obstacle [" << perception_obstacle.id() <<
"] "
158 clusters_->SortObstacles();
162 auto ptr_obstacle = ptr_obstacles_.GetSilently(
id);
163 if (ptr_obstacle !=
nullptr) {
164 return ptr_obstacle->get();
169Obstacle* ObstaclesContainer::GetObstacleWithLRUUpdate(
const int obstacle_id) {
170 auto ptr_obstacle = ptr_obstacles_.Get(obstacle_id);
171 if (ptr_obstacle !=
nullptr) {
172 return ptr_obstacle->get();
178 ptr_obstacles_.Clear();
183 return curr_frame_movable_obstacle_ids_;
186const std::vector<int>&
188 return curr_frame_unmovable_obstacle_ids_;
191const std::vector<int>&
193 return curr_frame_considered_obstacle_ids_;
197 curr_frame_considered_obstacle_ids_.clear();
198 for (
const int id : curr_frame_movable_obstacle_ids_) {
200 if (obstacle_ptr ==
nullptr) {
201 AERROR <<
"Null obstacle found.";
205 ADEBUG <<
"Ignore obstacle [" << obstacle_ptr->
id() <<
"]";
208 curr_frame_considered_obstacle_ids_.push_back(
id);
213 std::vector<int> curr_frame_obs_ids = curr_frame_movable_obstacle_ids_;
214 curr_frame_obs_ids.insert(curr_frame_obs_ids.end(),
215 curr_frame_unmovable_obstacle_ids_.begin(),
216 curr_frame_unmovable_obstacle_ids_.end());
217 return curr_frame_obs_ids;
223 int id = perception_obstacle.
id();
224 if (
id < FLAGS_ego_vehicle_id) {
225 AERROR <<
"Invalid ID [" <<
id <<
"]";
228 if (!IsMovable(perception_obstacle)) {
229 ADEBUG <<
"Perception obstacle [" << perception_obstacle.
id()
230 <<
"] is unmovable.";
231 curr_frame_unmovable_obstacle_ids_.push_back(
id);
236 auto obstacle_ptr = GetObstacleWithLRUUpdate(
id);
237 if (obstacle_ptr !=
nullptr) {
238 ADEBUG <<
"Current time = " << std::fixed << std::setprecision(6)
240 obstacle_ptr->Insert(perception_obstacle,
timestamp,
id);
241 ADEBUG <<
"Refresh obstacle [" <<
id <<
"]";
245 if (ptr_obstacle ==
nullptr) {
246 AERROR <<
"Failed to insert obstacle into container";
249 ptr_obstacle->SetJunctionAnalyzer(&junction_analyzer_);
250 ptr_obstacles_.Put(
id, std::move(ptr_obstacle));
251 ADEBUG <<
"Insert obstacle [" <<
id <<
"]";
254 if (FLAGS_prediction_offline_mode ==
256 id != FLAGS_ego_vehicle_id) {
257 curr_frame_movable_obstacle_ids_.push_back(
id);
262 if (!feature.has_id()) {
263 AERROR <<
"Invalid feature, no ID found.";
266 int id = feature.
id();
267 auto obstacle_ptr = GetObstacleWithLRUUpdate(
id);
268 if (obstacle_ptr !=
nullptr) {
269 obstacle_ptr->InsertFeature(feature);
272 if (ptr_obstacle ==
nullptr) {
273 AERROR <<
"Failed to insert obstacle into container";
276 ptr_obstacle->SetJunctionAnalyzer(&junction_analyzer_);
277 ptr_obstacles_.Put(
id, std::move(ptr_obstacle));
284 for (
const int id : curr_frame_considered_obstacle_ids_) {
286 if (obstacle_ptr ==
nullptr) {
287 AERROR <<
"Null obstacle found.";
290 if (FLAGS_prediction_offline_mode !=
292 ADEBUG <<
"Building Lane Graph.";
296 ADEBUG <<
"Building ordered Lane Graph.";
297 ADEBUG <<
"Building lane graph for id = " << id;
304 if (ego_vehicle_ptr ==
nullptr) {
305 AERROR <<
"Ego vehicle not inserted";
315 for (
const int id : curr_frame_considered_obstacle_ids_) {
317 if (obstacle_ptr ==
nullptr) {
318 AERROR <<
"Null obstacle found.";
321 const std::string& junction_id = junction_analyzer_.
GetJunctionId();
323 AINFO <<
"Build junction feature for obstacle [" << obstacle_ptr->
id()
324 <<
"] in junction [" << junction_id <<
"]";
330bool ObstaclesContainer::IsMovable(
332 if (!perception_obstacle.has_type() ||
344 for (
int id : curr_frame_considered_obstacle_ids_) {
346 if (obstacle ==
nullptr) {
347 AERROR <<
"Nullptr found for obstacle [" <<
id <<
"]";
356 if (ego_obstacle !=
nullptr) {
361 curr_frame_movable_obstacle_ids_);
363 curr_frame_unmovable_obstacle_ids_);
365 curr_frame_considered_obstacle_ids_);
368 return container_output;
372 return curr_scenario_;
376 return clusters_.get();
379 return &junction_analyzer_;
Cyber has builtin time type Time.
static void WriteDataForLearning()
Write DataForLearning features to a file
static int SizeOfPredictionResult()
Get the size of prediction results.
static int Size()
Get feature size
static int SizeOfFrameEnv()
Get the size of frame env.
static void WriteDataForTuning()
Write DataForTuning features to a file
static int SizeOfDataForLearning()
Get the size of data_for_learning features.
static void WriteFrameEnv()
Write frame env to a file
static void WriteFeatureProto()
Write features to a file
static void WritePredictionResult()
Write PredictionResult to a file
const std::string & GetJunctionId()
Get junction ID
bool IsInJunction(const std::string &junction_id) const
Check if the obstacle is a junction.
void SetNearbyObstacles()
Set nearby obstacles.
void BuildLaneGraphFromLeftToRight()
Build obstacle's lane graph with lanes being ordered.
void BuildLaneGraph()
Build obstacle's lane graph
void ClearOldInformation()
void TrimHistory(const size_t remain_size)
int id() const
Get the obstacle's ID.
bool ToIgnore()
Check if the obstacle can be ignored.
void BuildJunctionFeature()
Build junction feature.
static std::unique_ptr< Obstacle > Create(const perception::PerceptionObstacle &perception_obstacle, const double timestamp, const int prediction_id, ObstacleClusters *clusters_ptr)
Constructor
SubmoduleOutput GetSubmoduleOutput(const size_t history_size, const apollo::cyber::Time &frame_start_time)
JunctionAnalyzer * GetJunctionAnalyzer()
void Clear()
Clear obstacle container
ObstacleClusters * GetClustersPtr() const
Get the raw pointer of clusters_
void SetConsideredObstacleIds()
const std::vector< int > & curr_frame_movable_obstacle_ids()
Get movable obstacle IDs in the current frame
void Insert(const ::google::protobuf::Message &message) override
Insert a data message into the container
const std::vector< int > & curr_frame_unmovable_obstacle_ids()
Get unmovable obstacle IDs in the current frame
const std::vector< int > & curr_frame_considered_obstacle_ids()
Get non-ignore obstacle IDs in the current frame
const Scenario & curr_scenario() const
Get current scenario
void BuildLaneGraph()
Build lane graph for obstacles
Obstacle * GetObstacle(const int id)
Get obstacle pointer
std::vector< int > curr_frame_obstacle_ids()
Get current frame obstacle IDs in the current frame
void BuildJunctionFeature()
Build junction feature for obstacles
ObstaclesContainer()
Constructor
void InsertFeatureProto(const Feature &feature)
Insert a feature proto message into the container
void InsertPerceptionObstacle(const perception::PerceptionObstacle &perception_obstacle, const double timestamp)
Insert an perception obstacle
static const int kDumpDataForLearning
const std::vector< Obstacle > & curr_frame_obstacles() const
void set_curr_frame_movable_obstacle_ids(const std::vector< int > &curr_frame_movable_obstacle_ids)
void InsertEgoVehicle(const Obstacle &&ego_vehicle)
void set_curr_frame_unmovable_obstacle_ids(const std::vector< int > &curr_frame_unmovable_obstacle_ids)
void InsertObstacle(const Obstacle &&obstacle)
const Scenario & curr_scenario() const
void set_curr_frame_considered_obstacle_ids(const std::vector< int > &curr_frame_considered_obstacle_ids)
std::vector< int > curr_frame_considered_obstacle_ids() const
void set_frame_start_time(const apollo::cyber::Time &frame_start_time)
std::vector< int > curr_frame_movable_obstacle_ids() const
const Obstacle & GetEgoVehicle() const
std::vector< int > curr_frame_unmovable_obstacle_ids() const
Holds all global constants for the prediction module.
repeated PerceptionObstacle perception_obstacle
optional apollo::common::Header header