Skip to content

16.4.5

Choose a tag to compare

@github-actions github-actions released this 30 May 08:23

Abstract

This pull request is a refactoring of the BehaviorTreePlugin proposed by ROBOTECH.

Background

N/A

Details

Extract common pre-/post-processing into the base ActionNode and introduce a pure virtual doAction() method.
Delegate all action-specific side effects (state updates, outputs) to derived classes for improved traceability and testability.

// Base class (defines pure virtual function)
class ActionNode : public BT::ActionNodeBase {
public:
  ActionNode(const std::string &name, const BT::NodeConfiguration &config)
  : BT::ActionNodeBase(name, config) {}

  BT::NodeStatus tick() override {
    // ① Common: Retrieve values from the blackboard
    getBlackBoardValues();
    // ② Common: Perform precondition checks
    if (!checkPreconditions()) {
      return BT::NodeStatus::FAILURE;
    }
    // ③ Delegate logic to derived class (pure virtual)
    return doAction();
  }

protected:
  virtual void getBlackBoardValues() {
    // Common blackboard reading logic
  }
  virtual bool checkPreconditions() { return true; }

  // Must be implemented by derived classes
  virtual BT::NodeStatus doAction() = 0;
};

// Example of a derived class
class ExampleAction : public ActionNode {
public:

protected:
  void getBlackBoardValues() override {
    ActionNode::getBlackBoardValues();
    // Retrieve additional vehicle-specific parameters
  }

  BT::NodeStatus doAction() override {
    // Consolidate logic such as calculateUpdatedEntityStatus,
    // setOutput(), and other side effects here
    return BT::NodeStatus::SUCCESS;  // or RUNNING/FAILURE
  }
};

References

Destructive Changes

N/A

Known Limitations

N/A

Related Issues