|
| 1 | +#include "experimental_behaviors/get_pose_stamped_from_topic.hpp" |
| 2 | + |
| 3 | +#include <moveit_studio_behavior_interface/get_required_ports.hpp> |
| 4 | +#include <moveit_studio_behavior_interface/impl/get_message_from_topic_impl.hpp> |
| 5 | + |
| 6 | +namespace experimental_behaviors |
| 7 | +{ |
| 8 | + |
| 9 | +namespace |
| 10 | +{ |
| 11 | +constexpr auto kPortIDTimeoutDuration = "timeout_sec"; |
| 12 | +} // namespace |
| 13 | + |
| 14 | +GetPoseStampedFromTopic::GetPoseStampedFromTopic( |
| 15 | + const std::string& name, const BT::NodeConfiguration& config, |
| 16 | + const std::shared_ptr<moveit_studio::behaviors::BehaviorContext>& shared_resources) |
| 17 | + : moveit_studio::behaviors::GetMessageFromTopicBehaviorBase<geometry_msgs::msg::PoseStamped>(name, config, |
| 18 | + shared_resources) |
| 19 | +{ |
| 20 | +} |
| 21 | + |
| 22 | +BT::PortsList GetPoseStampedFromTopic::providedPorts() |
| 23 | +{ |
| 24 | + return BT::PortsList({ |
| 25 | + BT::InputPort<std::string>(kPortIDTopicName, "", "PoseStamped topic name."), |
| 26 | + BT::InputPort<double>(kPortIDTimeoutDuration, -1.0, |
| 27 | + "Maximum duration in seconds to wait for pose message to be published before " |
| 28 | + "failing. Set to -1.0 to wait indefinitely."), |
| 29 | + BT::OutputPort<geometry_msgs::msg::PoseStamped>(kPortIDMessageOut, "PoseStamped message."), |
| 30 | + }); |
| 31 | +} |
| 32 | + |
| 33 | +tl::expected<std::chrono::duration<double>, std::string> GetPoseStampedFromTopic::getWaitForMessageTimeout() |
| 34 | +{ |
| 35 | + const auto port = moveit_studio::behaviors::getRequiredInputs(getInput<double>(kPortIDTimeoutDuration)); |
| 36 | + |
| 37 | + // Check that input data ports were set. |
| 38 | + if (!port.has_value()) |
| 39 | + { |
| 40 | + return tl::make_unexpected("Failed to get required value from input data port: " + port.error()); |
| 41 | + } |
| 42 | + const auto& [timeout] = port.value(); |
| 43 | + if (timeout == 0.0) |
| 44 | + { |
| 45 | + return tl::make_unexpected("Timeout value is 0.0s."); |
| 46 | + } |
| 47 | + return std::chrono::duration<double>{ timeout }; |
| 48 | +} |
| 49 | +} // namespace experimental_behaviors |
| 50 | + |
| 51 | +template class moveit_studio::behaviors::GetMessageFromTopicBehaviorBase<geometry_msgs::msg::PoseStamped>; |
0 commit comments