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