Skip to content

Commit 3b708d2

Browse files
authored
Merge pull request tier4#1612 from tier4/refactor/behavior_tree_5
Refactor ActionNode to isolate side effects via pure virtual methods
2 parents e9151b2 + 72ff550 commit 3b708d2

26 files changed

+181
-113
lines changed

simulation/behavior_tree_plugin/include/behavior_tree_plugin/action_node.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class ActionNode : public BT::ActionNodeBase
118118
lanelet::Ids route_lanelets_;
119119
traffic_simulator_msgs::msg::BehaviorParameter behavior_parameter_;
120120

121+
virtual bool checkPreconditions() { return true; }
122+
virtual BT::NodeStatus doAction() = 0;
121123
auto getDistanceToTargetEntity(
122124
const math::geometry::CatmullRomSplineInterface & spline,
123125
const traffic_simulator::CanonicalizedEntityStatus & status) const -> std::optional<double>;
@@ -137,6 +139,7 @@ class ActionNode : public BT::ActionNodeBase
137139
-> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
138140
auto isOtherEntityAtConsideredAltitude(
139141
const traffic_simulator::CanonicalizedEntityStatus & entity_status) const -> bool;
142+
auto tick() -> BT::NodeStatus override;
140143

141144
std::shared_ptr<EuclideanDistancesMap> euclidean_distances_map_;
142145
};

simulation/behavior_tree_plugin/include/behavior_tree_plugin/pedestrian/follow_lane_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class FollowLaneAction : public entity_behavior::PedestrianActionNode
3939
{
4040
public:
4141
FollowLaneAction(const std::string & name, const BT::NodeConfiguration & config);
42-
BT::NodeStatus tick() override;
42+
bool checkPreconditions() override;
43+
BT::NodeStatus doAction() override;
4344
void getBlackBoardValues() override;
4445
static BT::PortsList providedPorts()
4546
{

simulation/behavior_tree_plugin/include/behavior_tree_plugin/pedestrian/follow_trajectory_sequence/follow_polyline_trajectory_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ struct FollowPolylineTrajectoryAction : public PedestrianActionNode
3434

3535
static auto providedPorts() -> BT::PortsList;
3636

37-
auto tick() -> BT::NodeStatus override;
37+
bool checkPreconditions() override;
38+
BT::NodeStatus doAction() override;
3839
};
3940
} // namespace pedestrian
4041
} // namespace entity_behavior

simulation/behavior_tree_plugin/include/behavior_tree_plugin/pedestrian/walk_straight_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class WalkStraightAction : public entity_behavior::PedestrianActionNode
4444
{
4545
public:
4646
WalkStraightAction(const std::string & name, const BT::NodeConfiguration & config);
47-
BT::NodeStatus tick() override;
47+
bool checkPreconditions() override;
48+
BT::NodeStatus doAction() override;
4849
void getBlackBoardValues() override;
4950
static BT::PortsList providedPorts()
5051
{

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/follow_front_entity_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class FollowFrontEntityAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
FollowFrontEntityAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
static BT::PortsList providedPorts()
3637
{
3738
return entity_behavior::VehicleActionNode::providedPorts();

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/follow_lane_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class FollowLaneAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
FollowLaneAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
void getBlackBoardValues() override;
3637
static BT::PortsList providedPorts()
3738
{

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/move_backward_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class MoveBackwardAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
MoveBackwardAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
void getBlackBoardValues() override;
3637
static BT::PortsList providedPorts()
3738
{

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/stop_at_crossing_entity_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class StopAtCrossingEntityAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
StopAtCrossingEntityAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
static BT::PortsList providedPorts()
3637
{
3738
return entity_behavior::VehicleActionNode::providedPorts();

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/stop_at_stop_line_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class StopAtStopLineAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
StopAtStopLineAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
static BT::PortsList providedPorts()
3637
{
3738
return entity_behavior::VehicleActionNode::providedPorts();

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/stop_at_traffic_light_action.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class StopAtTrafficLightAction : public entity_behavior::VehicleActionNode
3131
{
3232
public:
3333
StopAtTrafficLightAction(const std::string & name, const BT::NodeConfiguration & config);
34-
BT::NodeStatus tick() override;
34+
bool checkPreconditions() override;
35+
BT::NodeStatus doAction() override;
3536
static BT::PortsList providedPorts()
3637
{
3738
return entity_behavior::VehicleActionNode::providedPorts();

0 commit comments

Comments
 (0)