Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file MSRailCrossing.h
15 : /// @author Jakob Erdmann
16 : /// @date Dez 2015
17 : ///
18 : // A rail signal logic
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include "MSSimpleTrafficLightLogic.h"
24 : #include "MSPhaseDefinition.h"
25 : #include "MSTLLogicControl.h"
26 :
27 :
28 :
29 : // ===========================================================================
30 : // class definitions
31 : // ===========================================================================
32 : /**
33 : * @class MSRailCrossing
34 : * @brief A signal for rails
35 : */
36 : class MSRailCrossing : public MSSimpleTrafficLightLogic {
37 : public:
38 : /** @brief Constructor
39 : * @param[in] tlcontrol The tls control responsible for this tls
40 : * @param[in] id This tls' id
41 : * @param[in] programID This tls' sub-id (program id)
42 : * @param[in] parameters This tls' parameters
43 : */
44 : MSRailCrossing(MSTLLogicControl& tlcontrol,
45 : const std::string& id, const std::string& programID, SUMOTime delay,
46 : const Parameterised::Map& parameters);
47 :
48 : /// @brief Destructor
49 : ~MSRailCrossing();
50 :
51 :
52 : /** @brief Initialises the rail signal with information about adjacent rail signals
53 : * @param[in] nb The detector builder
54 : * @exception ProcessError If something fails on initialisation
55 : */
56 : void init(NLDetectorBuilder& nb);
57 :
58 : /**@brief Sets a parameter and updates internal constants */
59 : void setParameter(const std::string& key, const std::string& value);
60 :
61 : /// @name Handling of controlled links
62 : /// @{
63 :
64 : /** @brief Adds a link on building
65 : * @param[in] link The controlled link
66 : * @param[in] lane The lane this link starts at
67 : * @param[in] pos The link's index (signal group) within this program
68 : */
69 : void addLink(MSLink* link, MSLane* lane, int pos);
70 :
71 : /** @brief Applies information about controlled links and lanes from the given logic
72 : * @param[in] logic The logic to use the information about controlled links/lanes from
73 : * @see MSTrafficLightLogic::adaptLinkInformationFrom
74 : */
75 : void adaptLinkInformationFrom(const MSTrafficLightLogic& logic);
76 : /// @}
77 :
78 :
79 : /// @name Switching and setting current rows
80 : /// @{
81 :
82 :
83 : /// @brief updates the current phase of the signal
84 : SUMOTime updateCurrentPhase();
85 :
86 : /** @brief Switches to the next phase
87 : * @return The time of the next switch (always the next step)
88 : * @see MSTrafficLightLogic::trySwitch
89 : */
90 : SUMOTime trySwitch();
91 :
92 : /// @}
93 :
94 :
95 : /// @name Conversion between time and phase
96 : /// @{
97 :
98 : /** @brief Returns the index of the logic at the given simulation step
99 : * @return The (estimated) index of the tls at the given simulation time step (here, always zero will be returned)
100 : * @see MSTrafficLightLogic::getPhaseIndexAtTime
101 : */
102 : SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const;
103 :
104 :
105 : /** @brief Returns the position (start of a phase during a cycle) from of a given step
106 : * @param[in] index The index of the phase to return the begin of
107 : * @return The begin time of the phase (here, always zero will be returned)
108 : * @see MSTrafficLightLogic::getOffsetFromIndex
109 : */
110 : SUMOTime getOffsetFromIndex(int index) const;
111 :
112 :
113 : /** @brief Returns the step (the phasenumber) of a given position of the cycle
114 : * @param[in] offset The offset (time) for which the according phase shall be returned
115 : * @return The according phase (here, always zero will be returned)
116 : * @see MSTrafficLightLogic::getIndexFromOffset
117 : */
118 : int getIndexFromOffset(SUMOTime offset) const;
119 : /// @}
120 :
121 :
122 : /// @name Changing phases and phase durations
123 : /// @{
124 :
125 : /** @brief Changes the current phase and her duration
126 : * @param[in] tlcontrol The responsible traffic lights control
127 : * @param[in] simStep The current simulation step
128 : * @param[in] step Index of the phase to use
129 : * @param[in] stepDuration The left duration of the phase
130 : * @see MSTrafficLightLogic::changeStepAndDuration
131 : */
132 0 : void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) {
133 : UNUSED_PARAMETER(tlcontrol);
134 : UNUSED_PARAMETER(simStep);
135 : UNUSED_PARAMETER(step);
136 : UNUSED_PARAMETER(stepDuration);
137 0 : }
138 : /// @}
139 :
140 : protected:
141 :
142 : /// The incoming rail links
143 : std::vector<MSLink*> myIncomingRailLinks;
144 :
145 : protected:
146 :
147 :
148 : /// @brief minimum time gap between closing the crossing (end of yellow time) and train passing the crossing
149 : SUMOTime myTimeGap;
150 :
151 : /// @brief minimum distance between the train and the crossing which triggers closing (-1 means time only)
152 : double mySpaceGap;
153 :
154 : /// @brief minimum green time
155 : SUMOTime myMinGreenTime;
156 :
157 : /// @brief red time after the train has left
158 : SUMOTime myOpeningDelay;
159 :
160 : /// @brief red-yellow time after the delay while opening
161 : SUMOTime myOpeningTime;
162 :
163 : /// @brief yellow time
164 : SUMOTime myYellowTime;
165 :
166 : };
|