ros2 / message_filters

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

Fix TypeError: unhashable type: 'Time' error #33

Closed jdddog closed 5 years ago

jdddog commented 5 years ago

Fixes #34

In the TimeSynchronizer class the following error is thrown because msg.header.stamp (builtin_interfaces/Time) is not hashable (perhaps it was in ROS 1), see below:

  File "/home/jamie/my_ros2_ws/install/message_filters/lib/python3.6/site-packages/message_filters/__init__.py", line 227, in add
    my_queue[msg.header.stamp] = msg
TypeError: unhashable type: 'Time'

This occurs at messagefilters/__init_\.py#L227.

I've just taken the approach used in ApproximateTimeSynchronizer to hash the timestamp, creating a rclpy Time object and using the nanoseconds field as the hash:

stamp = Time.from_msg(msg.header.stamp)
my_queue[stamp.nanoseconds] = msg

There is also a lot of code that was added to ApproximateTimeSynchronizer but not to TimeSynchronizer, perhaps these checks should be in TimeSynchronizer too, in case someone doesn't set a header?

        if not hasattr(msg, 'header') or not hasattr(msg.header, 'stamp'):
            if not self.allow_headerless:
                msg_filters_logger = rclpy.logging.get_logger('message_filters_approx')
                msg_filters_logger.set_level(LoggingSeverity.INFO)
                msg_filters_logger.warn("can not use message filters for "
                              "messages without timestamp infomation when "
                              "'allow_headerless' is disabled. auto assign "
                              "ROSTIME to headerless messages once enabling "
                              "constructor option of 'allow_headerless'.")
                return

            stamp = ROSClock().now()
sloretz commented 5 years ago

CI (testing just message_filters)

sloretz commented 5 years ago

@jdddog It looks like there's a test failure in the time synchronizer test that might be related to this PR. Would you mind fixing it? https://ci.ros2.org/job/ci_linux/8279/testReport/junit/message_filters.test.directed/TestDirected/test_synchronizer/

jdddog commented 5 years ago

@jdddog It looks like there's a test failure in the time synchronizer test that might be related to this PR. Would you mind fixing it? https://ci.ros2.org/job/ci_linux/8279/testReport/junit/message_filters.test.directed/TestDirected/test_synchronizer/

Hey @sloretz, no worries and thanks for the feedback. Yeah sure, I can take a look on the weekend.

wjwwood commented 5 years ago

@jdddog can you have another look?

dirk-thomas commented 5 years ago

The failing tests are due to the fact that the called API Time.from_msg is currently broken. See ros2/rclpy#453 for the proposed fix.

sloretz commented 5 years ago

CI (testing just message_filters)

sloretz commented 5 years ago

CI (testing just message_filters)

sloretz commented 5 years ago

Thanks for the PR @jdddog !

jdddog commented 5 years ago

Thanks for the PR @jdddog !

@sloretz No worries. Apologies for not looking at how to fix the breaking test.