MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / getMahalanobisDistance

Method getMahalanobisDistance

tracking/src/track_object.cpp:320–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

predictMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected