Skip to content

rcl_jump_threshold does not disable forward jump #947

@Kettenhoax

Description

@Kettenhoax

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • rolling binaries
  • Version or commit hash:
    • ros-rolling-rcl 4.0.0-1focal.20210921.175344
  • DDS implementation:
    • CycloneDDS
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

Define a clock jump handler for your node, and set the forward threshold to 0, which according to rcl/time.h should disable forward jumps.

#include <functional>
#include "rclcpp/rclcpp.hpp"

class TestNode : public rclcpp::Node
{
private:
  rclcpp::JumpHandler::SharedPtr jump_handler_;

public:
  TestNode() : Node("test")
  {
    rcl_jump_threshold_t jump_threshold;
    jump_threshold.on_clock_change = true;
    jump_threshold.min_forward.nanoseconds = 0;
    jump_threshold.min_backward.nanoseconds = -1;
    jump_handler_ =
      get_clock()->create_jump_callback(
      nullptr,
      std::bind(&TestNode::onJump, this, std::placeholders::_1), jump_threshold);
  }

private:
  void onJump(const rcl_time_jump_t & jump)
  {
    RCLCPP_INFO(this->get_logger(), "Jump of '%li'", jump.delta.nanoseconds);
  }
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<TestNode>());
  rclcpp::shutdown();
  return 0;
}

Compile and run with sim time

./jump --ros-args -p use_sim_time:=true

Simultaneously publish /clock messages:

import rclpy
from rclpy.qos import qos_profile_sensor_data
from rclpy.node import Node
from rosgraph_msgs.msg import Clock

class PublishClock(Node):
    def __init__(self):
        super().__init__('publish_clock')
        self._pub = self.create_publisher(Clock, 'clock', qos_profile_sensor_data)
        self._timer = self.create_timer(1.0, self._on_timer)

    def _on_timer(self):
        msg = Clock()
        msg.clock = self.get_clock().now().to_msg()
        self._pub.publish(msg)

rclpy.init()
rclpy.spin(PublishClock())

Expected behavior

The callback is never called and there's no output.

Actual behavior

Output is written at every received /clock message.

Additional Information

Works as expected without sim time

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions