Apollo 10.0
自动驾驶开放平台
mrf_motion_refiner.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <algorithm>
20#include <limits>
21
22#include "cyber/common/file.h"
25
26namespace apollo {
27namespace perception {
28namespace radar4d {
29
31 std::string config_file = "mrf_motion_refiner.pb.txt";
32 if (!options.config_file.empty()) {
33 config_file = options.config_file;
34 }
35 config_file = GetConfigFile(options.config_path, config_file);
38 // read from proto config
41 return true;
42}
43
45 TrackedObjectPtr new_object) {
46 auto latest_object_pair = track_data->GetLatestObject();
47 const TrackedObjectConstPtr& latest_object = latest_object_pair.second;
48
49 // 1. keep motion if acceleration of filter is greater than a threshold
50 double time_diff = new_object->object_ptr->latest_tracked_time -
51 latest_object->object_ptr->latest_tracked_time;
52 Eigen::Vector3d filter_velocity_gain = new_object->belief_velocity_gain;
53 double filter_acceleration_gain = 0.0;
54 if (fabs(time_diff) < EPSION_TIME) {
55 filter_acceleration_gain = 0.0;
56 } else {
57 filter_acceleration_gain = filter_velocity_gain.norm() / time_diff;
58 }
59 bool need_keep_motion =
60 filter_acceleration_gain > claping_acceleration_threshold_;
61 // use tighter threshold for pedestrian
62 if (filter_acceleration_gain > claping_acceleration_threshold_ / 2 &&
63 new_object->type == base::ObjectType::PEDESTRIAN) {
64 need_keep_motion = true;
65 }
66
67 if (need_keep_motion && (!new_object->converged)) {
68 Eigen::Vector3d current_velocity = Eigen::Vector3d::Zero();
69 current_velocity = latest_object->output_velocity;
70 new_object->output_velocity = current_velocity;
71 AINFO << "Track_id " << track_data->track_id_
72 << ", keep motion because of extraodinary acceleration.";
73 return true;
74 }
75 // 2. static hypothesis check
76 bool is_static_hypothesis =
77 CheckStaticHypothesisByState(latest_object, new_object);
78
79 if (is_static_hypothesis) {
80 new_object->output_velocity = Eigen::Vector3d::Zero();
81 new_object->state.tail<2>().setZero();
82 AINFO << "Track_id " << track_data->track_id_
83 << ", set velocity to zero because of noise claping.";
84 return true;
85 }
86 return false;
87}
88
90 const TrackedObjectConstPtr& latest_object,
91 const TrackedObjectConstPtr& new_object) const {
92 // Check whether track is static or not
93 // evaluate speed noise level, the less the level is the
94 // greater the probability of noise is
95 double speed = new_object->output_velocity.head(2).norm();
96 bool velocity_noise_level_is_0 = speed < (claping_speed_threshold_ / 8);
97 bool velocity_noise_level_is_1 = speed < (claping_speed_threshold_ / 4);
98 bool velocity_noise_level_is_2 = speed < (claping_speed_threshold_ / 2);
99 bool velocity_noise_level_is_3 = speed < (claping_speed_threshold_ / 1);
100 // believe track is staic if velocity noise level is 0
101 // use loose threshold for object is not pedestrian
102 if (velocity_noise_level_is_1 &&
103 latest_object->type != base::ObjectType::PEDESTRIAN) {
104 velocity_noise_level_is_0 = true;
105 }
106 if (velocity_noise_level_is_0) {
107 return true;
108 }
109 // believe track is static if velocity noise level is
110 // 1 && angle change level is 0
111 // use loose threshold for object is not pedstrian
112 if (velocity_noise_level_is_2 &&
113 latest_object->type != base::ObjectType::PEDESTRIAN) {
114 velocity_noise_level_is_1 = true;
115 }
116 double reasonable_angle_change_maximum_0 = M_PI / 6;
117 bool velocity_angle_change_level_is_0 =
119 latest_object, new_object, reasonable_angle_change_maximum_0);
120 if (velocity_noise_level_is_1 && velocity_angle_change_level_is_0) {
121 return true;
122 }
123 // believe track is static if velocity noise level is
124 // 2 && angle change level is 1
125 // use loose threshold for object is not pedestrian
126 if (velocity_noise_level_is_3 &&
127 latest_object->type != base::ObjectType::PEDESTRIAN) {
128 velocity_noise_level_is_2 = true;
129 }
130 double reasonable_angle_change_maximum_1 = M_PI / 4;
131 bool velocity_angle_change_level_is_1 =
133 latest_object, new_object, reasonable_angle_change_maximum_1);
134 if (velocity_noise_level_is_2 && velocity_angle_change_level_is_1) {
135 return true;
136 }
137 return false;
138}
139
141 const TrackedObjectConstPtr& latest_object,
142 const TrackedObjectConstPtr& new_object,
143 double reasonable_angle_change_maximum) const {
144 // note reasonable_angle_change_maximum should be within [0, M_PI]
145 // believe angle change is obvious if one of estimation pair is
146 // extrodinary small
147 Eigen::Vector3d previous_velocity = latest_object->output_velocity;
148 Eigen::Vector3d current_velocity = new_object->output_velocity;
149 constexpr double kEpsilon = std::numeric_limits<double>::epsilon();
150 if (previous_velocity.norm() < kEpsilon) {
151 // return false; // without motion score, this should be true
152 return true;
153 }
154 if (current_velocity.norm() < kEpsilon) {
155 return true;
156 }
157 // believe angle change is obvious if it is greater than threshold
158
159 double velocity_angle_change =
160 algorithm::CalculateTheta2DXY(previous_velocity, current_velocity);
161 if (fabs(velocity_angle_change) > reasonable_angle_change_maximum) {
162 return true;
163 }
164 // Let track be static if angle change of current velocity
165 // & previous heading is larger
166 // than given reasonable maximum.
167 Eigen::Vector3d previous_direction = latest_object->output_direction;
168 double velocity_heading_angle_change_1 =
169 algorithm::CalculateTheta2DXY(previous_direction, current_velocity);
170 previous_direction *= -1;
171 double velocity_heading_angle_change_2 =
172 algorithm::CalculateTheta2DXY<double>(
173 previous_direction, current_velocity);
174 velocity_angle_change = std::min(fabs(velocity_heading_angle_change_1),
175 fabs(velocity_heading_angle_change_2));
176 if (fabs(velocity_angle_change) > reasonable_angle_change_maximum) {
177 return true;
178 }
179 return false;
180}
181
182} // namespace radar4d
183} // namespace perception
184} // namespace apollo
bool Refine(const MrfTrackDataConstPtr &track_data, TrackedObjectPtr new_object)
Refine velocity of new object
bool Init(const MrfMotionRefinerInitOptions &options=MrfMotionRefinerInitOptions())
Init motion refiner
bool CheckStaticHypothesisByState(const TrackedObjectConstPtr &latest_object, const TrackedObjectConstPtr &new_object) const
Check whether new observed object is static or not
bool CheckStaticHypothesisByVelocityAngleChange(const TrackedObjectConstPtr &latest_object, const TrackedObjectConstPtr &new_object, double reasonable_angle_change_maximum) const
Check whether new observed object is static or not via considering the angle velocity change
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
T CalculateTheta2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
Definition basic.h:92
std::shared_ptr< const TrackedObject > TrackedObjectConstPtr
std::shared_ptr< TrackedObject > TrackedObjectPtr
std::shared_ptr< const MrfTrackData > MrfTrackDataConstPtr
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37