Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_clock() method #77

Open
wants to merge 3 commits into
base: humble
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions behaviortree_ros2/include/behaviortree_ros2/bt_action_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ class RosActionNode : public BT::ActionNodeBase
return rclcpp::Clock(RCL_ROS_TIME).now();
}

rclcpp::Clock::SharedPtr clock()
{
if(auto node = node_.lock())
{
return node->get_clock();
}
static auto clock = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME);
return clock;
}

using ClientsRegistry =
std::unordered_map<std::string, std::weak_ptr<ActionClientInstance>>;
// contains the fully-qualified name of the node and the name of the client
Expand Down
10 changes: 10 additions & 0 deletions behaviortree_ros2/include/behaviortree_ros2/bt_service_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ class RosServiceNode : public BT::ActionNodeBase
return rclcpp::Clock(RCL_ROS_TIME).now();
}

rclcpp::Clock::SharedPtr clock()
{
if(auto node = node_.lock())
{
return node->get_clock();
}
static auto clock = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME);
return clock;
}

using ClientsRegistry =
std::unordered_map<std::string, std::weak_ptr<ServiceClientInstance>>;
// contains the fully-qualified name of the node and the name of the client
Expand Down
6 changes: 6 additions & 0 deletions btcpp_ros2_samples/src/sleep_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ NodeStatus SleepAction::onFailure(ActionNodeErrorCode error)
return NodeStatus::FAILURE;
}

BT::NodeStatus SleepAction::onFeedback(const std::shared_ptr<const Feedback> feedback)
{
RCLCPP_INFO_THROTTLE(logger(), *clock(), 1000, "Feedback cycle %d", feedback->cycle);
return NodeStatus::RUNNING;
}

void SleepAction::onHalt()
{
RCLCPP_INFO(logger(), "%s: onHalt", name().c_str());
Expand Down
2 changes: 2 additions & 0 deletions btcpp_ros2_samples/src/sleep_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ class SleepAction : public RosActionNode<btcpp_ros2_interfaces::action::Sleep>
BT::NodeStatus onResultReceived(const WrappedResult& wr) override;

virtual BT::NodeStatus onFailure(ActionNodeErrorCode error) override;

virtual BT::NodeStatus onFeedback(const std::shared_ptr<const Feedback> feedback) override;
};