32#include "modules/prediction/proto/offline_features.pb.h"
33#include "modules/prediction/proto/prediction_conf.pb.h"
48 return FLAGS_prediction_module_name;
52 const std::string& features_proto_file_name) {
53 auto obstacles_container_ptr =
56 obstacles_container_ptr->
Clear();
61 obstacles_container_ptr->InsertFeatureProto(feature);
62 Obstacle* obstacle_ptr = obstacles_container_ptr->GetObstacle(feature.id());
66 evaluator_manager_->EvaluateObstacle(obstacle_ptr, obstacles_container_ptr);
73 container_manager_ = std::make_shared<ContainerManager>();
79 if (!ComponentBase::GetProtoConfig(&prediction_conf)) {
80 AERROR <<
"Unable to load prediction conf file: "
81 << ComponentBase::ConfigFilePath();
84 ADEBUG <<
"Prediction config file is loaded into: "
85 << prediction_conf.ShortDebugString();
88 predictor_manager_.get(), prediction_conf)) {
95 localization_reader_ =
118 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
119 if (FLAGS_use_lego) {
120 return ContainerSubmoduleProcess(perception_obstacles);
122 return PredictionEndToEndProc(perception_obstacles);
125bool PredictionComponent::ContainerSubmoduleProcess(
126 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
127 constexpr static size_t kHistorySize = 10;
131 localization_reader_->Observe();
132 auto ptr_localization_msg = localization_reader_->GetLatestObserved();
133 if (ptr_localization_msg ==
nullptr) {
134 AERROR <<
"Prediction: cannot receive any localization message.";
138 *ptr_localization_msg);
142 planning_reader_->Observe();
143 auto ptr_trajectory_msg = planning_reader_->GetLatestObserved();
144 if (ptr_trajectory_msg !=
nullptr) {
150 storytelling_reader_->Observe();
151 auto ptr_storytelling_msg = storytelling_reader_->GetLatestObserved();
152 if (ptr_storytelling_msg !=
nullptr) {
154 *ptr_storytelling_msg);
158 scenario_manager_.get());
160 auto obstacles_container_ptr =
161 container_manager_->GetContainer<ObstaclesContainer>(
163 CHECK_NOTNULL(obstacles_container_ptr);
165 auto adc_trajectory_container_ptr =
166 container_manager_->GetContainer<ADCTrajectoryContainer>(
168 CHECK_NOTNULL(adc_trajectory_container_ptr);
170 SubmoduleOutput submodule_output =
171 obstacles_container_ptr->GetSubmoduleOutput(kHistorySize,
173 submodule_output.set_curr_scenario(scenario_manager_->scenario());
174 container_writer_->Write(submodule_output);
175 adc_container_writer_->Write(*adc_trajectory_container_ptr);
176 perception_obstacles_writer_->Write(*perception_obstacles);
180bool PredictionComponent::PredictionEndToEndProc(
181 const std::shared_ptr<PerceptionObstacles>& perception_obstacles) {
182 if (FLAGS_prediction_test_mode &&
184 FLAGS_prediction_test_duration)) {
185 ADEBUG <<
"Prediction finished running in test mode";
190 AERROR <<
"Relative map is empty.";
195 auto end_time1 = std::chrono::system_clock::now();
199 localization_reader_->Observe();
200 auto ptr_localization_msg = localization_reader_->GetLatestObserved();
201 if (ptr_localization_msg ==
nullptr) {
202 AERROR <<
"Prediction: cannot receive any localization message.";
206 *ptr_localization_msg);
207 auto end_time2 = std::chrono::system_clock::now();
208 std::chrono::duration<double>
diff = end_time2 - end_time1;
209 ADEBUG <<
"Time for updating PoseContainer: " <<
diff.count() * 1000
214 storytelling_reader_->Observe();
215 auto ptr_storytelling_msg = storytelling_reader_->GetLatestObserved();
216 if (ptr_storytelling_msg !=
nullptr) {
218 *ptr_storytelling_msg);
223 planning_reader_->Observe();
224 auto ptr_trajectory_msg = planning_reader_->GetLatestObserved();
225 if (ptr_trajectory_msg !=
nullptr) {
228 auto end_time3 = std::chrono::system_clock::now();
229 diff = end_time3 - end_time2;
230 ADEBUG <<
"Time for updating ADCTrajectoryContainer: " <<
diff.count() * 1000
235 auto perception_msg = *perception_obstacles;
236 PredictionObstacles prediction_obstacles;
238 perception_msg, container_manager_, evaluator_manager_.get(),
239 predictor_manager_.get(), scenario_manager_.get(), &prediction_obstacles);
240 auto end_time4 = std::chrono::system_clock::now();
241 diff = end_time4 - end_time3;
242 ADEBUG <<
"Time for updating PerceptionContainer: " <<
diff.count() * 1000
246 prediction_obstacles.set_start_timestamp(frame_start_time_);
248 prediction_obstacles.mutable_header()->set_lidar_timestamp(
249 perception_msg.header().lidar_timestamp());
250 prediction_obstacles.mutable_header()->set_camera_timestamp(
251 perception_msg.header().camera_timestamp());
252 prediction_obstacles.mutable_header()->set_radar_timestamp(
253 perception_msg.header().radar_timestamp());
255 prediction_obstacles.set_perception_error_code(perception_msg.error_code());
257 if (FLAGS_prediction_test_mode) {
258 for (
auto const& prediction_obstacle :
259 prediction_obstacles.prediction_obstacle()) {
260 for (
auto const& trajectory : prediction_obstacle.trajectory()) {
261 for (
auto const& trajectory_point : trajectory.trajectory_point()) {
263 AERROR <<
"Invalid trajectory point ["
264 << trajectory_point.ShortDebugString() <<
"]";
272 auto end_time5 = std::chrono::system_clock::now();
273 diff = end_time5 - end_time1;
274 ADEBUG <<
"End to end time elapsed: " <<
diff.count() * 1000 <<
" msec.";
277 common::util::FillHeader(
node_->Name(), &prediction_obstacles);
278 prediction_writer_->Write(prediction_obstacles);
280 if (FLAGS_prediction_eval_mode) {
281 for (
auto const& prediction_obstacle :
282 prediction_obstacles.prediction_obstacle()) {
283 AINFO <<
"prediction_eval_log (info): "
284 << std::to_string(prediction_obstacle.timestamp()) <<
", "
285 << prediction_obstacle.perception_obstacle().id() <<
", "
286 << prediction_obstacle.priority().priority() <<
", "
287 << prediction_obstacle.perception_obstacle().type() <<
", "
289 prediction_obstacle.perception_obstacle().position().x())
290 <<
", " << std::to_string(
291 prediction_obstacle.perception_obstacle().position().y());
293 if (prediction_obstacle.trajectory_size() != 0) {
294 for (
auto const& trajectory : prediction_obstacle.trajectory()) {
295 for (
auto const& trajectory_point : trajectory.trajectory_point()) {
296 AINFO <<
"prediction_eval_log (traj): "
297 << std::to_string(prediction_obstacle.timestamp()) <<
", "
298 << prediction_obstacle.perception_obstacle().id() <<
", "
299 << std::to_string(trajectory_point.path_point().x()) <<
", "
300 << 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,...
float diff(Image< float > *I, int x1, int y1, int x2, int y2)
Dissimilarity measure between pixels
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