32#include "modules/prediction/proto/offline_features.pb.h"
33#include "modules/prediction/proto/prediction_conf.pb.h"
49 return FLAGS_prediction_module_name;
53 const std::string& features_proto_file_name) {
54 auto obstacles_container_ptr =
57 obstacles_container_ptr->
Clear();
62 obstacles_container_ptr->InsertFeatureProto(feature);
63 Obstacle* obstacle_ptr = obstacles_container_ptr->GetObstacle(feature.id());
67 evaluator_manager_->EvaluateObstacle(obstacle_ptr, obstacles_container_ptr);
74 container_manager_ = std::make_shared<ContainerManager>();
80 if (!ComponentBase::GetProtoConfig(&prediction_conf)) {
81 AERROR <<
"Unable to load prediction conf file: "
82 << ComponentBase::ConfigFilePath();
85 ADEBUG <<
"Prediction config file is loaded into: "
86 << prediction_conf.ShortDebugString();
89 predictor_manager_.get(), prediction_conf)) {
96 localization_reader_ =
119 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
120 if (FLAGS_use_lego) {
121 return ContainerSubmoduleProcess(perception_obstacles);
123 return PredictionEndToEndProc(perception_obstacles);
126bool PredictionComponent::ContainerSubmoduleProcess(
127 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
128 constexpr static size_t kHistorySize = 10;
132 localization_reader_->Observe();
133 auto ptr_localization_msg = localization_reader_->GetLatestObserved();
134 if (ptr_localization_msg ==
nullptr) {
135 AERROR <<
"Prediction: cannot receive any localization message.";
139 *ptr_localization_msg);
143 planning_reader_->Observe();
144 auto ptr_trajectory_msg = planning_reader_->GetLatestObserved();
145 if (ptr_trajectory_msg !=
nullptr) {
151 storytelling_reader_->Observe();
152 auto ptr_storytelling_msg = storytelling_reader_->GetLatestObserved();
153 if (ptr_storytelling_msg !=
nullptr) {
155 *ptr_storytelling_msg);
159 scenario_manager_.get());
161 auto obstacles_container_ptr =
162 container_manager_->GetContainer<ObstaclesContainer>(
164 CHECK_NOTNULL(obstacles_container_ptr);
166 auto adc_trajectory_container_ptr =
167 container_manager_->GetContainer<ADCTrajectoryContainer>(
169 CHECK_NOTNULL(adc_trajectory_container_ptr);
171 SubmoduleOutput submodule_output =
172 obstacles_container_ptr->GetSubmoduleOutput(kHistorySize,
174 submodule_output.set_curr_scenario(scenario_manager_->scenario());
175 container_writer_->Write(submodule_output);
176 adc_container_writer_->Write(*adc_trajectory_container_ptr);
177 perception_obstacles_writer_->Write(*perception_obstacles);
181bool PredictionComponent::PredictionEndToEndProc(
182 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
183 if (FLAGS_prediction_test_mode &&
185 FLAGS_prediction_test_duration)) {
186 ADEBUG <<
"Prediction finished running in test mode";
191 AERROR <<
"Relative map is empty.";
196 auto end_time1 = std::chrono::system_clock::now();
200 localization_reader_->Observe();
201 auto ptr_localization_msg = localization_reader_->GetLatestObserved();
202 if (ptr_localization_msg ==
nullptr) {
203 AERROR <<
"Prediction: cannot receive any localization message.";
207 *ptr_localization_msg);
208 auto end_time2 = std::chrono::system_clock::now();
209 std::chrono::duration<double> diff = end_time2 - end_time1;
210 ADEBUG <<
"Time for updating PoseContainer: " << diff.count() * 1000
215 storytelling_reader_->Observe();
216 auto ptr_storytelling_msg = storytelling_reader_->GetLatestObserved();
217 if (ptr_storytelling_msg !=
nullptr) {
219 *ptr_storytelling_msg);
224 planning_reader_->Observe();
225 auto ptr_trajectory_msg = planning_reader_->GetLatestObserved();
226 if (ptr_trajectory_msg !=
nullptr) {
229 auto end_time3 = std::chrono::system_clock::now();
230 diff = end_time3 - end_time2;
231 ADEBUG <<
"Time for updating ADCTrajectoryContainer: " << diff.count() * 1000
236 auto perception_msg = *perception_obstacles;
237 PredictionObstacles prediction_obstacles;
239 perception_msg, container_manager_, evaluator_manager_.get(),
240 predictor_manager_.get(), scenario_manager_.get(), &prediction_obstacles);
241 auto end_time4 = std::chrono::system_clock::now();
242 diff = end_time4 - end_time3;
243 ADEBUG <<
"Time for updating PerceptionContainer: " << diff.count() * 1000
247 prediction_obstacles.set_start_timestamp(frame_start_time_);
249 prediction_obstacles.mutable_header()->set_lidar_timestamp(
250 perception_msg.header().lidar_timestamp());
251 prediction_obstacles.mutable_header()->set_camera_timestamp(
252 perception_msg.header().camera_timestamp());
253 prediction_obstacles.mutable_header()->set_radar_timestamp(
254 perception_msg.header().radar_timestamp());
256 for (
const PerceptionWaste& perception_waste :
257 perception_msg.perception_waste()) {
258 prediction_obstacles.add_perception_waste()->CopyFrom(
262 prediction_obstacles.set_perception_error_code(perception_msg.error_code());
264 if (FLAGS_prediction_test_mode) {
265 for (
auto const& prediction_obstacle :
266 prediction_obstacles.prediction_obstacle()) {
267 for (
auto const& trajectory : prediction_obstacle.trajectory()) {
268 for (
auto const& trajectory_point : trajectory.trajectory_point()) {
270 AERROR <<
"Invalid trajectory point ["
271 << trajectory_point.ShortDebugString() <<
"]";
279 auto end_time5 = std::chrono::system_clock::now();
280 diff = end_time5 - end_time1;
281 ADEBUG <<
"End to end time elapsed: " << diff.count() * 1000 <<
" msec.";
284 common::util::FillHeader(
node_->Name(), &prediction_obstacles);
285 prediction_writer_->Write(prediction_obstacles);
287 if (FLAGS_prediction_eval_mode) {
288 for (
auto const& prediction_obstacle :
289 prediction_obstacles.prediction_obstacle()) {
290 AINFO <<
"prediction_eval_log (info): "
291 << std::to_string(prediction_obstacle.timestamp()) <<
", "
292 << prediction_obstacle.perception_obstacle().id() <<
", "
293 << prediction_obstacle.priority().priority() <<
", "
294 << prediction_obstacle.perception_obstacle().type() <<
", "
296 prediction_obstacle.perception_obstacle().position().x())
297 <<
", " << std::to_string(
298 prediction_obstacle.perception_obstacle().position().y());
300 if (prediction_obstacle.trajectory_size() != 0) {
301 for (
auto const& trajectory : prediction_obstacle.trajectory()) {
302 for (
auto const& trajectory_point : trajectory.trajectory_point()) {
303 AINFO <<
"prediction_eval_log (traj): "
304 << std::to_string(prediction_obstacle.timestamp()) <<
", "
305 << prediction_obstacle.perception_obstacle().id() <<
", "
306 << std::to_string(trajectory_point.path_point().x()) <<
", "
307 << std::to_string(trajectory_point.path_point().y());
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
std::shared_ptr< Node > node_
static void OnPerception(const perception::PerceptionObstacles &perception_obstacles, const std::shared_ptr< ContainerManager > &container_manager, EvaluatorManager *evaluator_manager, PredictorManager *predictor_manager, ScenarioManager *scenario_manager, PredictionObstacles *const prediction_obstacles)
static void OnStoryTelling(ContainerManager *container_manager, const storytelling::Stories &story)
static void OnLocalization(ContainerManager *container_manager, const localization::LocalizationEstimate &localization)
static void OnPlanning(ContainerManager *container_manager, const planning::ADCTrajectory &adc_trajectory)
static bool Init(ContainerManager *container_manager, EvaluatorManager *evaluator_manager, PredictorManager *predictor_manager, const PredictionConf &prediction_conf)
static void ContainerProcess(const std::shared_ptr< ContainerManager > &container_manager, const perception::PerceptionObstacles &perception_obstacles, ScenarioManager *scenario_manger)
void Clear()
Clear obstacle container
~PredictionComponent()
Destructor
bool Proc(const std::shared_ptr< perception::PerceptionObstacles > &) override
Data callback upon receiving a perception obstacle message.
void OfflineProcessFeatureProtoFile(const std::string &features_proto_file)
Load and process feature proto file.
bool Init() override
Initialize the node
std::string Name() const
Get name of the node
static bool Ready()
Check if map is ready
static bool ValidTrajectoryPoint(const common::TrajectoryPoint &trajectory_point)
Check if a trajectory point is valid
Some string util functions.
bool GetProtoFromBinaryFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as binary representation of protobufs,...
Use evaluator manager to manage all evaluators
Use predictor manager to manage all predictors
optional TopicConf topic_conf
optional string prediction_topic
optional string container_topic_name
optional string planning_trajectory_topic
optional string localization_topic
optional string perception_obstacles_topic_name
optional string adccontainer_topic_name
optional string storytelling_topic