31 std::string config_file =
"mlf_motion_refiner.conf";
49 auto latest_object_pair = track_data->GetLatestObject();
53 double time_diff = new_object->object_ptr->latest_tracked_time -
54 latest_object->object_ptr->latest_tracked_time;
55 Eigen::Vector3d filter_velocity_gain = new_object->belief_velocity_gain;
56 double filter_acceleration_gain = 0.0;
58 filter_acceleration_gain = 0.0;
60 filter_acceleration_gain = filter_velocity_gain.norm() / time_diff;
62 bool need_keep_motion =
67 need_keep_motion =
true;
70 if (need_keep_motion && (!new_object->converged)) {
71 Eigen::Vector3d current_velocity = Eigen::Vector3d::Zero();
72 current_velocity = latest_object->output_velocity;
73 new_object->output_velocity = current_velocity;
78 AINFO <<
"[Velocity-Refine] track_id: " << track_data->track_id_
79 <<
" KEEP MOTION because of extraodinary acceleration.";
84 bool need_assign_movable_obj_speed =
87 if (new_object->belief_velocity.head(2).norm() > 0) {
88 new_object->output_velocity = new_object->belief_velocity;
89 }
else if (new_object->measured_barycenter_velocity.head(2).norm() > 0) {
90 new_object->output_velocity = new_object->measured_barycenter_velocity;
92 new_object->output_velocity = new_object->measured_center_velocity;
98 bool is_static_hypothesis =
101 if (is_static_hypothesis) {
102 new_object->output_velocity = Eigen::Vector3d::Zero();
103 new_object->state.tail<2>().setZero();
104 AINFO <<
"[Velocity-Refine] track_id: " << track_data->track_id_
105 <<
" set velocity to zero because of static_hypothesis.";
117 double speed = new_object->output_velocity.head(2).norm();
120 bool velocity_noise_level_0 =
false;
121 bool velocity_noise_level_1 =
false;
122 bool velocity_noise_level_2 =
false;
123 auto type_select = new_object->type;
141 if (velocity_noise_level_0) {
142 ADEBUG <<
"type: " <<
static_cast<size_t>(type_select)
143 <<
" speed is " << speed <<
" so small";
147 double velocity_change_angle = M_PI, velocity_heading_angle = M_PI;
149 &velocity_change_angle, &velocity_heading_angle)) {
150 ADEBUG <<
" velocity_change_angle: " << velocity_change_angle
151 <<
" velocity_heading_angle: " << velocity_heading_angle;
156 bool dir_change_level_0 = (fabs(velocity_change_angle) > M_PI / 6 ||
157 fabs(velocity_heading_angle) > M_PI / 6);
158 if (velocity_noise_level_1 && dir_change_level_0) {
159 ADEBUG <<
"type: " <<
static_cast<size_t>(type_select) <<
" speed is "
160 << speed <<
" velocity_change is " << velocity_change_angle
161 <<
" velocity_heading is " << velocity_heading_angle
162 <<
" bigger than PI/6";
168 bool dir_change_level_1 = (fabs(velocity_change_angle) > M_PI / 4 ||
169 fabs(velocity_heading_angle) > M_PI / 4);
170 if (velocity_noise_level_2 && dir_change_level_1) {
171 ADEBUG <<
"type: " <<
static_cast<size_t>(type_select) <<
" speed is "
172 << speed <<
" velocity_change is " << velocity_change_angle
173 <<
" velocity_heading is " << velocity_heading_angle
174 <<
" bigger than PI/4";
183 double* vel_change_angle,
184 double* velocity_heading_angle)
const {
185 Eigen::Vector3d pre_velocity = latest_object->output_velocity;
186 Eigen::Vector3d cur_velocity = new_object->output_velocity;
187 Eigen::Vector3d pre_direction = latest_object->output_direction;
188 constexpr double kEpsilon = std::numeric_limits<double>::epsilon();
190 if (pre_velocity.norm() < kEpsilon || cur_velocity.norm() < kEpsilon) {
193 *vel_change_angle = algorithm::CalculateTheta2DXY<double>(
194 pre_velocity, cur_velocity);
196 double velocity_heading_angle_1 = algorithm::CalculateTheta2DXY<double>(
197 pre_direction, cur_velocity);
199 double velocity_heading_angle_2 = algorithm::CalculateTheta2DXY<double>(
200 pre_direction, cur_velocity);
201 *velocity_heading_angle = std::min(fabs(velocity_heading_angle_1),
202 fabs(velocity_heading_angle_2));
209 double reasonable_angle_change_maximum)
const {
213 Eigen::Vector3d previous_velocity = latest_object->output_velocity;
214 Eigen::Vector3d current_velocity = new_object->output_velocity;
215 constexpr double kEpsilon = std::numeric_limits<double>::epsilon();
216 if (previous_velocity.norm() < kEpsilon) {
220 if (current_velocity.norm() < kEpsilon) {
225 double velocity_angle_change =
227 if (fabs(velocity_angle_change) > reasonable_angle_change_maximum) {
233 Eigen::Vector3d previous_direction = latest_object->output_direction;
234 double velocity_heading_angle_change_1 =
236 previous_direction *= -1;
237 double velocity_heading_angle_change_2 =
238 algorithm::CalculateTheta2DXY<double>(
239 previous_direction, current_velocity);
240 velocity_angle_change = std::min(fabs(velocity_heading_angle_change_1),
241 fabs(velocity_heading_angle_change_2));
242 if (fabs(velocity_angle_change) > reasonable_angle_change_maximum) {
254 new_object->output_velocity.head(2).norm() < 1e-6) {
bool CheckStaticHypothesisByState(const TrackedObjectConstPtr &latest_object, const TrackedObjectConstPtr &new_object) const
Check whether new observed object is static or not
bool Init(const MlfMotionRefinerInitOptions &options=MlfMotionRefinerInitOptions())
Init motion refiner
bool Refine(const MlfTrackDataConstPtr &track_data, TrackedObjectPtr new_object)
Refine velocity of new object
double claping_speed_threshold_
bool NeedAssignMovableObjectSpeed(const TrackedObjectConstPtr &latest_object, const TrackedObjectConstPtr &new_object) const
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
double claping_acceleration_threshold_
bool CalculateVelocityAngleChange(const TrackedObjectConstPtr &latest_object, const TrackedObjectConstPtr &new_object, double *vel_change_angle, double *velocity_heading_angle) const
bool use_movable_state_check_
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,...
T CalculateTheta2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
std::shared_ptr< Object > ObjectPtr
std::shared_ptr< const MlfTrackData > MlfTrackDataConstPtr
std::shared_ptr< const TrackedObject > TrackedObjectConstPtr
std::shared_ptr< TrackedObject > TrackedObjectPtr
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
optional bool use_movable_state_check
optional double car_refine_speed
optional double claping_speed_threshold
optional double claping_acceleration_threshold
optional double cyc_refine_speed