scenario_simulator_v2 C++ API
simulator_core.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 OPENSCENARIO_INTERPRETER__SIMULATOR_CORE_HPP_
16 #define OPENSCENARIO_INTERPRETER__SIMULATOR_CORE_HPP_
17 
30 
32 {
33 using NativeWorldPosition = geometry_msgs::msg::Pose;
34 
36 
38 
40 
42 {
43  static inline std::unique_ptr<traffic_simulator::API> core = nullptr;
44 
45 public:
46  template <typename Node, typename... Ts>
47  static auto activate(
48  const Node & node, const traffic_simulator::Configuration & configuration, Ts &&... xs) -> void
49  {
50  if (not active()) {
51  core = std::make_unique<traffic_simulator::API>(
52  node, configuration, std::forward<decltype(xs)>(xs)...);
53  } else {
54  throw Error("The simulator core has already been instantiated.");
55  }
56  }
57 
58  static auto active() { return static_cast<bool>(core); }
59 
60  static auto deactivate() -> void
61  {
62  if (active()) {
63  core->despawnEntities();
64  core->closeZMQConnection();
65  core.reset();
66  }
67  }
68 
69  static auto update() -> void { core->updateFrame(); }
70 
72  {
73  protected:
74  static auto canonicalize(const traffic_simulator::LaneletPose & non_canonicalized)
76  {
77  return NativeLanePosition(non_canonicalized, core->getHdmapUtils());
78  }
79 
80  template <typename T, typename std::enable_if_t<std::is_same_v<T, NativeLanePosition>, int> = 0>
81  static auto convert(const NativeWorldPosition & pose) -> NativeLanePosition
82  {
83  constexpr bool include_crosswalk{false};
84  if (
86  pose, include_crosswalk, core->getHdmapUtils())) {
87  return result.value();
88  } else {
89  throw Error(
90  "The specified WorldPosition = [", pose.position.x, ", ", pose.position.y, ", ",
91  pose.position.z,
92  "] could not be approximated to the proper Lane. Perhaps the "
93  "WorldPosition points to a location where multiple lanes overlap, and "
94  "there are at least two or more candidates for a LanePosition that "
95  "can be approximated to that WorldPosition. This issue can be "
96  "resolved by strictly specifying the location using LanePosition "
97  "instead of WorldPosition");
98  }
99  }
100 
101  template <
102  typename T, typename std::enable_if_t<std::is_same_v<T, NativeWorldPosition>, int> = 0>
103  static auto convert(const NativeLanePosition & native_lane_position) -> NativeWorldPosition
104  {
105  return traffic_simulator::pose::toMapPose(native_lane_position);
106  }
107 
109  const std::string & from_entity_name, const std::string & to_entity_name)
110  {
111  if (const auto from_entity = core->getEntity(from_entity_name)) {
112  if (const auto to_entity = core->getEntity(to_entity_name)) {
113  if (
114  const auto relative_pose = traffic_simulator::pose::relativePose(
115  from_entity->getMapPose(), to_entity->getMapPose()))
116  return relative_pose.value();
117  }
118  }
120  }
121 
123  const std::string & from_entity_name, const NativeWorldPosition & to_map_pose)
124  {
125  if (const auto from_entity = core->getEntity(from_entity_name)) {
126  if (
127  const auto relative_pose =
128  traffic_simulator::pose::relativePose(from_entity->getMapPose(), to_map_pose)) {
129  return relative_pose.value();
130  }
131  }
133  }
134 
136  const NativeWorldPosition & from_map_pose, const std::string & to_entity_name)
137  {
138  if (const auto to_entity = core->getEntity(to_entity_name)) {
139  if (
140  const auto relative_pose =
141  traffic_simulator::pose::relativePose(from_map_pose, to_entity->getMapPose())) {
142  return relative_pose.value();
143  }
144  }
146  }
147 
149  const std::string & from_entity_name, const std::string & to_entity_name,
150  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
152  {
153  if (const auto to_entity = core->getEntity(to_entity_name)) {
154  if (const auto to_lanelet_pose = to_entity->getCanonicalizedLaneletPose()) {
156  from_entity_name, to_lanelet_pose.value(), routing_algorithm);
157  }
158  }
160  }
161 
163  const std::string & from_entity_name, const NativeLanePosition & to_lanelet_pose,
164  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
166  {
167  if (const auto from_entity = core->getEntity(from_entity_name)) {
168  if (const auto from_lanelet_pose = from_entity->getCanonicalizedLaneletPose()) {
170  from_lanelet_pose.value(), to_lanelet_pose, routing_algorithm);
171  }
172  }
174  }
175 
177  const NativeLanePosition & from_lanelet_pose, const NativeLanePosition & to_lanelet_pose,
178  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
180  {
181  traffic_simulator::RoutingConfiguration routing_configuration;
182  routing_configuration.allow_lane_change =
183  (routing_algorithm == RoutingAlgorithm::value_type::shortest);
185  from_lanelet_pose, to_lanelet_pose, routing_configuration, core->getHdmapUtils());
186  }
187 
189  const std::string & from_entity_name, const std::string & to_entity_name,
190  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
191  {
192  if (const auto from_entity = core->getEntity(from_entity_name)) {
193  if (const auto to_entity = core->getEntity(to_entity_name)) {
194  if (const auto from_lanelet_pose = from_entity->getCanonicalizedLaneletPose()) {
195  if (const auto to_lanelet_pose = to_entity->getCanonicalizedLaneletPose()) {
197  from_lanelet_pose.value(), from_entity->getBoundingBox(), to_lanelet_pose.value(),
198  to_entity->getBoundingBox(), routing_algorithm);
199  }
200  }
201  }
202  }
204  }
205 
207  const std::string & from_entity_name, const NativeLanePosition & to_lanelet_pose,
208  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
209  {
210  if (const auto from_entity = core->getEntity(from_entity_name)) {
211  if (const auto from_lanelet_pose = from_entity->getCanonicalizedLaneletPose()) {
213  from_lanelet_pose.value(), from_entity->getBoundingBox(), to_lanelet_pose,
214  traffic_simulator_msgs::msg::BoundingBox(), routing_algorithm);
215  }
216  }
218  }
219 
221  const NativeLanePosition & from_lanelet_pose,
222  const traffic_simulator_msgs::msg::BoundingBox & from_bounding_box,
223  const NativeLanePosition & to_lanelet_pose,
224  const traffic_simulator_msgs::msg::BoundingBox & to_bounding_box,
225  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined)
227  {
228  traffic_simulator::RoutingConfiguration routing_configuration;
229  routing_configuration.allow_lane_change =
230  (routing_algorithm == RoutingAlgorithm::value_type::shortest);
232  from_lanelet_pose, from_bounding_box, to_lanelet_pose, to_bounding_box,
233  routing_configuration, core->getHdmapUtils());
234  }
235 
237  const std::string & from_entity_name, const std::string & to_entity_name)
238  {
239  if (const auto from_entity = core->getEntity(from_entity_name)) {
240  if (const auto to_entity = core->getEntity(to_entity_name)) {
241  if (
242  const auto relative_pose = traffic_simulator::pose::boundingBoxRelativePose(
243  from_entity->getMapPose(), from_entity->getBoundingBox(), to_entity->getMapPose(),
244  to_entity->getBoundingBox())) {
245  return relative_pose.value();
246  }
247  }
248  }
250  }
251 
253  const std::string & from_entity_name, const NativeWorldPosition & to_map_pose)
254  {
255  if (const auto from_entity = core->getEntity(from_entity_name)) {
256  if (
257  const auto relative_pose = traffic_simulator::pose::boundingBoxRelativePose(
258  from_entity->getMapPose(), from_entity->getBoundingBox(), to_map_pose,
259  traffic_simulator_msgs::msg::BoundingBox())) {
260  return relative_pose.value();
261  }
262  }
264  }
265 
267  const std::string & from_entity_name, const std::string & to_entity_name,
268  const RoutingAlgorithm::value_type routing_algorithm = RoutingAlgorithm::undefined) -> int
269  {
270  traffic_simulator::RoutingConfiguration routing_configuration;
271  routing_configuration.allow_lane_change =
272  (routing_algorithm == RoutingAlgorithm::value_type::shortest);
273  if (const auto from_entity = core->getEntity(from_entity_name)) {
274  if (const auto to_entity = core->getEntity(to_entity_name)) {
275  if (
277  from_entity->getCanonicalizedLaneletPose().value(),
278  to_entity->getCanonicalizedLaneletPose().value(), routing_configuration,
279  core->getHdmapUtils())) {
280  return lane_changes.value().first - lane_changes.value().second;
281  }
282  }
283  }
284  throw common::Error(
285  "Failed to evaluate lateral relative lanes between ", from_entity_name, " and ",
286  to_entity_name);
287  }
288  };
289 
290  class ActionApplication // OpenSCENARIO 1.1.1 Section 3.1.5
291  {
292  protected:
293  template <typename... Ts>
294  static auto applyAcquirePositionAction(const std::string & entity_ref, Ts &&... xs)
295  {
296  core->requestClearRoute(entity_ref);
297  return core->requestAcquirePosition(entity_ref, std::forward<decltype(xs)>(xs)...);
298  }
299 
300  template <typename... Ts>
301  static auto applyAddEntityAction(Ts &&... xs)
302  {
303  return core->spawn(std::forward<decltype(xs)>(xs)...);
304  }
305 
306  template <typename EntityRef, typename DynamicConstraints>
307  static auto applyProfileAction(
308  const EntityRef & entity_ref, const DynamicConstraints & dynamic_constraints) -> void
309  {
310  return core->setBehaviorParameter(entity_ref, [&]() {
311  auto behavior_parameter = core->getBehaviorParameter(entity_ref);
312 
313  if (not std::isinf(dynamic_constraints.max_speed)) {
314  behavior_parameter.dynamic_constraints.max_speed = dynamic_constraints.max_speed;
315  }
316 
317  if (not std::isinf(dynamic_constraints.max_acceleration)) {
318  behavior_parameter.dynamic_constraints.max_acceleration =
319  dynamic_constraints.max_acceleration;
320  }
321 
322  if (not std::isinf(dynamic_constraints.max_acceleration_rate)) {
323  behavior_parameter.dynamic_constraints.max_acceleration_rate =
324  dynamic_constraints.max_acceleration_rate;
325  }
326 
327  if (not std::isinf(dynamic_constraints.max_deceleration)) {
328  behavior_parameter.dynamic_constraints.max_deceleration =
329  dynamic_constraints.max_deceleration;
330  }
331 
332  if (not std::isinf(dynamic_constraints.max_deceleration_rate)) {
333  behavior_parameter.dynamic_constraints.max_deceleration_rate =
334  dynamic_constraints.max_deceleration_rate;
335  }
336 
337  return behavior_parameter;
338  }());
339  }
340 
341  template <typename Controller>
343  const std::string & entity_ref, Controller && controller) -> void
344  {
345  core->setVelocityLimit(
346  entity_ref, controller.properties.template get<Double>(
347  "maxSpeed", std::numeric_limits<Double::value_type>::max()));
348 
349  core->setBehaviorParameter(entity_ref, [&]() {
350  auto message = core->getBehaviorParameter(entity_ref);
351  message.see_around = not controller.properties.template get<Boolean>("isBlind");
353  message.dynamic_constraints.max_acceleration =
354  controller.properties.template get<Double>("maxAcceleration", 10.0);
355  message.dynamic_constraints.max_acceleration_rate =
356  controller.properties.template get<Double>("maxAccelerationRate", 3.0);
357  message.dynamic_constraints.max_deceleration =
358  controller.properties.template get<Double>("maxDeceleration", 10.0);
359  message.dynamic_constraints.max_deceleration_rate =
360  controller.properties.template get<Double>("maxDecelerationRate", 3.0);
361  message.dynamic_constraints.max_speed =
362  controller.properties.template get<Double>("maxSpeed", 50.0);
363  return message;
364  }());
365 
366  if (controller.isAutoware()) {
367  core->attachImuSensor(entity_ref, [&]() {
368  simulation_api_schema::ImuSensorConfiguration configuration;
369  configuration.set_entity(entity_ref);
370  configuration.set_frame_id("base_link");
371  configuration.set_add_gravity(true);
372  configuration.set_use_seed(true);
373  configuration.set_seed(0);
374  configuration.set_noise_standard_deviation_orientation(0.01);
375  configuration.set_noise_standard_deviation_twist(0.01);
376  configuration.set_noise_standard_deviation_acceleration(0.01);
377  return configuration;
378  }());
379 
380  core->attachLidarSensor([&]() {
381  simulation_api_schema::LidarConfiguration configuration;
382 
383  auto degree_to_radian = [](auto degree) {
384  return degree / 180.0 * boost::math::constants::pi<double>();
385  };
386 
387  // clang-format off
388  configuration.set_architecture_type(core->getROS2Parameter<std::string>("architecture_type", "awf/universe/20240605"));
389  configuration.set_entity(entity_ref);
390  configuration.set_horizontal_resolution(degree_to_radian(controller.properties.template get<Double>("pointcloudHorizontalResolution", 1.0)));
391  configuration.set_lidar_sensor_delay(controller.properties.template get<Double>("pointcloudPublishingDelay"));
392  configuration.set_scan_duration(0.1);
393  // clang-format on
394 
395  const auto vertical_field_of_view = degree_to_radian(
396  controller.properties.template get<Double>("pointcloudVerticalFieldOfView", 30.0));
397 
398  const auto channels =
399  controller.properties.template get<UnsignedInteger>("pointcloudChannels", 16);
400 
401  for (std::size_t i = 0; i < channels; ++i) {
402  configuration.add_vertical_angles(
403  vertical_field_of_view / 2 - vertical_field_of_view / channels * i);
404  }
405 
406  return configuration;
407  }());
408 
409  core->attachDetectionSensor([&]() {
410  simulation_api_schema::DetectionSensorConfiguration configuration;
411  // clang-format off
412  configuration.set_architecture_type(core->getROS2Parameter<std::string>("architecture_type", "awf/universe/20240605"));
413  configuration.set_entity(entity_ref);
414  configuration.set_detect_all_objects_in_range(controller.properties.template get<Boolean>("isClairvoyant"));
415  configuration.set_object_recognition_delay(controller.properties.template get<Double>("detectedObjectPublishingDelay"));
416  configuration.set_pos_noise_stddev(controller.properties.template get<Double>("detectedObjectPositionStandardDeviation"));
417  configuration.set_probability_of_lost(controller.properties.template get<Double>("detectedObjectMissingProbability"));
418  configuration.set_random_seed(controller.properties.template get<UnsignedInteger>("randomSeed"));
419  configuration.set_range(controller.properties.template get<Double>("detectionSensorRange",300.0));
420  configuration.set_object_recognition_ground_truth_delay(controller.properties.template get<Double>("detectedObjectGroundTruthPublishingDelay"));
421  configuration.set_update_duration(0.1);
422  // clang-format on
423  return configuration;
424  }());
425 
426  core->attachOccupancyGridSensor([&]() {
427  simulation_api_schema::OccupancyGridSensorConfiguration configuration;
428  // clang-format off
429  configuration.set_architecture_type(core->getROS2Parameter<std::string>("architecture_type", "awf/universe/20240605"));
430  configuration.set_entity(entity_ref);
431  configuration.set_filter_by_range(controller.properties.template get<Boolean>("isClairvoyant"));
432  configuration.set_height(200);
433  configuration.set_range(300);
434  configuration.set_resolution(0.5);
435  configuration.set_update_duration(0.1);
436  configuration.set_width(200);
437  // clang-format on
438  return configuration;
439  }());
440 
441  core->attachPseudoTrafficLightDetector([&]() {
442  simulation_api_schema::PseudoTrafficLightDetectorConfiguration configuration;
443  configuration.set_architecture_type(
444  core->getROS2Parameter<std::string>("architecture_type", "awf/universe/20240605"));
445  return configuration;
446  }());
447 
448  core->asFieldOperatorApplication(entity_ref)
449  .declare_parameter<bool>(
450  "allow_goal_modification",
451  controller.properties.template get<Boolean>("allowGoalModification"));
452 
453  for (const auto & module :
454  [](std::string manual_modules_string) {
455  manual_modules_string.erase(
456  std::remove_if(
457  manual_modules_string.begin(), manual_modules_string.end(),
458  [](const auto & c) { return std::isspace(c); }),
459  manual_modules_string.end());
460 
461  std::vector<std::string> modules;
462  std::string buffer;
463  std::istringstream modules_stream(manual_modules_string);
464  while (std::getline(modules_stream, buffer, ',')) {
465  modules.push_back(buffer);
466  }
467  return modules;
468  }(controller.properties.template get<String>(
469  "featureIdentifiersRequiringExternalPermissionForAutonomousDecisions"))) {
470  try {
471  core->asFieldOperatorApplication(entity_ref)
472  .requestAutoModeForCooperation(module, false);
473  } catch (const Error & error) {
474  throw Error(
475  "featureIdentifiersRequiringExternalPermissionForAutonomousDecisions is not "
476  "supported in this environment: ",
477  error.what());
478  }
479  }
480  }
481  }
482 
483  template <typename... Ts>
484  static auto applyAssignRouteAction(const std::string & entity_ref, Ts &&... xs)
485  {
486  core->requestClearRoute(entity_ref);
487  return core->requestAssignRoute(entity_ref, std::forward<decltype(xs)>(xs)...);
488  }
489 
490  template <typename... Ts>
491  static auto applyDeleteEntityAction(Ts &&... xs)
492  {
493  return core->despawn(std::forward<decltype(xs)>(xs)...);
494  }
495 
496  template <typename... Ts>
497  static auto applyFollowTrajectoryAction(Ts &&... xs)
498  {
499  return core->requestFollowTrajectory(std::forward<decltype(xs)>(xs)...);
500  }
501 
502  template <typename... Ts>
503  static auto applyLaneChangeAction(Ts &&... xs)
504  {
505  return core->requestLaneChange(std::forward<decltype(xs)>(xs)...);
506  }
507 
508  template <typename... Ts>
509  static auto applySpeedAction(Ts &&... xs)
510  {
511  return core->requestSpeedChange(std::forward<decltype(xs)>(xs)...);
512  }
513 
514  template <typename... Ts>
515  static auto applyTeleportAction(Ts &&... xs)
516  {
517  return core->setEntityStatus(std::forward<decltype(xs)>(xs)...);
518  }
519 
520  template <typename... Ts>
521  static auto applyWalkStraightAction(Ts &&... xs)
522  {
523  return core->requestWalkStraight(std::forward<decltype(xs)>(xs)...);
524  }
525  };
526 
527  // OpenSCENARIO 1.1.1 Section 3.1.5
529  {
530  protected:
531  template <typename... Ts>
532  static auto evaluateAcceleration(Ts &&... xs)
533  {
534  return core->getCurrentAccel(std::forward<decltype(xs)>(xs)...).linear.x;
535  }
536 
537  template <typename... Ts>
538  static auto evaluateCollisionCondition(Ts &&... xs) -> bool
539  {
540  return core->checkCollision(std::forward<decltype(xs)>(xs)...);
541  }
542 
544  const std::string & from_entity_name,
545  const std::string & to_entity_name) // for RelativeDistanceCondition
546  {
547  if (const auto from_entity = core->getEntity(from_entity_name)) {
548  if (const auto to_entity = core->getEntity(to_entity_name)) {
549  if (
551  from_entity->getMapPose(), from_entity->getBoundingBox(), to_entity->getMapPose(),
552  to_entity->getBoundingBox())) {
553  return distance.value();
554  }
555  }
556  }
557  return std::numeric_limits<double>::quiet_NaN();
558  }
559 
560  static auto evaluateRelativeSpeed(const Entity & from, const Entity & to) -> Eigen::Vector3d
561  {
562  if (const auto observer = core->getEntity(from.name())) {
563  if (const auto observed = core->getEntity(to.name())) {
564  auto velocity = [](const auto & entity) -> Eigen::Vector3d {
565  auto direction = [](const auto & q) -> Eigen::Vector3d {
566  return Eigen::Quaternion(q.w, q.x, q.y, q.z) * Eigen::Vector3d::UnitX();
567  };
568  return direction(entity->getMapPose().orientation) * entity->getCurrentTwist().linear.x;
569  };
570 
571  const Eigen::Matrix3d rotation =
572  math::geometry::getRotationMatrix(observer->getMapPose().orientation);
573 
574  return rotation.transpose() * velocity(observed) -
575  rotation.transpose() * velocity(observer);
576  }
577  }
578 
579  return Eigen::Vector3d(Double::nan(), Double::nan(), Double::nan());
580  }
581 
582  template <typename... Ts>
583  static auto evaluateSimulationTime(Ts &&... xs) -> double
584  {
585  if (SimulatorCore::active()) {
586  return core->getCurrentTime(std::forward<decltype(xs)>(xs)...);
587  } else {
588  return std::numeric_limits<double>::quiet_NaN();
589  }
590  }
591 
592  template <typename... Ts>
593  static auto evaluateSpeed(Ts &&... xs)
594  {
595  /*
596  The function name "evaluateSpeed" stands for "evaluate SpeedCondition"
597  and is a part used to implement `SpeedCondition::evaluate`.
598  SpeedCondition can be evaluated in three directions: longitudinal,
599  lateral, and vertical, based on the attribute direction. Therefore,
600  please note that this function returns velocity, that is, a vector,
601  rather than speed, contrary to the name "evaluateSpeed".
602  */
603  const auto linear = core->getCurrentTwist(std::forward<decltype(xs)>(xs)...).linear;
604  return Eigen::Vector3d(linear.x, linear.y, linear.z);
605  }
606 
607  template <typename... Ts>
608  static auto evaluateStandStill(Ts &&... xs)
609  {
610  return core->getStandStillDuration(std::forward<decltype(xs)>(xs)...);
611  }
612 
613  template <typename... Ts>
614  static auto evaluateTimeHeadway(Ts &&... xs)
615  {
616  if (const auto result = core->getTimeHeadway(std::forward<decltype(xs)>(xs)...); result) {
617  return result.value();
618  } else {
619  using value_type = typename std::decay<decltype(result)>::type::value_type;
620  return std::numeric_limits<value_type>::quiet_NaN();
621  }
622  }
623  };
624 
626  {
627  protected:
628  template <typename Performance, typename Properties>
630  const std::string & entity_ref, const Performance & performance,
631  const Properties & properties)
632  {
633  core->activateOutOfRangeJob(
634  entity_ref, -performance.max_speed, +performance.max_speed, -performance.max_deceleration,
635  +performance.max_acceleration, properties.template get<Double>("minJerk", Double::lowest()),
636  properties.template get<Double>("maxJerk", Double::max()));
637  }
638 
639  template <typename... Ts>
640  static auto asFieldOperatorApplication(Ts &&... xs) -> decltype(auto)
641  {
642  return core->asFieldOperatorApplication(std::forward<decltype(xs)>(xs)...);
643  }
644 
645  static auto activateNonUserDefinedControllers() -> decltype(auto)
646  {
647  return core->startNpcLogic();
648  }
649 
650  template <typename... Ts>
651  static auto evaluateCurrentState(Ts &&... xs) -> decltype(auto)
652  {
653  return core->getCurrentAction(std::forward<decltype(xs)>(xs)...);
654  }
655 
656  template <typename EntityRef, typename OSCLanePosition>
658  const EntityRef & entity_ref, const OSCLanePosition & osc_lane_position)
659  {
660  if (const auto entity = core->getEntity(entity_ref)) {
661  const auto from_map_pose = entity->getMapPose();
662  const auto to_map_pose = static_cast<NativeWorldPosition>(osc_lane_position);
663  if (
664  const auto relative_pose =
665  traffic_simulator::pose::relativePose(from_map_pose, to_map_pose)) {
666  return static_cast<Double>(std::abs(
667  math::geometry::convertQuaternionToEulerAngle(relative_pose.value().orientation).z));
668  }
669  }
670  return Double::nan();
671  }
672 
673  template <typename EntityRef>
674  static auto evaluateRelativeHeading(const EntityRef & entity_ref)
675  {
676  if (const auto entity = core->getEntity(entity_ref)) {
677  if (const auto canonicalized_lanelet_pose = entity->getCanonicalizedLaneletPose()) {
678  return static_cast<Double>(std::abs(
679  static_cast<traffic_simulator::LaneletPose>(canonicalized_lanelet_pose.value()).rpy.z));
680  }
681  }
682  return Double::nan();
683  }
684 
685  template <typename... Ts>
686  static auto sendCooperateCommand(Ts &&... xs) -> decltype(auto)
687  {
688  return asFieldOperatorApplication(core->getEgoName())
689  .sendCooperateCommand(std::forward<decltype(xs)>(xs)...);
690  }
691 
692  // TrafficLights - Conventional and V2I
693  template <typename... Ts>
694  static auto setConventionalTrafficLightsState(Ts &&... xs) -> decltype(auto)
695  {
696  return core->getConventionalTrafficLights()->setTrafficLightsState(
697  std::forward<decltype(xs)>(xs)...);
698  }
699 
700  template <typename... Ts>
701  static auto setConventionalTrafficLightConfidence(Ts &&... xs) -> decltype(auto)
702  {
703  return core->getConventionalTrafficLights()->setTrafficLightsConfidence(
704  std::forward<decltype(xs)>(xs)...);
705  }
706 
707  template <typename... Ts>
708  static auto getConventionalTrafficLightsComposedState(Ts &&... xs) -> decltype(auto)
709  {
710  return core->getConventionalTrafficLights()->getTrafficLightsComposedState(
711  std::forward<decltype(xs)>(xs)...);
712  }
713 
714  template <typename... Ts>
715  static auto compareConventionalTrafficLightsState(Ts &&... xs) -> decltype(auto)
716  {
717  return core->getConventionalTrafficLights()->compareTrafficLightsState(
718  std::forward<decltype(xs)>(xs)...);
719  }
720 
721  template <typename... Ts>
722  static auto resetConventionalTrafficLightPublishRate(Ts &&... xs) -> decltype(auto)
723  {
724  return core->getConventionalTrafficLights()->resetUpdate(std::forward<decltype(xs)>(xs)...);
725  }
726 
727  template <typename... Ts>
728  static auto setV2ITrafficLightsState(Ts &&... xs) -> decltype(auto)
729  {
730  return core->getV2ITrafficLights()->setTrafficLightsState(std::forward<decltype(xs)>(xs)...);
731  }
732 
733  template <typename... Ts>
734  static auto resetV2ITrafficLightPublishRate(Ts &&... xs) -> decltype(auto)
735  {
736  return core->getV2ITrafficLights()->resetUpdate(std::forward<decltype(xs)>(xs)...);
737  }
738  };
739 };
740 } // namespace openscenario_interpreter
741 
742 #endif // OPENSCENARIO_INTERPRETER__SIMULATOR_CORE_HPP_
static auto applyWalkStraightAction(Ts &&... xs)
Definition: simulator_core.hpp:521
static auto applyFollowTrajectoryAction(Ts &&... xs)
Definition: simulator_core.hpp:497
static auto applySpeedAction(Ts &&... xs)
Definition: simulator_core.hpp:509
static auto applyAcquirePositionAction(const std::string &entity_ref, Ts &&... xs)
Definition: simulator_core.hpp:294
static auto applyAssignRouteAction(const std::string &entity_ref, Ts &&... xs)
Definition: simulator_core.hpp:484
static auto applyAssignControllerAction(const std::string &entity_ref, Controller &&controller) -> void
Definition: simulator_core.hpp:342
static auto applyProfileAction(const EntityRef &entity_ref, const DynamicConstraints &dynamic_constraints) -> void
Definition: simulator_core.hpp:307
static auto applyTeleportAction(Ts &&... xs)
Definition: simulator_core.hpp:515
static auto applyDeleteEntityAction(Ts &&... xs)
Definition: simulator_core.hpp:491
static auto applyLaneChangeAction(Ts &&... xs)
Definition: simulator_core.hpp:503
static auto applyAddEntityAction(Ts &&... xs)
Definition: simulator_core.hpp:301
static auto evaluateTimeHeadway(Ts &&... xs)
Definition: simulator_core.hpp:614
static auto evaluateCollisionCondition(Ts &&... xs) -> bool
Definition: simulator_core.hpp:538
static auto evaluateSimulationTime(Ts &&... xs) -> double
Definition: simulator_core.hpp:583
static auto evaluateBoundingBoxEuclideanDistance(const std::string &from_entity_name, const std::string &to_entity_name)
Definition: simulator_core.hpp:543
static auto evaluateRelativeSpeed(const Entity &from, const Entity &to) -> Eigen::Vector3d
Definition: simulator_core.hpp:560
static auto evaluateStandStill(Ts &&... xs)
Definition: simulator_core.hpp:608
static auto evaluateSpeed(Ts &&... xs)
Definition: simulator_core.hpp:593
static auto evaluateAcceleration(Ts &&... xs)
Definition: simulator_core.hpp:532
static auto makeNativeRelativeWorldPosition(const std::string &from_entity_name, const std::string &to_entity_name)
Definition: simulator_core.hpp:108
static auto makeNativeBoundingBoxRelativeWorldPosition(const std::string &from_entity_name, const std::string &to_entity_name)
Definition: simulator_core.hpp:236
static auto makeNativeRelativeLanePosition(const std::string &from_entity_name, const NativeLanePosition &to_lanelet_pose, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined) -> traffic_simulator::LaneletPose
Definition: simulator_core.hpp:162
static auto makeNativeBoundingBoxRelativeLanePosition(const std::string &from_entity_name, const std::string &to_entity_name, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined)
Definition: simulator_core.hpp:188
static auto makeNativeBoundingBoxRelativeLanePosition(const NativeLanePosition &from_lanelet_pose, const traffic_simulator_msgs::msg::BoundingBox &from_bounding_box, const NativeLanePosition &to_lanelet_pose, const traffic_simulator_msgs::msg::BoundingBox &to_bounding_box, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined) -> traffic_simulator::LaneletPose
Definition: simulator_core.hpp:220
static auto convert(const NativeLanePosition &native_lane_position) -> NativeWorldPosition
Definition: simulator_core.hpp:103
static auto convert(const NativeWorldPosition &pose) -> NativeLanePosition
Definition: simulator_core.hpp:81
static auto evaluateLateralRelativeLanes(const std::string &from_entity_name, const std::string &to_entity_name, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined) -> int
Definition: simulator_core.hpp:266
static auto makeNativeRelativeLanePosition(const NativeLanePosition &from_lanelet_pose, const NativeLanePosition &to_lanelet_pose, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined) -> traffic_simulator::LaneletPose
Definition: simulator_core.hpp:176
static auto makeNativeBoundingBoxRelativeWorldPosition(const std::string &from_entity_name, const NativeWorldPosition &to_map_pose)
Definition: simulator_core.hpp:252
static auto makeNativeRelativeLanePosition(const std::string &from_entity_name, const std::string &to_entity_name, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined) -> traffic_simulator::LaneletPose
Definition: simulator_core.hpp:148
static auto canonicalize(const traffic_simulator::LaneletPose &non_canonicalized) -> NativeLanePosition
Definition: simulator_core.hpp:74
static auto makeNativeRelativeWorldPosition(const std::string &from_entity_name, const NativeWorldPosition &to_map_pose)
Definition: simulator_core.hpp:122
static auto makeNativeRelativeWorldPosition(const NativeWorldPosition &from_map_pose, const std::string &to_entity_name)
Definition: simulator_core.hpp:135
static auto makeNativeBoundingBoxRelativeLanePosition(const std::string &from_entity_name, const NativeLanePosition &to_lanelet_pose, const RoutingAlgorithm::value_type routing_algorithm=RoutingAlgorithm::undefined)
Definition: simulator_core.hpp:206
static auto evaluateCurrentState(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:651
static auto evaluateRelativeHeading(const EntityRef &entity_ref)
Definition: simulator_core.hpp:674
static auto setV2ITrafficLightsState(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:728
static auto resetV2ITrafficLightPublishRate(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:734
static auto setConventionalTrafficLightsState(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:694
static auto compareConventionalTrafficLightsState(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:715
static auto resetConventionalTrafficLightPublishRate(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:722
static auto evaluateRelativeHeading(const EntityRef &entity_ref, const OSCLanePosition &osc_lane_position)
Definition: simulator_core.hpp:657
static auto getConventionalTrafficLightsComposedState(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:708
static auto sendCooperateCommand(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:686
static auto activatePerformanceAssertion(const std::string &entity_ref, const Performance &performance, const Properties &properties)
Definition: simulator_core.hpp:629
static auto asFieldOperatorApplication(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:640
static auto setConventionalTrafficLightConfidence(Ts &&... xs) -> decltype(auto)
Definition: simulator_core.hpp:701
static auto activateNonUserDefinedControllers() -> decltype(auto)
Definition: simulator_core.hpp:645
Definition: simulator_core.hpp:42
static auto deactivate() -> void
Definition: simulator_core.hpp:60
static auto active()
Definition: simulator_core.hpp:58
static auto activate(const Node &node, const traffic_simulator::Configuration &configuration, Ts &&... xs) -> void
Definition: simulator_core.hpp:47
static auto update() -> void
Definition: simulator_core.hpp:69
Definition: lanelet_pose.hpp:27
auto getRotationMatrix(T quat) -> Eigen::Matrix3d
Definition: get_rotation_matrix.hpp:33
auto convertQuaternionToEulerAngle(const T &q)
Definition: quaternion_to_euler.hpp:30
Definition: hypot.hpp:22
traffic_simulator::CanonicalizedLaneletPose NativeLanePosition
Definition: simulator_core.hpp:37
geometry_msgs::msg::Pose NativeWorldPosition
Definition: simulator_core.hpp:33
traffic_simulator::LaneletPose NativeRelativeLanePosition
Definition: simulator_core.hpp:39
NativeWorldPosition NativeRelativeWorldPosition
Definition: simulator_core.hpp:35
auto distance(const geometry_msgs::Pose &pose1, const geometry_msgs::Pose &pose2)
Definition: detection_sensor.cpp:36
auto countLaneChanges(const CanonicalizedLaneletPose &from, const CanonicalizedLaneletPose &to, const traffic_simulator::RoutingConfiguration &routing_configuration, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils_ptr) -> std::optional< std::pair< int, int >>
Definition: distance.cpp:48
auto boundingBoxDistance(const geometry_msgs::msg::Pose &from, const traffic_simulator_msgs::msg::BoundingBox &from_bounding_box, const geometry_msgs::msg::Pose &to, const traffic_simulator_msgs::msg::BoundingBox &to_bounding_box) -> std::optional< double >
Definition: distance.cpp:133
auto quietNaNPose() -> geometry_msgs::msg::Pose
Definition: pose.cpp:25
auto quietNaNLaneletPose() -> LaneletPose
Definition: pose.cpp:35
auto relativeLaneletPose(const CanonicalizedLaneletPose &from, const CanonicalizedLaneletPose &to, const traffic_simulator::RoutingConfiguration &routing_configuration, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils_ptr) -> LaneletPose
Definition: pose.cpp:182
auto boundingBoxRelativePose(const geometry_msgs::msg::Pose &from, const traffic_simulator_msgs::msg::BoundingBox &from_bounding_box, const geometry_msgs::msg::Pose &to, const traffic_simulator_msgs::msg::BoundingBox &to_bounding_box) -> std::optional< geometry_msgs::msg::Pose >
Definition: pose.cpp:162
auto relativePose(const geometry_msgs::msg::Pose &from, const geometry_msgs::msg::Pose &to) -> std::optional< geometry_msgs::msg::Pose >
Definition: pose.cpp:140
auto boundingBoxRelativeLaneletPose(const CanonicalizedLaneletPose &from, const traffic_simulator_msgs::msg::BoundingBox &from_bounding_box, const CanonicalizedLaneletPose &to, const traffic_simulator_msgs::msg::BoundingBox &to_bounding_box, const traffic_simulator::RoutingConfiguration &routing_configuration, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils_ptr) -> LaneletPose
Definition: pose.cpp:207
auto toCanonicalizedLaneletPose(const geometry_msgs::msg::Pose &map_pose, const bool include_crosswalk, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils_ptr) -> std::optional< CanonicalizedLaneletPose >
Definition: pose.cpp:77
auto toMapPose(const CanonicalizedLaneletPose &lanelet_pose) -> geometry_msgs::msg::Pose
Definition: pose.cpp:63
traffic_simulator_msgs::msg::LaneletPose LaneletPose
Definition: lanelet_pose.hpp:22
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: exception.hpp:27
Definition: controller.hpp:46
Definition: double.hpp:25
Definition: dynamic_constraints.hpp:44
Definition: entity_ref.hpp:35
Definition: entity.hpp:46
Definition: performance.hpp:39
const Double max_deceleration
Definition: performance.hpp:44
const Double max_acceleration
Definition: performance.hpp:40
const Double max_speed
Definition: performance.hpp:48
Definition: properties.hpp:42
Definition: configuration.hpp:30
Definition: routing_configuration.hpp:24
bool allow_lane_change
Definition: routing_configuration.hpp:25
traffic_simulator::lanelet_pose::CanonicalizedLaneletPose CanonicalizedLaneletPose
Definition: test_lanelet_pose.cpp:21