Beispiel #1
0
typename rclcpp::timer::WallTimer<CallbackType>::SharedPtr
Node::create_wall_timer(
  std::chrono::nanoseconds period,
  CallbackType callback,
  rclcpp::callback_group::CallbackGroup::SharedPtr group)
{
  auto timer = rclcpp::timer::WallTimer<CallbackType>::make_shared(
    period, std::move(callback));
  if (group) {
    if (!group_in_node(group)) {
      // TODO(jacquelinekay): use custom exception
      throw std::runtime_error("Cannot create timer, group not in node.");
    }
    group->add_timer(timer);
  } else {
    default_callback_group_->add_timer(timer);
  }
  number_of_timers_++;
  if (rcl_trigger_guard_condition(&notify_guard_condition_) != RCL_RET_OK) {
    throw std::runtime_error(
            std::string(
              "Failed to notify waitset on timer creation: ") + rmw_get_error_string());
  }
  return timer;
}
Beispiel #2
0
typename rclcpp::timer::WallTimer<CallbackType>::SharedPtr
Node::create_wall_timer(
  std::chrono::nanoseconds period,
  CallbackType callback,
  rclcpp::callback_group::CallbackGroup::SharedPtr group)
{
  auto timer = rclcpp::timer::WallTimer<CallbackType>::make_shared(
    period, std::move(callback));
  if (group) {
    if (!group_in_node(group)) {
      // TODO(jacquelinekay): use custom exception
      throw std::runtime_error("Cannot create timer, group not in node.");
    }
    group->add_timer(timer);
  } else {
    default_callback_group_->add_timer(timer);
  }
  number_of_timers_++;
  return timer;
}
Beispiel #3
0
void
NodeTimers::add_timer(
  rclcpp::timer::TimerBase::SharedPtr timer,
  rclcpp::callback_group::CallbackGroup::SharedPtr callback_group)
{
  if (callback_group) {
    if (!node_base_->callback_group_in_node(callback_group)) {
      // TODO(jacquelinekay): use custom exception
      throw std::runtime_error("Cannot create timer, group not in node.");
    }
    callback_group->add_timer(timer);
  } else {
    node_base_->get_default_callback_group()->add_timer(timer);
  }
  if (rcl_trigger_guard_condition(node_base_->get_notify_guard_condition()) != RCL_RET_OK) {
    throw std::runtime_error(
            std::string(
              "Failed to notify waitset on timer creation: ") + rmw_get_error_string());
  }
}