scenario_simulator_v2 C++ API
ego_entity.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 TRAFFIC_SIMULATOR__ENTITY__EGO_ENTITY_HPP_
16 #define TRAFFIC_SIMULATOR__ENTITY__EGO_ENTITY_HPP_
17 
18 #include <algorithm>
19 #include <boost/filesystem.hpp>
21 #include <memory>
22 #include <optional>
23 #include <string>
27 #include <traffic_simulator_msgs/msg/entity_type.hpp>
28 #include <vector>
29 
30 namespace traffic_simulator
31 {
32 namespace entity
33 {
34 class EgoEntity : public VehicleEntity
35 {
36  const std::unique_ptr<concealer::FieldOperatorApplication> field_operator_application;
37 
38  static auto makeFieldOperatorApplication(
39  const Configuration &, const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &)
40  -> std::unique_ptr<concealer::FieldOperatorApplication>;
41 
42  bool is_controlled_by_simulator_{false};
43  std::optional<double> target_speed_;
44  traffic_simulator_msgs::msg::BehaviorParameter behavior_parameter_;
45  std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> polyline_trajectory_;
46 
47 public:
48  explicit EgoEntity() = delete;
49 
50  explicit EgoEntity(
52  const std::shared_ptr<hdmap_utils::HdMapUtils> &,
53  const traffic_simulator_msgs::msg::VehicleParameters &, const Configuration &,
54  const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr &);
55 
56  explicit EgoEntity(EgoEntity &&) = delete;
57 
58  explicit EgoEntity(const EgoEntity &) = delete;
59 
60  ~EgoEntity() override = default;
61 
62  auto operator=(EgoEntity &&) -> EgoEntity & = delete;
63 
64  auto operator=(const EgoEntity &) -> EgoEntity & = delete;
65 
66  auto asFieldOperatorApplication() const -> concealer::FieldOperatorApplication & override;
67 
68  auto getCurrentAction() const -> std::string override;
69 
70  auto getCurrentPose() const -> const geometry_msgs::msg::Pose &;
71 
72  auto getDefaultDynamicConstraints() const
73  -> const traffic_simulator_msgs::msg::DynamicConstraints & override;
74 
75  auto getBehaviorParameter() const -> traffic_simulator_msgs::msg::BehaviorParameter override;
76 
77  auto getEntityStatus(const double, const double) const -> const CanonicalizedEntityStatus;
78 
79  auto getEntityTypename() const -> const std::string & override;
80 
81  auto getObstacle() -> std::optional<traffic_simulator_msgs::msg::Obstacle> override;
82 
83  auto getRouteLanelets(double horizon = 100) -> lanelet::Ids override;
84 
85  auto getWaypoints() -> const traffic_simulator_msgs::msg::WaypointsArray override;
86 
87  auto updateFieldOperatorApplication() const -> void;
88 
89  void onUpdate(double current_time, double step_time) override;
90 
91  void requestAcquirePosition(const CanonicalizedLaneletPose &) override;
92 
93  void requestAcquirePosition(const geometry_msgs::msg::Pose & map_pose) override;
94 
95  void requestAssignRoute(const std::vector<CanonicalizedLaneletPose> &) override;
96 
97  void requestAssignRoute(const std::vector<geometry_msgs::msg::Pose> &) override;
98 
100  const std::shared_ptr<traffic_simulator_msgs::msg::PolylineTrajectory> &) -> void override;
101 
102  void requestLaneChange(const lanelet::Id) override;
103 
104  auto requestLaneChange(const traffic_simulator::lane_change::Parameter &) -> void override;
105 
106  auto requestSpeedChange(
107  const double, const speed_change::Transition, const speed_change::Constraint,
108  const bool continuous) -> void override;
109 
110  auto requestSpeedChange(
111  const speed_change::RelativeTargetSpeed &, const speed_change::Transition,
112  const speed_change::Constraint, const bool continuous) -> void override;
113 
114  void requestClearRoute() override;
115 
116  auto isControlledBySimulator() const -> bool override;
117 
118  auto setControlledBySimulator(bool state) -> void override
119  {
120  is_controlled_by_simulator_ = state;
121  }
122 
123  auto setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &)
124  -> void override;
125 
126  void requestSpeedChange(double, bool continuous) override;
127 
128  void requestSpeedChange(
129  const speed_change::RelativeTargetSpeed & target_speed, bool continuous) override;
130 
131  auto setVelocityLimit(double) -> void override;
132 
133  auto setMapPose(const geometry_msgs::msg::Pose & map_pose) -> void override;
134 
135  template <typename... Ts>
136  auto setStatus(Ts &&... xs)
137  {
138  if (status_->getTime() > 0 && not isControlledBySimulator()) {
140  "You cannot set entity status to the ego vehicle named ", std::quoted(status_->getName()),
141  " after starting scenario.");
142  } else {
143  EntityBase::setStatus(std::forward<decltype(xs)>(xs)...);
144  }
145  }
146 };
147 } // namespace entity
148 } // namespace traffic_simulator
149 
150 #endif // TRAFFIC_SIMULATOR__ENTITY__EGO_ENTITY_HPP_
Definition: ego_entity.hpp:35
auto getObstacle() -> std::optional< traffic_simulator_msgs::msg::Obstacle > override
Definition: ego_entity.cpp:107
auto setMapPose(const geometry_msgs::msg::Pose &map_pose) -> void override
Definition: ego_entity.cpp:294
void requestAssignRoute(const std::vector< CanonicalizedLaneletPose > &) override
Definition: ego_entity.cpp:180
void requestLaneChange(const lanelet::Id) override
Definition: ego_entity.cpp:225
void requestAcquirePosition(const CanonicalizedLaneletPose &) override
Definition: ego_entity.cpp:170
auto getWaypoints() -> const traffic_simulator_msgs::msg::WaypointsArray override
Definition: ego_entity.cpp:132
auto getEntityStatus(const double, const double) const -> const CanonicalizedEntityStatus
auto getCurrentPose() const -> const geometry_msgs::msg::Pose &
Definition: ego_entity.cpp:127
auto getDefaultDynamicConstraints() const -> const traffic_simulator_msgs::msg::DynamicConstraints &override
Definition: ego_entity.cpp:259
auto setStatus(Ts &&... xs)
Definition: ego_entity.hpp:136
auto asFieldOperatorApplication() const -> concealer::FieldOperatorApplication &override
Definition: ego_entity.cpp:81
void requestClearRoute() override
Definition: ego_entity.cpp:257
auto updateFieldOperatorApplication() const -> void
Definition: ego_entity.cpp:137
void onUpdate(double current_time, double step_time) override
Definition: ego_entity.cpp:143
auto setControlledBySimulator(bool state) -> void override
Definition: ego_entity.hpp:118
auto getEntityTypename() const -> const std::string &override
Definition: ego_entity.cpp:101
auto requestFollowTrajectory(const std::shared_ptr< traffic_simulator_msgs::msg::PolylineTrajectory > &) -> void override
Definition: ego_entity.cpp:217
auto setVelocityLimit(double) -> void override
Definition: ego_entity.cpp:288
auto operator=(EgoEntity &&) -> EgoEntity &=delete
auto getCurrentAction() const -> std::string override
Definition: ego_entity.cpp:87
auto operator=(const EgoEntity &) -> EgoEntity &=delete
auto getRouteLanelets(double horizon=100) -> lanelet::Ids override
Definition: ego_entity.cpp:112
EgoEntity(const EgoEntity &)=delete
auto setBehaviorParameter(const traffic_simulator_msgs::msg::BehaviorParameter &) -> void override
Definition: ego_entity.cpp:265
auto getBehaviorParameter() const -> traffic_simulator_msgs::msg::BehaviorParameter override
Definition: ego_entity.cpp:93
auto requestSpeedChange(const double, const speed_change::Transition, const speed_change::Constraint, const bool continuous) -> void override
Definition: ego_entity.cpp:241
auto isControlledBySimulator() const -> bool override
Definition: ego_entity.cpp:215
virtual auto setStatus(const EntityStatus &status, const lanelet::Ids &lanelet_ids) -> void
Definition: entity_base.cpp:546
const std::string name
Definition: entity_base.hpp:255
std::shared_ptr< CanonicalizedEntityStatus > status_
Definition: entity_base.hpp:260
Definition: vehicle_entity.hpp:37
Definition: entity_status.hpp:32
Definition: lanelet_pose.hpp:27
#define THROW_SEMANTIC_ERROR(...)
Definition: exception.hpp:59
Definition: autoware_universe.hpp:40
Definition: cache.hpp:27
Transition
Definition: speed_change.hpp:26
Definition: api.hpp:48
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: configuration.hpp:30