scenario_simulator_v2 C++ API
traffic_light.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__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_HPP_
16 #define TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_HPP_
17 
18 #include <lanelet2_core/geometry/Lanelet.h>
19 #include <simulation_interface/simulation_api_schema.pb.h>
20 
21 #include <color_names/color_names.hpp>
22 #include <cstdint>
23 #include <geometry_msgs/msg/point.hpp>
24 #include <iostream>
25 #include <limits>
26 #include <memory>
27 #include <optional>
28 #include <regex>
30 #include <set>
31 #include <stdexcept>
32 #include <traffic_simulator_msgs/msg/traffic_light_array_v1.hpp>
33 #include <tuple>
34 #include <type_traits>
35 #include <unordered_map>
36 #include <utility>
37 #include <vector>
38 #include <visualization_msgs/msg/marker.hpp>
39 
40 namespace traffic_simulator
41 {
43 {
44  struct Color
45  {
46  enum Value : std::uint8_t {
49  red,
52  } value;
53 
54  // clang-format off
55  static_assert(static_cast<std::uint8_t>(green ) == 0b0000'0000);
56  static_assert(static_cast<std::uint8_t>(yellow ) == 0b0000'0001);
57  static_assert(static_cast<std::uint8_t>(red ) == 0b0000'0010);
58  static_assert(static_cast<std::uint8_t>(white ) == 0b0000'0011);
59  static_assert(static_cast<std::uint8_t>(unknown) == 0b0000'0100);
60  // clang-format on
61 
62  constexpr Color(const Value value = green) : value(value) {}
63 
64  Color(const std::string & name) : value(make(name)) {}
65 
66  static inline const std::unordered_map<std::string, Value> table{
67  std::make_pair("amber", yellow),
68  std::make_pair("green", green),
69  std::make_pair("red", red),
70  std::make_pair("white", white),
71  std::make_pair("yellow", yellow),
72  std::make_pair("unknown", unknown),
73 
74  // BACKWARD COMPATIBILITY
75  std::make_pair("Green", green),
76  std::make_pair("Red", red),
77  std::make_pair("Yellow", yellow),
78  };
79 
80  static auto make(const std::string & name) -> Color;
81 
82  constexpr auto is(const Color given) const { return value == given; }
83 
84  constexpr operator Value() const noexcept { return value; }
85 
86  friend auto operator>>(std::istream & is, Color & color) -> std::istream &;
87 
88  friend auto operator<<(std::ostream & os, const Color & color) -> std::ostream &;
89  };
90 
91  struct Status
92  {
93  enum Value : std::uint8_t {
98  } value;
99 
100  // clang-format off
101  static_assert(static_cast<std::uint8_t>(solid_on ) == 0b0000'0000);
102  static_assert(static_cast<std::uint8_t>(solid_off) == 0b0000'0001);
103  static_assert(static_cast<std::uint8_t>(flashing ) == 0b0000'0010);
104  static_assert(static_cast<std::uint8_t>(unknown ) == 0b0000'0011);
105  // clang-format on
106 
107  constexpr Status(const Value value = solid_on) : value(value) {}
108 
109  Status(const std::string & name) : value(make(name)) {}
110 
111  static inline const std::unordered_map<std::string, Value> table{
112  std::make_pair("solidOn", solid_on),
113  std::make_pair("solidOff", solid_off),
114  std::make_pair("flashing", flashing),
115  std::make_pair("unknown", unknown),
116 
117  // BACKWARD COMPATIBILITY
118  std::make_pair("Blank", solid_off),
119  std::make_pair("none", solid_off),
120  };
121 
122  static auto make(const std::string & name) -> Status;
123 
124  constexpr auto is(const Value given) const { return value == given; }
125 
126  constexpr operator bool() const { return value == solid_on or value == flashing; }
127 
128  constexpr operator Value() const noexcept { return value; }
129 
130  friend auto operator>>(std::istream & is, Status & status) -> std::istream &;
131 
132  friend auto operator<<(std::ostream & os, const Status & status) -> std::ostream &;
133  };
134 
135  struct Shape
136  {
137  enum class Category : std::uint8_t {
138  circle,
139  cross,
140  arrow,
141  unknown,
142  };
143 
144  // clang-format off
145  static_assert(static_cast<std::uint8_t>(Category::circle ) == 0b0000'0000);
146  static_assert(static_cast<std::uint8_t>(Category::cross ) == 0b0000'0001);
147  static_assert(static_cast<std::uint8_t>(Category::arrow ) == 0b0000'0010);
148  static_assert(static_cast<std::uint8_t>(Category::unknown) == 0b0000'0011);
149  // clang-format on
150 
151  enum Value : std::uint16_t {
152  // clang-format off
153  circle = static_cast<std::uint8_t>(Category::circle ),
154  cross = static_cast<std::uint8_t>(Category::cross ),
155  left = (0b0000'1000 << 8) | static_cast<std::uint8_t>(Category::arrow ),
156  down = (0b0000'0100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
157  up = (0b0000'0010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
158  right = (0b0000'0001 << 8) | static_cast<std::uint8_t>(Category::arrow ),
159  lower_left = (0b0000'1100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
160  upper_left = (0b0000'1010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
161  lower_right = (0b0000'0101 << 8) | static_cast<std::uint8_t>(Category::arrow ),
162  upper_right = (0b0000'0011 << 8) | static_cast<std::uint8_t>(Category::arrow ),
163  unknown = static_cast<std::uint8_t>(Category::unknown),
164  // clang-format on
165  } value;
166 
167  // clang-format off
168  static_assert(static_cast<std::uint16_t>(circle ) == 0b0000'0000'0000'0000);
169  static_assert(static_cast<std::uint16_t>(cross ) == 0b0000'0000'0000'0001);
170  static_assert(static_cast<std::uint16_t>(left ) == 0b0000'1000'0000'0010);
171  static_assert(static_cast<std::uint16_t>(down ) == 0b0000'0100'0000'0010);
172  static_assert(static_cast<std::uint16_t>(up ) == 0b0000'0010'0000'0010);
173  static_assert(static_cast<std::uint16_t>(right ) == 0b0000'0001'0000'0010);
174  static_assert(static_cast<std::uint16_t>(lower_left ) == 0b0000'1100'0000'0010);
175  static_assert(static_cast<std::uint16_t>(upper_left ) == 0b0000'1010'0000'0010);
176  static_assert(static_cast<std::uint16_t>(lower_right) == 0b0000'0101'0000'0010);
177  static_assert(static_cast<std::uint16_t>(upper_right) == 0b0000'0011'0000'0010);
178  static_assert(static_cast<std::uint16_t>(unknown ) == 0b0000'0000'0000'0011);
179  // clang-format on
180 
181  constexpr Shape(const Value value = circle) : value(value) {}
182 
183  Shape(const std::string & name) : value(make(name)) {}
184 
185  static inline const std::unordered_map<std::string, Shape::Value> table{
186  std::make_pair("circle", Shape::circle),
187  std::make_pair("cross", Shape::cross),
188  std::make_pair("left", Shape::left),
189  std::make_pair("down", Shape::down),
190  std::make_pair("up", Shape::up),
191  std::make_pair("right", Shape::right),
192  std::make_pair("lowerLeft", Shape::lower_left),
193  std::make_pair("upperLeft", Shape::upper_left),
194  std::make_pair("lowerRight", Shape::lower_right),
195  std::make_pair("upperRight", Shape::upper_right),
196  std::make_pair("unknown", Shape::unknown),
197 
198  // BACKWARD COMPATIBILITY
199  std::make_pair("straight", Shape::up),
200  };
201 
202  static auto make(const std::string & name) -> Shape;
203 
204  constexpr auto category() const
205  {
206  return static_cast<Category>(static_cast<std::uint16_t>(value) & 0b1111'1111);
207  }
208 
209  constexpr auto is(const Value given) const { return value == given; }
210 
211  constexpr auto is(const Category given) const { return category() == given; }
212 
213  constexpr operator Value() const noexcept { return value; }
214 
215  friend auto operator>>(std::istream & is, Shape & shape) -> std::istream &;
216 
217  friend auto operator<<(std::ostream & os, const Shape & shape) -> std::ostream &;
218  };
219 
220  struct Bulb
221  {
222  using Value = std::tuple<Color, Status, Shape>;
223 
224  const Value value;
225 
226  using Hash = std::uint32_t; // (Color::Value << 8 + 16) | (Status::Value << 16) | Shape::Value
227 
228  constexpr Bulb(const Value value) : value(value) {}
229 
230  constexpr Bulb(const Color color = {}, const Status status = {}, const Shape shape = {})
231  : Bulb(std::forward_as_tuple(color, status, shape))
232  {
233  }
234 
235  Bulb(const std::string & name) : Bulb(make(name)) {}
236 
237  auto make(const std::string & s) -> Value;
238 
239  constexpr auto is(const Color color) const { return std::get<Color>(value).is(color); }
240 
241  constexpr auto is(const Status status) const { return std::get<Status>(value).is(status); }
242 
243  constexpr auto is(const Shape shape) const { return std::get<Shape>(value).is(shape); }
244 
245  constexpr auto is(const Shape::Category category) const
246  {
247  return std::get<Shape>(value).is(category);
248  }
249 
250  constexpr auto hash() const -> Hash
251  {
252  return (static_cast<Hash>(std::get<Color>(value).value) << 24) |
253  (static_cast<Hash>(std::get<Status>(value).value) << 16) |
254  static_cast<Hash>(std::get<Shape>(value).value);
255  }
256 
257  friend constexpr auto operator<(const Bulb & lhs, const Bulb & rhs) -> bool
258  {
259  return lhs.hash() < rhs.hash();
260  }
261 
262  friend auto operator<<(std::ostream & os, const Bulb & bulb) -> std::ostream &;
263 
264  explicit operator simulation_api_schema::TrafficLight() const
265  {
266  const auto color = [this]() {
267  auto color_message = simulation_api_schema::TrafficLight_Color_UNKNOWN_COLOR;
268  switch (std::get<Color>(value).value) {
269  case Color::green:
270  color_message = simulation_api_schema::TrafficLight_Color_GREEN;
271  break;
272  case Color::yellow:
273  color_message = simulation_api_schema::TrafficLight_Color_AMBER;
274  break;
275  case Color::red:
276  color_message = simulation_api_schema::TrafficLight_Color_RED;
277  break;
278  case Color::white:
279  color_message = simulation_api_schema::TrafficLight_Color_WHITE;
280  break;
281  case Color::unknown:
282  color_message = simulation_api_schema::TrafficLight_Color_UNKNOWN_COLOR;
283  break;
284  }
285  return color_message;
286  };
287 
288  const auto status = [this]() {
289  auto status_message = simulation_api_schema::TrafficLight_Status_UNKNOWN_STATUS;
290  switch (std::get<Status>(value).value) {
291  case Status::solid_on:
292  status_message = simulation_api_schema::TrafficLight_Status_SOLID_ON;
293  break;
294  case Status::solid_off:
295  status_message = simulation_api_schema::TrafficLight_Status_SOLID_OFF;
296  break;
297  case Status::flashing:
298  status_message = simulation_api_schema::TrafficLight_Status_FLASHING;
299  break;
300  case Status::unknown:
301  status_message = simulation_api_schema::TrafficLight_Status_UNKNOWN_STATUS;
302  break;
303  }
304  return status_message;
305  };
306 
307  const auto shape = [this]() {
308  auto shape_message = simulation_api_schema::TrafficLight_Shape_UNKNOWN_SHAPE;
309  switch (std::get<Shape>(value).value) {
310  case Shape::circle:
311  shape_message = simulation_api_schema::TrafficLight_Shape_CIRCLE;
312  break;
313  case Shape::cross:
314  shape_message = simulation_api_schema::TrafficLight_Shape_CROSS;
315  break;
316  case Shape::left:
317  shape_message = simulation_api_schema::TrafficLight_Shape_LEFT_ARROW;
318  break;
319  case Shape::down:
320  shape_message = simulation_api_schema::TrafficLight_Shape_DOWN_ARROW;
321  break;
322  case Shape::up:
323  shape_message = simulation_api_schema::TrafficLight_Shape_UP_ARROW;
324  break;
325  case Shape::right:
326  shape_message = simulation_api_schema::TrafficLight_Shape_RIGHT_ARROW;
327  break;
328  case Shape::lower_left:
329  shape_message = simulation_api_schema::TrafficLight_Shape_DOWN_LEFT_ARROW;
330  break;
331  case Shape::lower_right:
332  shape_message = simulation_api_schema::TrafficLight_Shape_DOWN_RIGHT_ARROW;
333  break;
334  case Shape::upper_left:
335  shape_message = simulation_api_schema::TrafficLight_Shape_UP_LEFT_ARROW;
336  break;
337  case Shape::upper_right:
338  shape_message = simulation_api_schema::TrafficLight_Shape_UP_RIGHT_ARROW;
339  break;
340  case Shape::unknown:
341  shape_message = simulation_api_schema::TrafficLight_Shape_UNKNOWN_SHAPE;
342  break;
343  }
344  return shape_message;
345  };
346 
347  simulation_api_schema::TrafficLight traffic_light_bulb_proto;
348  traffic_light_bulb_proto.set_status(status());
349  traffic_light_bulb_proto.set_shape(shape());
350  traffic_light_bulb_proto.set_color(color());
351  // NOTE: confidence will be overwritten in TrafficLight::operator simulation_api_schema::TrafficSignal()
352  traffic_light_bulb_proto.set_confidence(1.0);
353 
354  return traffic_light_bulb_proto;
355  }
356 
357  explicit operator traffic_simulator_msgs::msg::TrafficLightBulbV1() const
358  {
359  const auto color = [this] {
360  auto color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
361  switch (std::get<Color>(value).value) {
362  case Color::green:
363  color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::GREEN;
364  break;
365  case Color::yellow:
366  color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::AMBER;
367  break;
368  case Color::red:
369  color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::RED;
370  break;
371  case Color::white:
372  color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::WHITE;
373  break;
374  case Color::unknown:
375  color_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
376  break;
377  }
378  return color_message;
379  };
380 
381  const auto status = [this] {
382  auto status_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
383  switch (std::get<Status>(value).value) {
384  case Status::solid_on:
385  status_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::SOLID_ON;
386  break;
387  case Status::solid_off:
388  status_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::SOLID_OFF;
389  break;
390  case Status::flashing:
391  status_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::FLASHING;
392  break;
393  case Status::unknown:
394  status_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
395  break;
396  }
397  return status_message;
398  };
399 
400  const auto shape = [this] {
401  auto shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
402  switch (std::get<Shape>(value).value) {
403  case Shape::circle:
404  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::CIRCLE;
405  break;
406  case Shape::cross:
407  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::CROSS;
408  break;
409  case Shape::left:
410  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::LEFT_ARROW;
411  break;
412  case Shape::down:
413  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::DOWN_ARROW;
414  break;
415  case Shape::up:
416  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UP_ARROW;
417  break;
418  case Shape::right:
419  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::RIGHT_ARROW;
420  break;
421  case Shape::lower_left:
422  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::DOWN_LEFT_ARROW;
423  break;
424  case Shape::lower_right:
425  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::DOWN_RIGHT_ARROW;
426  break;
427  case Shape::upper_left:
428  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UP_LEFT_ARROW;
429  break;
430  case Shape::upper_right:
431  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UP_RIGHT_ARROW;
432  break;
433  case Shape::unknown:
434  shape_message = traffic_simulator_msgs::msg::TrafficLightBulbV1::UNKNOWN;
435  break;
436  }
437  return shape_message;
438  };
439 
440  traffic_simulator_msgs::msg::TrafficLightBulbV1 msg;
441  msg.color = color();
442  msg.status = status();
443  msg.shape = shape();
444  // NOTE: confidence will be overwritten
445  msg.confidence = 1.0;
446  // NOTE: unused data member 'enum_revision' for
447  // traffic_simulator_msgs::msg::TrafficLightBulbV1
448  return msg;
449  }
450  };
451 
452  explicit TrafficLight(const lanelet::Id);
453 
454  const lanelet::Id way_id;
455 
456  const lanelet::Ids regulatory_elements_ids;
457 
458  double confidence = 1.0;
459 
460  std::set<Bulb> bulbs;
461 
462  const std::map<Color, std::optional<geometry_msgs::msg::Point>> positions;
463 
464  auto clear() { bulbs.clear(); }
465 
466  auto contains(const Bulb & bulb) const { return bulbs.find(bulb) != std::end(bulbs); }
467 
468  auto contains(const Color & color, const Status & status, const Shape & shape) const
469  {
470  return contains(Bulb(color, status, shape));
471  }
472 
473  auto contains(const std::string & name) const { return contains(Bulb(name)); }
474 
475  template <typename Markers, typename Now>
476  auto draw(Markers & markers, const Now & now, const std::string & frame_id) const
477  {
478  auto create_bulb_marker = [&](const Color & color, const bool is_on) {
479  visualization_msgs::msg::Marker marker;
480  marker.header.stamp = now;
481  marker.header.frame_id = frame_id;
482  marker.action = visualization_msgs::msg::Marker::ADD;
483  marker.ns = "bulb";
484  marker.id = way_id << 2 | static_cast<int>(color.value);
485  marker.type = visualization_msgs::msg::Marker::SPHERE;
486  marker.pose.position = positions.at(color).value();
487  marker.pose.orientation = geometry_msgs::msg::Quaternion();
488  marker.scale.x = 0.3;
489  marker.scale.y = 0.3;
490  marker.scale.z = 0.3;
491  marker.color = color_names::makeColorMsg(boost::lexical_cast<std::string>(color));
492  marker.color.a = is_on ? 1.0 : 0.3;
493  return marker;
494  };
495 
496  std::set<Color> added_colors;
497 
498  // Place on markers for actual bulbs
499  for (const auto & bulb : bulbs) {
500  // NOTE: Status is ignored intentionally
501  if (bulb.is(Shape::Category::circle)) {
502  const auto color = std::get<Color>(bulb.value);
503  const auto position = positions.find(color);
504  if (position == positions.end() or not position->second.has_value()) {
505  continue;
506  }
507 
508  markers.push_back(create_bulb_marker(color, true));
509  added_colors.insert(color);
510  }
511  }
512 
513  // Place solidOff markers for other positions
514  for (const auto & [color, position] : positions) {
515  if (position.has_value() and added_colors.find(color) == added_colors.end()) {
516  markers.push_back(create_bulb_marker(color, false));
517  }
518  }
519  }
520 
521  template <typename... Ts>
522  auto emplace(Ts &&... xs)
523  {
524  bulbs.emplace(std::forward<decltype(xs)>(xs)...);
525  }
526 
527  auto empty() const { return bulbs.empty(); }
528 
529  auto set(const std::string & states) -> void;
530 
531  friend auto operator<<(std::ostream & os, const TrafficLight & traffic_light) -> std::ostream &;
532 
533  explicit operator simulation_api_schema::TrafficSignal() const
534  {
535  simulation_api_schema::TrafficSignal traffic_signal_proto;
536 
537  traffic_signal_proto.set_id(way_id);
538  for (const auto & relation_id : regulatory_elements_ids) {
539  traffic_signal_proto.add_relation_ids(relation_id);
540  }
541  for (const auto & bulb : bulbs) {
542  auto traffic_light_bulb_proto = static_cast<simulation_api_schema::TrafficLight>(bulb);
543  traffic_light_bulb_proto.set_confidence(confidence);
544  *traffic_signal_proto.add_traffic_light_status() = traffic_light_bulb_proto;
545  }
546  return traffic_signal_proto;
547  }
548 
549  explicit operator traffic_simulator_msgs::msg::TrafficLightV1() const
550  {
551  traffic_simulator_msgs::msg::TrafficLightV1 traffic_signal;
552  traffic_signal.lanelet_way_id = way_id;
553  for (const auto & bulb : bulbs) {
554  auto traffic_light_bulb = static_cast<traffic_simulator_msgs::msg::TrafficLightBulbV1>(bulb);
555  traffic_light_bulb.confidence = confidence;
556  traffic_signal.traffic_light_bulbs.push_back(traffic_light_bulb);
557  }
558  return traffic_signal;
559  }
560 };
561 } // namespace traffic_simulator
562 
563 #endif // TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_HPP_
Definition: api.hpp:33
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: traffic_light.hpp:221
constexpr auto is(const Shape shape) const
Definition: traffic_light.hpp:243
std::tuple< Color, Status, Shape > Value
Definition: traffic_light.hpp:222
constexpr auto hash() const -> Hash
Definition: traffic_light.hpp:250
constexpr Bulb(const Value value)
Definition: traffic_light.hpp:228
constexpr Bulb(const Color color={}, const Status status={}, const Shape shape={})
Definition: traffic_light.hpp:230
Bulb(const std::string &name)
Definition: traffic_light.hpp:235
constexpr friend auto operator<(const Bulb &lhs, const Bulb &rhs) -> bool
Definition: traffic_light.hpp:257
constexpr auto is(const Color color) const
Definition: traffic_light.hpp:239
friend auto operator<<(std::ostream &os, const Bulb &bulb) -> std::ostream &
Definition: traffic_light.cpp:161
auto make(const std::string &s) -> Value
Definition: traffic_light.cpp:135
constexpr auto is(const Shape::Category category) const
Definition: traffic_light.hpp:245
const Value value
Definition: traffic_light.hpp:224
std::uint32_t Hash
Definition: traffic_light.hpp:226
constexpr auto is(const Status status) const
Definition: traffic_light.hpp:241
Definition: traffic_light.hpp:45
Value
Definition: traffic_light.hpp:46
@ white
Definition: traffic_light.hpp:50
@ green
Definition: traffic_light.hpp:47
@ red
Definition: traffic_light.hpp:49
@ unknown
Definition: traffic_light.hpp:51
@ yellow
Definition: traffic_light.hpp:48
friend auto operator<<(std::ostream &os, const Color &color) -> std::ostream &
Definition: traffic_light.cpp:38
constexpr Color(const Value value=green)
Definition: traffic_light.hpp:62
Color(const std::string &name)
Definition: traffic_light.hpp:64
static const std::unordered_map< std::string, Value > table
Definition: traffic_light.hpp:66
enum traffic_simulator::TrafficLight::Color::Value value
friend auto operator>>(std::istream &is, Color &color) -> std::istream &
Definition: traffic_light.cpp:30
static auto make(const std::string &name) -> Color
Definition: traffic_light.cpp:21
constexpr auto is(const Color given) const
Definition: traffic_light.hpp:82
Definition: traffic_light.hpp:136
Value
Definition: traffic_light.hpp:151
@ up
Definition: traffic_light.hpp:157
@ upper_right
Definition: traffic_light.hpp:162
@ left
Definition: traffic_light.hpp:155
@ cross
Definition: traffic_light.hpp:154
@ lower_right
Definition: traffic_light.hpp:161
@ upper_left
Definition: traffic_light.hpp:160
@ lower_left
Definition: traffic_light.hpp:159
@ down
Definition: traffic_light.hpp:156
@ unknown
Definition: traffic_light.hpp:163
@ circle
Definition: traffic_light.hpp:153
@ right
Definition: traffic_light.hpp:158
constexpr auto category() const
Definition: traffic_light.hpp:204
enum traffic_simulator::TrafficLight::Shape::Value value
static auto make(const std::string &name) -> Shape
Definition: traffic_light.cpp:88
constexpr auto is(const Category given) const
Definition: traffic_light.hpp:211
friend auto operator>>(std::istream &is, Shape &shape) -> std::istream &
Definition: traffic_light.cpp:97
Category
Definition: traffic_light.hpp:137
friend auto operator<<(std::ostream &os, const Shape &shape) -> std::ostream &
Definition: traffic_light.cpp:105
constexpr auto is(const Value given) const
Definition: traffic_light.hpp:209
constexpr Shape(const Value value=circle)
Definition: traffic_light.hpp:181
static const std::unordered_map< std::string, Shape::Value > table
Definition: traffic_light.hpp:185
Shape(const std::string &name)
Definition: traffic_light.hpp:183
Definition: traffic_light.hpp:92
constexpr auto is(const Value given) const
Definition: traffic_light.hpp:124
constexpr Status(const Value value=solid_on)
Definition: traffic_light.hpp:107
static const std::unordered_map< std::string, Value > table
Definition: traffic_light.hpp:111
Status(const std::string &name)
Definition: traffic_light.hpp:109
Value
Definition: traffic_light.hpp:93
@ solid_off
Definition: traffic_light.hpp:95
@ unknown
Definition: traffic_light.hpp:97
@ solid_on
Definition: traffic_light.hpp:94
@ flashing
Definition: traffic_light.hpp:96
friend auto operator<<(std::ostream &os, const Status &status) -> std::ostream &
Definition: traffic_light.cpp:73
enum traffic_simulator::TrafficLight::Status::Value value
static auto make(const std::string &name) -> Status
Definition: traffic_light.cpp:56
friend auto operator>>(std::istream &is, Status &status) -> std::istream &
Definition: traffic_light.cpp:65
Definition: traffic_light.hpp:43
auto clear()
Definition: traffic_light.hpp:464
const lanelet::Ids regulatory_elements_ids
Definition: traffic_light.hpp:456
double confidence
Definition: traffic_light.hpp:458
const lanelet::Id way_id
Definition: traffic_light.hpp:454
auto empty() const
Definition: traffic_light.hpp:527
const std::map< Color, std::optional< geometry_msgs::msg::Point > > positions
Definition: traffic_light.hpp:462
auto contains(const Color &color, const Status &status, const Shape &shape) const
Definition: traffic_light.hpp:468
std::set< Bulb > bulbs
Definition: traffic_light.hpp:460
auto set(const std::string &states) -> void
Definition: traffic_light.cpp:180
auto contains(const std::string &name) const
Definition: traffic_light.hpp:473
auto draw(Markers &markers, const Now &now, const std::string &frame_id) const
Definition: traffic_light.hpp:476
friend auto operator<<(std::ostream &os, const TrafficLight &traffic_light) -> std::ostream &
Definition: traffic_light.cpp:198
auto contains(const Bulb &bulb) const
Definition: traffic_light.hpp:466
auto emplace(Ts &&... xs)
Definition: traffic_light.hpp:522
TrafficLight(const lanelet::Id)
Definition: traffic_light.cpp:168
traffic_simulator::TrafficLight TrafficLight
Definition: test_traffic_light.cpp:24
TrafficLight::Bulb Bulb
Definition: test_traffic_light.cpp:28