|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <behaviortree_cpp/action_node.h> |
| 4 | + |
| 5 | +// This header includes the SharedResourcesNode type |
| 6 | +#include <moveit_studio_behavior_interface/shared_resources_node.hpp> |
| 7 | + |
| 8 | +#include <moveit_msgs/msg/move_it_error_codes.hpp> |
| 9 | + |
| 10 | +#include <moveit_studio_behavior_interface/check_for_error.hpp> |
| 11 | + |
| 12 | +namespace example_behaviors |
| 13 | +{ |
| 14 | +/** |
| 15 | + * @brief DelayedMessage will use FailureLoggerROS to log a "Hello World" message after the duration specified on the input port |
| 16 | + */ |
| 17 | +class DelayedMessage : public moveit_studio::behaviors::SharedResourcesNode<BT::StatefulActionNode> |
| 18 | +{ |
| 19 | +private: |
| 20 | + std::chrono::time_point<std::chrono::steady_clock> start_time_; |
| 21 | + double delay_duration_; |
| 22 | + |
| 23 | +public: |
| 24 | + /** |
| 25 | + * @brief Constructor for the delayed_message behavior. |
| 26 | + * @param name The name of a particular instance of this Behavior. This will be set by the behavior tree factory when |
| 27 | + * this Behavior is created within a new behavior tree. |
| 28 | + * @param shared_resources A shared_ptr to a BehaviorContext that is shared among all SharedResourcesNode Behaviors in |
| 29 | + * the behavior tree. This BehaviorContext is owned by the Studio Agent's ObjectiveServerNode. |
| 30 | + * @param config This contains runtime configuration info for this Behavior, such as the mapping between the |
| 31 | + * Behavior's data ports on the behavior tree's blackboard. This will be set by the behavior tree factory when this |
| 32 | + * Behavior is created within a new behavior tree. |
| 33 | + * @details An important limitation is that the members of the base Behavior class are not instantiated until after |
| 34 | + * the initialize() function is called, so these classes should not be used within the constructor. |
| 35 | + */ |
| 36 | + DelayedMessage(const std::string& name, const BT::NodeConfiguration& config, |
| 37 | + const std::shared_ptr<moveit_studio::behaviors::BehaviorContext>& shared_resources); |
| 38 | + |
| 39 | + /** |
| 40 | + * @brief Implementation of the required providedPorts() function for the delayed_message Behavior. |
| 41 | + * @details The BehaviorTree.CPP library requires that Behaviors must implement a static function named |
| 42 | + * providedPorts() which defines their input and output ports. If the Behavior does not use any ports, this function |
| 43 | + * must return an empty BT::PortsList. This function returns a list of ports with their names and port info, which is |
| 44 | + * used internally by the behavior tree. |
| 45 | + * @return If delayed_message does not expose any ports, this function returns an empty list. |
| 46 | + */ |
| 47 | + static BT::PortsList providedPorts(); |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief Implementation of the metadata() function for displaying metadata, such as Behavior description and |
| 51 | + * subcategory, in the MoveIt Studio Developer Tool. |
| 52 | + * @return A BT::KeyValueVector containing the Behavior metadata. |
| 53 | + */ |
| 54 | + static BT::KeyValueVector metadata(); |
| 55 | + |
| 56 | + /** |
| 57 | + * @brief Implementation of onStart(). Runs when the Behavior is ticked for the first time. |
| 58 | + * @return Always returns BT::NodeStatus::RUNNING, since the success of Behavior's initialization is checked in @ref |
| 59 | + * onRunning(). |
| 60 | + */ |
| 61 | + BT::NodeStatus onStart() override; |
| 62 | + |
| 63 | + /** |
| 64 | + * @brief Implementation of onRunning(). Checks the status of the Behavior when it is ticked after it starts running. |
| 65 | + * @return BT::NodeStatus::RUNNING, BT::NodeStatus::SUCCESS, or BT::NodeStatus::FAILURE depending on the Behavior status. |
| 66 | + */ |
| 67 | + BT::NodeStatus onRunning() override; |
| 68 | + |
| 69 | + void onHalted() override; |
| 70 | +}; |
| 71 | +} // namespace example_behaviors |
0 commit comments