scenario_simulator_v2 C++ API
action_node.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BEHAVIOR_TREE_PLUGIN__ACTION_NODE_HPP_
16 #define BEHAVIOR_TREE_PLUGIN__ACTION_NODE_HPP_
17 
18 #include <behaviortree_cpp_v3/action_node.h>
19 
20 #include <algorithm>
22 #include <memory>
23 #include <optional>
24 #include <string>
33 #include <traffic_simulator_msgs/msg/obstacle.hpp>
34 #include <traffic_simulator_msgs/msg/waypoints_array.hpp>
35 #include <unordered_map>
36 #include <vector>
37 
38 namespace entity_behavior
39 {
40 BT::PortsList operator+(const BT::PortsList & ports_0, const BT::PortsList & ports_1);
41 
42 class ActionNode : public BT::ActionNodeBase
43 {
44 public:
45  ActionNode(const std::string & name, const BT::NodeConfiguration & config);
46  ~ActionNode() override = default;
47  auto foundConflictingEntity(const lanelet::Ids & following_lanelets) const -> bool;
49  const lanelet::Ids & route_lanelets,
50  const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;
52  -> std::optional<std::string>;
53  auto calculateStopDistance(const traffic_simulator_msgs::msg::DynamicConstraints &) const
54  -> double;
56  -> std::optional<double>;
58  const lanelet::Ids & route_lanelets,
59  const std::vector<geometry_msgs::msg::Point> & waypoints) const -> std::optional<double>;
61  const lanelet::Ids & route_lanelets,
62  const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;
63  auto getRightOfWayEntities() const -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
64  auto getRightOfWayEntities(const lanelet::Ids & following_lanelets) const
65  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
66  auto getYieldStopDistance(const lanelet::Ids & following_lanelets) const -> std::optional<double>;
67  auto getOtherEntityStatus(lanelet::Id lanelet_id) const
68  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
69  auto stopEntity() const -> void;
70  auto getHorizon() const -> double;
71 
73  auto executeTick() -> BT::NodeStatus override;
74 
75  void halt() override final { setStatus(BT::NodeStatus::IDLE); }
76 
77  static BT::PortsList providedPorts()
78  {
79  return {
80  // clang-format off
81  BT::InputPort<double>("current_time"),
82  BT::InputPort<double>("matching_distance_for_lanelet_pose_calculation"),
83  BT::InputPort<double>("step_time"),
84  BT::InputPort<EntityStatusDict>("other_entity_status"),
85  BT::InputPort<lanelet::Ids>("route_lanelets"),
86  BT::InputPort<std::optional<double>>("target_speed"),
87  BT::InputPort<std::shared_ptr<hdmap_utils::HdMapUtils>>("hdmap_utils"),
88  BT::InputPort<std::shared_ptr<traffic_simulator::CanonicalizedEntityStatus>>("canonicalized_entity_status"),
89  BT::InputPort<std::shared_ptr<traffic_simulator::TrafficLightsBase>>("traffic_lights"),
90  BT::InputPort<traffic_simulator::behavior::Request>("request"),
91  BT::OutputPort<std::optional<traffic_simulator_msgs::msg::Obstacle>>("obstacle"),
92  BT::OutputPort<traffic_simulator_msgs::msg::WaypointsArray>("waypoints"),
93  BT::OutputPort<traffic_simulator::behavior::Request>("request"),
94  // clang-format on
95  };
96  }
97 
98  virtual auto getBlackBoardValues() -> void;
99  auto getEntityStatus(const std::string & target_name) const
102  const math::geometry::CatmullRomSplineInterface & spline, const std::string target_name,
103  double width_extension_right = 0.0, double width_extension_left = 0.0,
104  double length_extension_front = 0.0, double length_extension_rear = 0.0) const
105  -> std::optional<double>;
106 
107  auto setCanonicalizedEntityStatus(const traffic_simulator::EntityStatus & entity_status) -> void;
109  double target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const
112  double target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const
114 
115 protected:
117  std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils;
118  std::shared_ptr<traffic_simulator::TrafficLightsBase> traffic_lights;
119  std::shared_ptr<traffic_simulator::CanonicalizedEntityStatus> canonicalized_entity_status;
120  double current_time;
121  double step_time;
123  std::optional<double> target_speed;
125  lanelet::Ids route_lanelets;
126 
127 private:
128  auto getDistanceToTargetEntityOnCrosswalk(
129  const math::geometry::CatmullRomSplineInterface & spline,
130  const traffic_simulator::CanonicalizedEntityStatus & status) const -> std::optional<double>;
132  const math::geometry::CatmullRomSplineInterface & spline,
133  const traffic_simulator::CanonicalizedEntityStatus & status, double width_extension_right = 0.0,
134  double width_extension_left = 0.0, double length_extension_front = 0.0,
135  double length_extension_rear = 0.0) const -> std::optional<double>;
136  auto getConflictingEntityStatus(const lanelet::Ids & following_lanelets) const
137  -> std::optional<traffic_simulator::CanonicalizedEntityStatus>;
138  auto getConflictingEntityStatusOnCrossWalk(const lanelet::Ids & route_lanelets) const
139  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
140  auto getConflictingEntityStatusOnLane(const lanelet::Ids & route_lanelets) const
141  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
142  auto isOtherEntityAtConsideredAltitude(
143  const traffic_simulator::CanonicalizedEntityStatus & entity_status) const -> bool;
144 };
145 } // namespace entity_behavior
146 
147 #endif // BEHAVIOR_TREE_PLUGIN__ACTION_NODE_HPP_
Definition: action_node.hpp:43
EntityStatusDict other_entity_status
Definition: action_node.hpp:124
auto getDistanceToTrafficLightStopLine(const lanelet::Ids &route_lanelets, const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:205
void halt() override final
Definition: action_node.hpp:75
~ActionNode() override=default
lanelet::Ids route_lanelets
Definition: action_node.hpp:125
std::shared_ptr< traffic_simulator::CanonicalizedEntityStatus > canonicalized_entity_status
Definition: action_node.hpp:119
auto stopEntity() const -> void
Definition: action_node.cpp:97
auto calculateStopDistance(const traffic_simulator_msgs::msg::DynamicConstraints &) const -> double
Definition: action_node.cpp:550
auto getDistanceToStopLine(const lanelet::Ids &route_lanelets, const std::vector< geometry_msgs::msg::Point > &waypoints) const -> std::optional< double >
Definition: action_node.cpp:228
auto setCanonicalizedEntityStatus(const traffic_simulator::EntityStatus &entity_status) -> void
Definition: action_node.cpp:104
auto calculateUpdatedEntityStatus(double target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const -> traffic_simulator::EntityStatus
Definition: action_node.cpp:416
auto getHorizon() const -> double
Definition: action_node.cpp:92
std::shared_ptr< traffic_simulator::TrafficLightsBase > traffic_lights
Definition: action_node.hpp:118
double step_time
Definition: action_node.hpp:121
traffic_simulator::behavior::Request request
Definition: action_node.hpp:116
auto getDistanceToFrontEntity(const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:235
auto calculateUpdatedEntityStatusInWorldFrame(double target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const -> traffic_simulator::EntityStatus
Definition: action_node.cpp:509
auto getDistanceToTargetEntityPolygon(const math::geometry::CatmullRomSplineInterface &spline, const std::string target_name, double width_extension_right=0.0, double width_extension_left=0.0, double length_extension_front=0.0, double length_extension_rear=0.0) const -> std::optional< double >
Definition: action_node.cpp:299
auto getEntityStatus(const std::string &target_name) const -> const traffic_simulator::CanonicalizedEntityStatus &
Definition: action_node.cpp:289
auto getDistanceToConflictingEntity(const lanelet::Ids &route_lanelets, const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:336
double default_matching_distance_for_lanelet_pose_calculation
Definition: action_node.hpp:122
auto getYieldStopDistance(const lanelet::Ids &following_lanelets) const -> std::optional< double >
Definition: action_node.cpp:125
auto getFrontEntityName(const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< std::string >
Definition: action_node.cpp:245
auto getRightOfWayEntities() const -> std::vector< traffic_simulator::CanonicalizedEntityStatus >
Definition: action_node.cpp:181
auto getOtherEntityStatus(lanelet::Id lanelet_id) const -> std::vector< traffic_simulator::CanonicalizedEntityStatus >
Definition: action_node.cpp:111
double current_time
Definition: action_node.hpp:120
static BT::PortsList providedPorts()
Definition: action_node.hpp:77
ActionNode(const std::string &name, const BT::NodeConfiguration &config)
Definition: action_node.cpp:43
auto executeTick() -> BT::NodeStatus override
throws if the derived class return RUNNING.
Definition: action_node.cpp:48
auto foundConflictingEntity(const lanelet::Ids &following_lanelets) const -> bool
Definition: action_node.cpp:394
std::optional< double > target_speed
Definition: action_node.hpp:123
virtual auto getBlackBoardValues() -> void
Definition: action_node.cpp:50
Definition: catmull_rom_spline_interface.hpp:30
Definition: entity_status.hpp:32
Definition: action_node.hpp:39
std::unordered_map< std::string, traffic_simulator::CanonicalizedEntityStatus > EntityStatusDict
Definition: behavior_plugin_base.hpp:37
BT::PortsList operator+(const BT::PortsList &ports_0, const BT::PortsList &ports_1)
Definition: action_node.cpp:36
Definition: cache.hpp:46
Definition: bounding_box.hpp:32
Definition: cache.hpp:27
Request
Definition: behavior.hpp:25
Definition: api.hpp:48
std::string string
Definition: junit5.hpp:26
traffic_simulator_msgs::EntityStatus EntityStatus
Definition: helper_functions.hpp:32