Skip to content

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

@XCYRKDSDA

Description

@XCYRKDSDA

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:

rclcpp::Time last_correction_time = pose_estimator->last_correction_time();
if (enable_robot_odometry_prediction && last_correction_time != rclcpp::Time((int64_t)0, get_clock()->get_clock_type())) {

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions