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