@@ -16,7 +16,7 @@ use coordinate_systems::{Ground, Pixel};
1616use framework:: { AdditionalOutput , HistoricInput , MainOutput , PerceptionInput } ;
1717use geometry:: circle:: Circle ;
1818use linear_algebra:: { IntoFramed , Isometry2 } ;
19- use projection:: { Projection , camera_matrix:: CameraMatrix } ;
19+ use projection:: { camera_matrix:: CameraMatrix , Projection } ;
2020use types:: {
2121 ball_detection:: BallPercept ,
2222 ball_position:: { BallPosition , HypotheticalBallPosition } ,
@@ -319,7 +319,7 @@ fn mahalanobis_matrix_of_hypotheses_and_percepts(
319319 let ball = hypothesis. position ( ) ;
320320
321321 let residual = percept. percept_in_ground . mean - ball. position . inner . coords ;
322- let covariance = hypothesis. position_covariance ( ) ;
322+ let covariance = hypothesis. position_covariance ( ) + percept . percept_in_ground . covariance ;
323323
324324 let mahalanobis_distance = residual. dot (
325325 & covariance
@@ -502,4 +502,31 @@ mod tests {
502502 assert_eq ! ( assignment. len( ) , 2 ) ;
503503 assert_eq ! ( assignment. into_iter( ) . flatten( ) . count( ) , 2 ) ;
504504 }
505+
506+ #[ test]
507+ fn matching_cost_accounts_for_percept_covariance ( ) {
508+ let hypothesis = BallHypothesis {
509+ mode : BallMode :: Moving ( MultivariateNormalDistribution {
510+ mean : nalgebra:: vector![ 0.0 , 0.0 , 0.0 , 0.0 ] ,
511+ covariance : Matrix4 :: from_diagonal ( & nalgebra:: vector![ 0.01 , 0.01 , 1.0 , 1.0 ] ) ,
512+ } ) ,
513+ last_seen : Time :: zero ( ) ,
514+ validity : 1.0 ,
515+ } ;
516+ let percept = BallPercept {
517+ percept_in_ground : MultivariateNormalDistribution {
518+ mean : vector ! [ 1.0 , 0.0 ] ,
519+ covariance : Matrix2 :: identity ( ) * 100.0 ,
520+ } ,
521+ image_location : Circle :: new ( point ! [ 0.0 , 0.0 ] , 1.0 ) ,
522+ } ;
523+
524+ let costs = mahalanobis_matrix_of_hypotheses_and_percepts ( & [ hypothesis] , & [ percept] ) ;
525+ let cost = costs[ ( 0 , 0 ) ] . into_inner ( ) ;
526+
527+ assert ! (
528+ cost > -1.0 ,
529+ "uncertain percept should not be treated as a precise outlier, got cost {cost}"
530+ ) ;
531+ }
505532}
0 commit comments