pyc5714 / hdl-localization-ROS2

28 stars 8 forks source link

Program failed to compare rclcpp::Time instances with different time types #4

Open XCYRKDSDA opened 7 months ago

XCYRKDSDA commented 7 months ago

I launched the node HdlLocalizationNodelet with robot odometry prediction enabled. It died and reported:

terminate called after throwing an instance of 'std::runtime_error'
   what():  can't compare times with different time sources

After some debugging, I found that this error was directly come from line 261 of the file _hdl_localization_nodelet.cpp_:

https://github.com/pyc5714/hdl-localization-ROS2/blob/35de917029371c4de93fc8107ad25a09cca7b238/hdl_localization/apps/hdl_localization_nodelet.cpp#L260-L261

I found that the member PoseEstimator::last_correction_stamp is not explicitly initialized in the constructor of PoseEstimator, and the default constructor of rclcpp::Time will sets its type to RCL_SYSTEM_TIME. Therefore, when the program first comes to line 261, the last_correction_time is of type RCL_SYSTEM_TIME while the right side of the comparison is of type RCL_ROS_TIME, leading to the error.

I think PoseEstimator::last_correction_stamp might need an initialization similar to that of PoseEstimator::prev_stamp, for example:

last_correction_stamp = rclcpp::Time((int64_t)0, init_stamp.get_clock_type());

The program did work after adding this line in the constructor.