| 322 | } |
| 323 | |
| 324 | double |
| 325 | Track::getMahalanobisDistance(double x, double y, const ros::Time& when) |
| 326 | { |
| 327 | int difference = int(round((when - last_time_predicted_).toSec() / period_)); |
| 328 | // std::cout << "time difference from last detection: " << difference << std::endl; |
| 329 | int index; |
| 330 | if(difference <= 0) |
| 331 | { |
| 332 | index = (MAX_SIZE + last_time_predicted_index_ + difference) % MAX_SIZE; |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | for(int i = 0; i < difference; i++) |
| 337 | { |
| 338 | tmp_filter_->predict(); |
| 339 | last_time_predicted_index_ = (last_time_predicted_index_ + 1) % MAX_SIZE; |
| 340 | if (velocity_in_motion_term_) |
| 341 | tmp_filter_->getMahalanobisParameters(mahalanobis_map4d_[last_time_predicted_index_]); |
| 342 | else |
| 343 | tmp_filter_->getMahalanobisParameters(mahalanobis_map2d_[last_time_predicted_index_]); |
| 344 | tmp_filter_->update(); |
| 345 | } |
| 346 | last_time_predicted_ = when; |
| 347 | index = last_time_predicted_index_; |
| 348 | } |
| 349 | |
| 350 | if (velocity_in_motion_term_) |
| 351 | { |
| 352 | ros::Duration d(1.0); |
| 353 | ros::Duration d2(2.0); |
| 354 | |
| 355 | double t = std::max(first_time_detected_.toSec(), (when - d).toSec()); |
| 356 | t = std::min(t, last_time_detected_.toSec()); |
| 357 | t = std::max(t, (last_time_predicted_ - d2).toSec()); |
| 358 | double dt = t - last_time_predicted_.toSec(); |
| 359 | |
| 360 | difference = int(round(dt / period_)); |
| 361 | int vIndex = (MAX_SIZE + last_time_predicted_index_ + difference) % MAX_SIZE; |
| 362 | |
| 363 | // std::cout << "dt: " << dt << std::endl; |
| 364 | // std::cout << "vIndex: " << vIndex << std::endl; |
| 365 | |
| 366 | double vx, vy; |
| 367 | if(difference != 0) |
| 368 | { |
| 369 | vx = - (x - mahalanobis_map4d_[vIndex].x) / dt; |
| 370 | vy = - (y - mahalanobis_map4d_[vIndex].y) / dt; |
| 371 | } |
| 372 | else |
| 373 | { |
| 374 | vx = mahalanobis_map4d_[vIndex].x; |
| 375 | vy = mahalanobis_map4d_[vIndex].y; |
| 376 | } |
| 377 | |
| 378 | // std::cout << "vx: " << vx << ", vy: " << vy<< std::endl; |
| 379 | |
| 380 | return open_ptrack::tracking::KalmanFilter::performMahalanobisDistance(x, y, vx, vy, mahalanobis_map4d_[index]); |
| 381 | } |
no test coverage detected