scenario_simulator_v2 C++ API
traffic_signal_controller.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__SYNTAX__TRAFFIC_SIGNAL_CONTROLLER_HPP_
16 #define OPENSCENARIO_INTERPRETER__SYNTAX__TRAFFIC_SIGNAL_CONTROLLER_HPP_
17 
24 #include <optional>
25 #include <pugixml.hpp>
26 
28 {
29 inline namespace syntax
30 {
31 /* ---- TrafficSignalController ------------------------------------------------
32  *
33  * <xsd:complexType name="TrafficSignalController">
34  * <xsd:sequence>
35  * <xsd:element name="Phase" minOccurs="0" maxOccurs="unbounded" type="Phase"/>
36  * </xsd:sequence>
37  * <xsd:attribute name="name" type="String" use="required"/>
38  * <xsd:attribute name="delay" type="Double" use="optional"/>
39  * <xsd:attribute name="reference" type="String" use="optional"/>
40  * </xsd:complexType>
41  *
42  * -------------------------------------------------------------------------- */
45 {
46  // ID of the traffic signal controller in the road network.
47  const String name;
48 
49  /*
50  The delay to the controller in the reference property. A controller
51  having a delay to another one means that its first phase virtually starts
52  delaytime seconds after the start of the reference's first phase. This
53  can be used to define a progressive signal system, but only makes sense,
54  if the total times of all connected controllers are the same. If delay is
55  set, reference is required. Unit: s; Range: [0..inf[.
56  */
57  const Double delay;
58 
59  /*
60  A reference (ID) to the connected controller in the road network. If
61  reference is set, a delay is required.
62  */
64 
65  // Phases of a TrafficSignalController.
66  std::list<Phase> phases;
67 
68 private:
69  CircularIterator<std::list<Phase>> current_phase;
70 
71  std::optional<double> change_to_begin_time;
72 
73  double current_phase_started_at;
74 
75  std::vector<std::shared_ptr<TrafficSignalController>> observers;
76 
78 
79  friend struct TrafficSignals;
80 
81 public:
82  explicit TrafficSignalController() = delete;
83 
85 
87 
88  explicit TrafficSignalController(const pugi::xml_node &, Scope &);
89 
90  auto changePhaseTo(const String &) -> Object;
91 
92  auto changePhaseTo(std::list<Phase>::iterator) -> Object;
93 
94  auto currentPhaseExceeded() const -> bool;
95 
96  auto currentPhaseName() const -> const String &;
97 
98  auto currentPhaseSince() const -> double;
99 
100  auto cycleTime() const -> double;
101 
102  auto evaluate() -> Object;
103 
104  auto notifyBegin() -> void;
105 
106  auto shouldChangePhaseToBegin() -> bool;
107 
108  auto updatePredictions() -> void;
109 };
110 } // namespace syntax
111 } // namespace openscenario_interpreter
112 
113 #endif // OPENSCENARIO_INTERPRETER__SYNTAX__TRAFFIC_SIGNAL_CONTROLLER_HPP_
Definition: scope.hpp:158
Definition: circular_iterator.hpp:27
Definition: traffic_signals.hpp:37
std::string String
Definition: string.hpp:24
Definition: hypot.hpp:22
Pointer< Expression > Object
Definition: object.hpp:26
Definition: traffic_signal_controller_action.hpp:38
Definition: traffic_signal_controller.hpp:45
auto shouldChangePhaseToBegin() -> bool
Definition: traffic_signal_controller.cpp:123
std::list< Phase > phases
Definition: traffic_signal_controller.hpp:66
auto changePhaseTo(const String &) -> Object
Definition: traffic_signal_controller.cpp:49
auto currentPhaseName() const -> const String &
Definition: traffic_signal_controller.cpp:90
const String reference
Definition: traffic_signal_controller.hpp:63
auto cycleTime() const -> double
Definition: traffic_signal_controller.cpp:100
const String name
Definition: traffic_signal_controller.hpp:47
auto notifyBegin() -> void
Definition: traffic_signal_controller.cpp:118
const Double delay
Definition: traffic_signal_controller.hpp:57
auto updatePredictions() -> void
Definition: traffic_signal_controller.cpp:136
auto currentPhaseSince() const -> double
Definition: traffic_signal_controller.cpp:95
auto evaluate() -> Object
Definition: traffic_signal_controller.cpp:107
TrafficSignalController(const TrafficSignalController &)=delete
auto currentPhaseExceeded() const -> bool
Definition: traffic_signal_controller.cpp:84
TrafficSignalController(TrafficSignalController &&)=delete