ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
trafficlight.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Stephan Lapoehn - initial implementation and API
13  ********************************************************************************/
14 #pragma once
15 
17 #include <unordered_map>
18 
19 namespace adore
20 {
21  namespace env
22  {
49  enum class TrafficLightColor
50  {
51  GREEN = 1,
52  YELLOW = 2,
53  RED = 3,
54  RED_YELLOW = 4,
55  YELLOW_FLASHING = 5,
56  UNDEFINED_COLOR = 99
57  };
58 
63  {
64  private:
65 
67 
69 
70  public:
71 
72  /*
73  * saving zones with speed advisory if supported by traffic light (e.g. using MAPEM/SPATEM)
74  * first parameter is the distance limit starting from position of limitline, second the allowed velocity e.g. [0 - ]100m : 3m/s ; 200m : 5m/s, etc.
75  */
76  std::map<float,float> distanceSpeedTuples;
77 
79  long validUntilTimestamp = 0)
80  : m_currentColor(currentcolor), m_validUntilTimestamp(validUntilTimestamp)
81  {
82  }
83 
85  {
86  return m_currentColor;
87  }
88 
90  {
91  m_currentColor = color;
92  }
93  void setValidUntilTimestamp(long timestamp)
94  {
95  m_validUntilTimestamp = timestamp;
96  }
98  {
99  return m_validUntilTimestamp;
100  }
101 
102  std::string toString()
103  {
104  switch (getCurrentColor())
105  {
107  return "RED";
109  return "RED_YELLOW";
111  return "YELLOW";
113  return "GREEN";
114  default:
115  return "UNDEFINED_COLOR";
116  }
117  }
118 
119 
120  class TrafficLight;
129  static void GenerateSpeedAdvisories(adore::env::TrafficLightStatus & state, float speedLimit = 10.0f)
130  {
131  state.distanceSpeedTuples.clear();
132 
133  float minimumSpeed = speedLimit * 0.6;
134  float timeToOther = state.getValidUntilTimestamp()/1000;
135 
136  switch(state.getCurrentColor())
137  {
139  state.distanceSpeedTuples[speedLimit * timeToOther * 0.5] = minimumSpeed;
140  state.distanceSpeedTuples[speedLimit * timeToOther * 0.6] = speedLimit * 0.7;
141  state.distanceSpeedTuples[speedLimit * timeToOther * 0.7] = speedLimit * 0.8;
142  state.distanceSpeedTuples[speedLimit * timeToOther * 0.95] = speedLimit;
143  state.distanceSpeedTuples[speedLimit * timeToOther * 5] = 50.0f;
144  break;
146  break;
148  state.distanceSpeedTuples[minimumSpeed * timeToOther] = 50.0f;
149  state.distanceSpeedTuples[speedLimit * 0.7 * timeToOther] = speedLimit * 0.7;
150  state.distanceSpeedTuples[speedLimit * 0.8 * timeToOther] = speedLimit * 0.8;
151  state.distanceSpeedTuples[speedLimit * 0.9 * timeToOther] = speedLimit * 0.9;
152  state.distanceSpeedTuples[speedLimit * 1.5 * timeToOther] = speedLimit;
153  break;
155  break;
157  break;
159  break;
160  }
161  }
162  };
163 
168  {
169  private:
170 
172 
173  public:
174 
175  /*
176  * used as signal group ID, controlling multiple lanes via one tl-controller
177  */
179 
180  /*
181  * deescribes the intersection that this traffic light is applied to
182  */
184 
186  {
188  }
189 
191  {
192  return &status_;
193  }
194 
195  virtual TrafficLightStatus const * getStatus() const
196  {
197  return &status_;
198  }
199 
200  bool operator==(const TrafficLight& other) {
201 
202  if(getCoordinate() == other.getCoordinate()
204  && movement_id_ == other.movement_id_
205  && getID() == other.getID())
206  return true;
207 
208  return false;
209  }
210 
211  };
212 
219  {
220  public:
222 
223  // all durations are specified in ms
225 
227 
229 
231 
233 
235 
237 
239 
241 
242  };
243 
244  typedef std::unordered_map<adore::env::BorderBased::Coordinate, adore::env::SimTrafficLight,adore::env::BorderBased::CoordinateHasher> SimTrafficLightMap;
245  typedef std::unordered_map<adore::env::BorderBased::Coordinate, adore::env::TrafficLight,adore::env::BorderBased::CoordinateHasher> TrafficLightMap;
246  }
247 }
Definition: trafficlight.h:219
int time_to_yellow_
Definition: trafficlight.h:238
int yellow_red_duration_
Definition: trafficlight.h:230
TrafficLightColor start_state_
Definition: trafficlight.h:232
int time_to_red_
Definition: trafficlight.h:234
int green_duration_
Definition: trafficlight.h:228
SimTrafficLight()
Definition: trafficlight.h:221
int time_to_red_yellow_
Definition: trafficlight.h:236
int time_to_green_
Definition: trafficlight.h:240
int red_duration_
Definition: trafficlight.h:221
int yellow_duration_
Definition: trafficlight.h:226
Definition: trafficcontroldevice.h:24
void setType(TCDType type)
Definition: trafficcontroldevice.h:150
BorderBased::Coordinate getCoordinate() const
Definition: trafficcontroldevice.h:175
int getID() const
Definition: trafficcontroldevice.h:146
@ TRAFFIC_LIGHT
Definition: trafficcontroldevice.h:29
Definition: trafficlight.h:63
TrafficLightColor getCurrentColor() const
Definition: trafficlight.h:84
long getValidUntilTimestamp() const
Definition: trafficlight.h:97
std::string toString()
Definition: trafficlight.h:102
TrafficLightColor m_currentColor
Definition: trafficlight.h:66
void setCurrentColor(TrafficLightColor color)
Definition: trafficlight.h:89
void setValidUntilTimestamp(long timestamp)
Definition: trafficlight.h:93
TrafficLightStatus(TrafficLightColor currentcolor=TrafficLightColor::UNDEFINED_COLOR, long validUntilTimestamp=0)
Definition: trafficlight.h:78
std::map< float, float > distanceSpeedTuples
Definition: trafficlight.h:76
static void GenerateSpeedAdvisories(adore::env::TrafficLightStatus &state, float speedLimit=10.0f)
Definition: trafficlight.h:129
long m_validUntilTimestamp
Definition: trafficlight.h:68
Definition: trafficlight.h:168
int intersection_id_
Definition: trafficlight.h:183
bool operator==(const TrafficLight &other)
Definition: trafficlight.h:200
virtual TrafficLightStatus * getStatus()
Definition: trafficlight.h:190
int movement_id_
Definition: trafficlight.h:178
virtual TrafficLightStatus const * getStatus() const
Definition: trafficlight.h:195
TrafficLight()
Definition: trafficlight.h:185
TrafficLightStatus status_
Definition: trafficlight.h:171
TrafficLightColor
Definition: trafficlight.h:50
std::unordered_map< adore::env::BorderBased::Coordinate, adore::env::TrafficLight, adore::env::BorderBased::CoordinateHasher > TrafficLightMap
Definition: trafficlight.h:245
std::unordered_map< adore::env::BorderBased::Coordinate, adore::env::SimTrafficLight, adore::env::BorderBased::CoordinateHasher > SimTrafficLightMap
Definition: trafficlight.h:244
Definition: areaofeffectconverter.h:20