16.4.5
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
- tier4/sim_evaluation_tools#526
- https://tier4.atlassian.net/jira/software/c/projects/RT4/boards/446?assignee=712020%3A86ceb94c-d91a-412a-8dcf-056519a0fbf8&selectedIssue=RT4-16990
Destructive Changes
N/A
Known Limitations
N/A