15 #ifndef TRAFFIC_SIMULATOR__TRAFFIC__TRAFFIC_SOURCE_HPP_
16 #define TRAFFIC_SIMULATOR__TRAFFIC__TRAFFIC_SOURCE_HPP_
19 #include <geometry_msgs/msg/pose.hpp>
23 #include <traffic_simulator_msgs/msg/pedestrian_parameters.hpp>
24 #include <traffic_simulator_msgs/msg/vehicle_parameters.hpp>
43 const lanelet::Ids
ids;
48 const std::shared_ptr<hdmap_utils::HdMapUtils> &,
const geometry_msgs::msg::Pose &,
49 const double source_radius,
const bool include_crosswalk);
54 auto operator()(
const std::vector<geometry_msgs::msg::Point> &, lanelet::Id)
const -> bool;
69 std::vector<std::tuple<VehicleOrPedestrianParameter, std::string, std::string, double>>;
71 template <
typename Pose,
typename Parameters>
76 template <
typename Spawner>
78 const double radius,
const double rate,
const geometry_msgs::msg::Pose &
pose,
79 const Distribution & distribution,
const std::optional<int> seed,
const double current_time,
85 spawn_vehicle_in_lane_coordinate(spawn),
86 spawn_pedestrian_in_lane_coordinate(spawn),
87 spawn_vehicle_in_world_coordinate(spawn),
88 spawn_pedestrian_in_world_coordinate(spawn),
90 engine_(seed ? seed.value() :
std::random_device()()),
91 angle_distribution_(0.0, boost::
math::constants::two_pi<double>()),
92 radius_distribution_(0.0, radius),
93 params_distribution_([&]() {
94 auto weights = std::vector<double>();
95 weights.reserve(distribution.size());
96 for ([[maybe_unused]]
auto && [parameter, behavior, model3d, weight] : distribution) {
97 weights.push_back(weight);
99 return std::discrete_distribution<std::size_t>(weights.begin(), weights.end());
101 start_execution_time_(
103 (std::isnan(current_time) ? 0.0 : current_time) + std::max(configuration.start_delay, 0.0)),
104 configuration_(configuration),
105 distribution_(distribution),
107 validate_considering_crosswalk(
hdmap_utils,
pose, radius_distribution_.max(),
true)
111 void execute(
const double current_time,
const double step_time)
override;
115 const geometry_msgs::msg::Pose
pose;
117 const std::size_t
id;
120 auto makeRandomPose(
const bool random_orientation =
false) -> geometry_msgs::msg::Pose;
123 -> std::pair<bool, std::optional<CanonicalizedLaneletPose>>;
125 static inline std::size_t source_count_ = 0;
127 std::size_t entity_count_ = 0;
137 const std::shared_ptr<hdmap_utils::HdMapUtils> hdmap_utils_;
139 std::mt19937 engine_;
141 std::uniform_real_distribution<double> angle_distribution_;
143 std::uniform_real_distribution<double> radius_distribution_;
145 std::discrete_distribution<std::size_t> params_distribution_;
147 const double start_execution_time_;
154 const Validator validate, validate_considering_crosswalk;
Definition: traffic_module_base.hpp:36
Definition: traffic_source.hpp:31
void execute(const double current_time, const double step_time) override
Definition: traffic_source.cpp:94
std::function< void(const std::string &, const Pose &, const Parameters &, const std::string &, const std::string &)> Spawner
Definition: traffic_source.hpp:74
traffic_simulator_msgs::msg::PedestrianParameters PedestrianParameter
Definition: traffic_source.hpp:35
const double rate
Definition: traffic_source.hpp:113
std::vector< std::tuple< VehicleOrPedestrianParameter, std::string, std::string, double > > Distribution
Definition: traffic_source.hpp:69
traffic_simulator_msgs::msg::VehicleParameters VehicleParameter
Definition: traffic_source.hpp:33
std::variant< VehicleParameter, PedestrianParameter > VehicleOrPedestrianParameter
Definition: traffic_source.hpp:37
const geometry_msgs::msg::Pose pose
Definition: traffic_source.hpp:115
const std::size_t id
Definition: traffic_source.hpp:117
TrafficSource(const double radius, const double rate, const geometry_msgs::msg::Pose &pose, const Distribution &distribution, const std::optional< int > seed, const double current_time, const Configuration &configuration, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils, const Spawner &spawn)
Definition: traffic_source.hpp:77
Definition: bounding_box.hpp:32
std::string string
Definition: junit5.hpp:26
Definition: traffic_source.hpp:58
bool require_footprint_fitting
Definition: traffic_source.hpp:61
bool allow_spawn_outside_lane
Definition: traffic_source.hpp:59
double start_delay
Definition: traffic_source.hpp:65
bool use_random_orientation
Definition: traffic_source.hpp:63
Definition: traffic_source.hpp:40
Validator(const std::shared_ptr< hdmap_utils::HdMapUtils > &, const geometry_msgs::msg::Pose &, const double source_radius, const bool include_crosswalk)
Definition: traffic_source.cpp:26
const lanelet::Ids ids
Definition: traffic_source.hpp:43
auto operator()(const std::vector< geometry_msgs::msg::Point > &, lanelet::Id) const -> bool
whether the 2D polygon does fit inside the lanelet with the given id
Definition: traffic_source.cpp:35
const lanelet::Lanelets lanelets
Definition: traffic_source.hpp:45
static constexpr std::size_t spawning_lanes_limit
Definition: traffic_source.hpp:41