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>
34 #include <traffic_simulator_msgs/msg/obstacle.hpp>
35 #include <traffic_simulator_msgs/msg/waypoints_array.hpp>
36 #include <unordered_map>
37 #include <vector>
38 
39 namespace entity_behavior
40 {
41 BT::PortsList operator+(const BT::PortsList & ports_0, const BT::PortsList & ports_1);
42 
43 class ActionNode : public BT::ActionNodeBase
44 {
45 public:
46  ActionNode(const std::string & name, const BT::NodeConfiguration & config);
47  ~ActionNode() override = default;
48  auto foundConflictingEntity(const lanelet::Ids & following_lanelets) const -> bool;
50  const lanelet::Ids & route_lanelets,
51  const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;
53  -> std::optional<std::string>;
54  auto calculateStopDistance(const traffic_simulator_msgs::msg::DynamicConstraints &) const
55  -> double;
57  -> std::optional<double>;
59  const lanelet::Ids & route_lanelets,
60  const math::geometry::CatmullRomSplineInterface & spline) const -> std::optional<double>;
61  auto getRightOfWayEntities() const -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
62  auto getRightOfWayEntities(const lanelet::Ids & following_lanelets) const
63  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
64  auto getYieldStopDistance(const lanelet::Ids & following_lanelets) const -> std::optional<double>;
65  auto getOtherEntityStatus(lanelet::Id lanelet_id) const
66  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
67  auto stopEntity() const -> void;
68  auto getHorizon() const -> double;
69 
71  auto executeTick() -> BT::NodeStatus override;
72 
73  void halt() override final { setStatus(BT::NodeStatus::IDLE); }
74 
75  static BT::PortsList providedPorts()
76  {
77  return {
78  // clang-format off
79  BT::InputPort<double>("current_time"),
80  BT::InputPort<double>("matching_distance_for_lanelet_pose_calculation"),
81  BT::InputPort<double>("step_time"),
82  BT::InputPort<EntityStatusDict>("other_entity_status"),
83  BT::InputPort<lanelet::Ids>("route_lanelets"),
84  BT::InputPort<std::optional<double>>("target_speed"),
85  BT::InputPort<std::shared_ptr<hdmap_utils::HdMapUtils>>("hdmap_utils"),
86  BT::InputPort<std::shared_ptr<traffic_simulator::CanonicalizedEntityStatus>>("canonicalized_entity_status"),
87  BT::InputPort<std::shared_ptr<traffic_simulator::TrafficLightsBase>>("traffic_lights"),
88  BT::InputPort<traffic_simulator::behavior::Request>("request"),
89  BT::OutputPort<std::optional<traffic_simulator_msgs::msg::Obstacle>>("obstacle"),
90  BT::OutputPort<traffic_simulator_msgs::msg::WaypointsArray>("waypoints"),
91  BT::OutputPort<traffic_simulator::behavior::Request>("request"),
92  // clang-format on
93  };
94  }
95 
96  virtual auto getBlackBoardValues() -> void;
97  auto getEntityStatus(const std::string & target_name) const
99 
100  auto setCanonicalizedEntityStatus(const traffic_simulator::EntityStatus & entity_status) -> void;
102  const double local_target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const
105  const double local_target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const
107 
108 protected:
110  std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils;
111  std::shared_ptr<traffic_simulator::TrafficLightsBase> traffic_lights;
112  std::shared_ptr<traffic_simulator::CanonicalizedEntityStatus> canonicalized_entity_status;
113  double current_time;
114  double step_time;
116  std::optional<double> target_speed;
118  lanelet::Ids route_lanelets;
119 
122  const traffic_simulator::CanonicalizedEntityStatus & status) const -> std::optional<double>;
123 
124 private:
125  auto getDistanceToTargetEntityOnCrosswalk(
127  const traffic_simulator::CanonicalizedEntityStatus & status) const -> std::optional<double>;
128  auto getConflictingEntityStatus(const lanelet::Ids & following_lanelets) const
129  -> std::optional<traffic_simulator::CanonicalizedEntityStatus>;
130  auto getConflictingEntityStatusOnCrossWalk(const lanelet::Ids & route_lanelets) const
131  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
132  auto getConflictingEntityStatusOnLane(const lanelet::Ids & route_lanelets) const
133  -> std::vector<traffic_simulator::CanonicalizedEntityStatus>;
134  auto isOtherEntityAtConsideredAltitude(
135  const traffic_simulator::CanonicalizedEntityStatus & entity_status) const -> bool;
136 };
137 } // namespace entity_behavior
138 
139 #endif // BEHAVIOR_TREE_PLUGIN__ACTION_NODE_HPP_
Definition: action_node.hpp:44
EntityStatusDict other_entity_status
Definition: action_node.hpp:117
auto getDistanceToTrafficLightStopLine(const lanelet::Ids &route_lanelets, const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:204
void halt() override final
Definition: action_node.hpp:73
~ActionNode() override=default
lanelet::Ids route_lanelets
Definition: action_node.hpp:118
std::shared_ptr< traffic_simulator::CanonicalizedEntityStatus > canonicalized_entity_status
Definition: action_node.hpp:112
auto stopEntity() const -> void
Definition: action_node.cpp:101
auto calculateStopDistance(const traffic_simulator_msgs::msg::DynamicConstraints &) const -> double
Definition: action_node.cpp:581
auto calculateUpdatedEntityStatus(const double local_target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const -> traffic_simulator::EntityStatus
Definition: action_node.cpp:455
auto setCanonicalizedEntityStatus(const traffic_simulator::EntityStatus &entity_status) -> void
Definition: action_node.cpp:108
auto getHorizon() const -> double
Definition: action_node.cpp:96
std::shared_ptr< traffic_simulator::TrafficLightsBase > traffic_lights
Definition: action_node.hpp:111
double step_time
Definition: action_node.hpp:114
traffic_simulator::behavior::Request request
Definition: action_node.hpp:109
auto getDistanceToFrontEntity(const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:227
auto getEntityStatus(const std::string &target_name) const -> const traffic_simulator::CanonicalizedEntityStatus &
Definition: action_node.cpp:281
std::shared_ptr< hdmap_utils::HdMapUtils > hdmap_utils
Definition: action_node.hpp:110
auto getDistanceToConflictingEntity(const lanelet::Ids &route_lanelets, const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< double >
Definition: action_node.cpp:380
double default_matching_distance_for_lanelet_pose_calculation
Definition: action_node.hpp:115
auto getYieldStopDistance(const lanelet::Ids &following_lanelets) const -> std::optional< double >
Definition: action_node.cpp:127
auto calculateUpdatedEntityStatusInWorldFrame(const double local_target_speed, const traffic_simulator_msgs::msg::DynamicConstraints &) const -> traffic_simulator::EntityStatus
Definition: action_node.cpp:496
auto getFrontEntityName(const math::geometry::CatmullRomSplineInterface &spline) const -> std::optional< std::string >
Definition: action_node.cpp:237
auto getRightOfWayEntities() const -> std::vector< traffic_simulator::CanonicalizedEntityStatus >
Definition: action_node.cpp:182
auto getOtherEntityStatus(lanelet::Id lanelet_id) const -> std::vector< traffic_simulator::CanonicalizedEntityStatus >
Definition: action_node.cpp:115
double current_time
Definition: action_node.hpp:113
static BT::PortsList providedPorts()
Definition: action_node.hpp:75
ActionNode(const std::string &name, const BT::NodeConfiguration &config)
Definition: action_node.cpp:47
auto executeTick() -> BT::NodeStatus override
throws if the derived class return RUNNING.
Definition: action_node.cpp:52
auto foundConflictingEntity(const lanelet::Ids &following_lanelets) const -> bool
Definition: action_node.cpp:435
auto getDistanceToTargetEntity(const math::geometry::CatmullRomSplineInterface &spline, const traffic_simulator::CanonicalizedEntityStatus &status) const -> std::optional< double >
Definition: action_node.cpp:306
std::optional< double > target_speed
Definition: action_node.hpp:116
virtual auto getBlackBoardValues() -> void
Definition: action_node.cpp:54
Definition: catmull_rom_spline_interface.hpp:30
Definition: entity_status.hpp:32
Definition: action_node.hpp:40
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:40
Definition: lanelet_wrapper.hpp:40
Request
Definition: behavior.hpp:25
Definition: api.hpp:32
traffic_simulator_msgs::msg::EntityStatus EntityStatus
Definition: entity_status.hpp:25
std::string string
Definition: junit5.hpp:26