BehaviorTree/include/behaviortree_cpp/controls/sequence_node.h

54 lines
2.1 KiB
C++

/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "behaviortree_cpp/control_node.h"
namespace BT
{
/**
* @brief The SequenceNode is used to tick children in an ordered sequence.
* If any child returns RUNNING, previous children will NOT be ticked again.
*
* - If all the children return SUCCESS, this node returns SUCCESS.
*
* - If a child returns RUNNING, this node returns RUNNING.
* Loop is NOT restarted, the same running child will be ticked again.
*
* - If a child returns FAILURE, stop the loop and return FAILURE.
* Restart the loop only if (reset_on_failure == true)
*
*/
class SequenceNode : public ControlNode
{
public:
SequenceNode(const std::string& name, bool make_async = false);
virtual ~SequenceNode() override = default;
virtual void halt() override;
protected:
size_t current_child_idx_;
private:
size_t skipped_count_ = 0;
bool asynch_ = false;
virtual BT::NodeStatus tick() override;
};
} // namespace BT