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  * -------------------------------------------------------------------------- */
44 {
45  // ID of the traffic signal controller in the road network.
46  const String name;
47 
48  /*
49  The delay to the controller in the reference property. A controller
50  having a delay to another one means that its first phase virtually starts
51  delaytime seconds after the start of the reference's first phase. This
52  can be used to define a progressive signal system, but only makes sense,
53  if the total times of all connected controllers are the same. If delay is
54  set, reference is required. Unit: s; Range: [0..inf[.
55  */
56  const Double delay;
57 
58  /*
59  A reference (ID) to the connected controller in the road network. If
60  reference is set, a delay is required.
61  */
63 
64  // Phases of a TrafficSignalController.
65  std::list<Phase> phases;
66 
67 private:
68  CircularIterator<std::list<Phase>> current_phase;
69 
70  std::optional<double> change_to_begin_time;
71 
72  double current_phase_started_at;
73 
74  std::vector<std::shared_ptr<TrafficSignalController>> observers;
75 
77 
78  friend struct TrafficSignals;
79 
80 public:
81  explicit TrafficSignalController() = delete;
82 
84 
86 
87  explicit TrafficSignalController(const pugi::xml_node &, Scope &);
88 
89  auto changePhaseTo(const String &) -> Object;
90 
91  auto changePhaseTo(std::list<Phase>::iterator) -> Object;
92 
93  auto currentPhaseExceeded() const -> bool;
94 
95  auto currentPhaseName() const -> const String &;
96 
97  auto currentPhaseSince() const -> double;
98 
99  auto cycleTime() const -> double;
100 
101  auto evaluate() -> Object;
102 
103  auto notifyBegin() -> void;
104 
105  auto shouldChangePhaseToBegin() -> bool;
106 };
107 } // namespace syntax
108 } // namespace openscenario_interpreter
109 
110 #endif // OPENSCENARIO_INTERPRETER__SYNTAX__TRAFFIC_SIGNAL_CONTROLLER_HPP_
Definition: scope.hpp:154
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:44
auto shouldChangePhaseToBegin() -> bool
Definition: traffic_signal_controller.cpp:116
std::list< Phase > phases
Definition: traffic_signal_controller.hpp:65
auto changePhaseTo(const String &) -> Object
Definition: traffic_signal_controller.cpp:49
auto currentPhaseName() const -> const String &
Definition: traffic_signal_controller.cpp:83
const String reference
Definition: traffic_signal_controller.hpp:62
auto cycleTime() const -> double
Definition: traffic_signal_controller.cpp:93
const String name
Definition: traffic_signal_controller.hpp:46
auto notifyBegin() -> void
Definition: traffic_signal_controller.cpp:111
const Double delay
Definition: traffic_signal_controller.hpp:56
auto currentPhaseSince() const -> double
Definition: traffic_signal_controller.cpp:88
auto evaluate() -> Object
Definition: traffic_signal_controller.cpp:100
TrafficSignalController(const TrafficSignalController &)=delete
auto currentPhaseExceeded() const -> bool
Definition: traffic_signal_controller.cpp:77
TrafficSignalController(TrafficSignalController &&)=delete