View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.lmrs;
2   
3   import java.util.function.Supplier;
4   
5   import org.djunits.value.vdouble.scalar.Duration;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
8   import org.opentrafficsim.road.gtu.lane.perception.object.PerceivedTrafficLight;
9   import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight;
10  import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLightColor;
11  
12  /**
13   * Traffic light perceived through delayed perception channel.
14   * <p>
15   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * </p>
18   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
19   */
20  public class PerceivedTrafficLightChannel extends PerceivedTrafficLight
21  {
22  
23      /** Perception delay supplier. */
24      private final Supplier<Duration> perceptionDelay;
25  
26      /** Simulator. */
27      private final OtsSimulatorInterface simulator;
28  
29      /**
30       * Construct a new Headway information object, for a traffic light ahead of us (or behind us, although that does not seem
31       * very useful).
32       * @param trafficLight the traffic light object for further observation, can not be null.
33       * @param distance the distance to the traffic light, distance cannot be null.
34       * @param turnOnRed whether the perceiving GTU may turn on red.
35       * @param perceptionDelay perception delay supplier.
36       */
37      public PerceivedTrafficLightChannel(final TrafficLight trafficLight, final Length distance, final boolean turnOnRed,
38              final Supplier<Duration> perceptionDelay)
39      {
40          super(trafficLight, distance, turnOnRed);
41          this.perceptionDelay = perceptionDelay;
42          this.simulator = trafficLight.getSimulator();
43      }
44  
45      /**
46       * Returns the traffic light color.
47       * @return the traffic light color.
48       */
49      @Override
50      public TrafficLightColor getTrafficLightColor()
51      {
52          Duration when = this.simulator.getSimulatorTime().minus(this.perceptionDelay.get());
53          return getTrafficLight().getTrafficLightColor(when);
54      }
55  
56  }