ros2 / message_filters

BSD 3-Clause "New" or "Revised" License
76 stars 66 forks source link

Fix latest time policy when cont. pivot switching due to decreasing rates #147

Open nicolaloi opened 2 months ago

nicolaloi commented 2 months ago

Trying to fix #131.

In the LatestTime policy, if the current pivot and other topics are decreasing in rate such that the pivot alternates between these topics, the policy might indefinitely stop publishing.

The rationale of this PR is to implement a special check when a message is received from the current pivot topic causing it to decrease its rate and to lose the pivot status (because now another topic has the highest rate). When this happens, it is checked if the now outdated pivot activated a publication when it received its previous message while it was still the pivot. If not, this could indicate that the skipped publication was caused by the pivot-switching behavior, so we force the publication at the current step.

Using the test script shared in https://github.com/ros2/message_filters/issues/131#issuecomment-2200457575, the PR branch obtains:

----- stable -----

sub1 1725490793.748611450
sub2 1725490793.758611441
sub1 1725490793.768611431
published at 1725490793.768900871
        msg1 1725490793.768611431
        msg2 1725490793.758611441
sub2 1725490793.778611422
published at 1725490793.778852701
        msg1 1725490793.768611431
        msg2 1725490793.778611422
sub1 1725490793.788611412
published at 1725490793.788865089
        msg1 1725490793.788611412
        msg2 1725490793.778611422
sub2 1725490793.798611403
published at 1725490793.798822641
        msg1 1725490793.788611412
        msg2 1725490793.798611403
sub1 1725490793.808611393
sub2 1725490793.818611383
sub1 1725490793.828611374
sub2 1725490793.838611364
sub1 1725490793.848611355
published at 1725490793.848868847
        msg1 1725490793.848611355
        msg2 1725490793.838611364

...

----- decreasing -----

sub1 1725490794.748611450
sub2 1725490794.758611441
sub1 1725490794.768878222
sub2 1725490794.779144764
sub1 1725490794.789678097
published at 1725490794.789924860
        msg1 1725490794.789678097
        msg2 1725490794.779144764
sub2 1725490794.800211668
sub1 1725490794.811011791
sub2 1725490794.821811914
sub1 1725490794.832878590
sub2 1725490794.843945503
published at 1725490794.844178200
        msg1 1725490794.832878590
        msg2 1725490794.843945503
sub1 1725490794.855278969
sub2 1725490794.866612434
sub1 1725490794.878212690
sub2 1725490794.889812708
sub1 1725490794.901679754
published at 1725490794.901928186
        msg1 1725490794.901679754
        msg2 1725490794.889812708
...

instead using the current rolling branch (no publications when rates are decreasing):

----- stable -----

sub1 1725490618.965097666
sub2 1725490618.975097656
sub1 1725490618.985097647
published at 1725490618.985387325
        msg1 1725490618.985097647
        msg2 1725490618.975097656
sub2 1725490618.995097637
published at 1725490618.995360851
        msg1 1725490618.985097647
        msg2 1725490618.995097637
sub1 1725490619.005097628
sub2 1725490619.015097618
published at 1725490619.015326262
        msg1 1725490619.005097628
        msg2 1725490619.015097618
sub1 1725490619.025097609
published at 1725490619.025310040
        msg1 1725490619.025097609
        msg2 1725490619.015097618
sub2 1725490619.035097599
sub1 1725490619.045097589
sub2 1725490619.055097580
sub1 1725490619.065097570
published at 1725490619.065652370
        msg1 1725490619.065097570
        msg2 1725490619.055097580

...

----- decreasing -----

sub1 1725490619.965097666
published at 1725490619.965355873
        msg1 1725490619.965097666
        msg2 1725490619.955097675
sub2 1725490619.975097656
sub1 1725490619.985364199
sub2 1725490619.995630980
sub1 1725490620.006164312
sub2 1725490620.016697884
sub1 1725490620.027498007
sub2 1725490620.038297892
sub1 1725490620.049364805
sub2 1725490620.060431719
sub1 1725490620.071765184
sub2 1725490620.083098650
sub1 1725490620.094698906

...

@wjwwood @fujitatomoya @ahcorde this is a draft fix, looking forward to your suggestions and ideas, as you can point out possible shortcomings with this solution.