TrafficLight.java

  1. package org.opentrafficsim.road.gtu.lane.object;

  2. import org.djunits.unit.LengthUnit;
  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.opentrafficsim.core.geometry.OTSGeometryException;
  5. import org.opentrafficsim.core.geometry.OTSLine3D;
  6. import org.opentrafficsim.road.network.lane.CrossSectionElement;

  7. /**
  8.  * <p>
  9.  * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  10.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  11.  * </p>
  12.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  13.  * initial version Nov 26, 2015 <br>
  14.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  15.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  16.  */
  17. public class TrafficLight extends AbstractTrafficLightNew
  18. {
  19.     /** The GTU colors for a normal traffic light. */
  20.     public enum TrafficLightColor
  21.     {
  22.         /** GTU needs to stop. */
  23.         RED,

  24.         /** GTU is allowed to continue if it cannot stop anymore. */
  25.         YELLOW,

  26.         /** GTU is allowed to drive. */
  27.         GREEN,

  28.         /** Traffic light is not working. */
  29.         BLACK
  30.     };

  31.     /** The color of the traffic light. */
  32.     private TrafficLightColor trafficLightColor;

  33.     /**
  34.      * @param geometry the geometry of the object
  35.      * @param height the height of the object
  36.      * @param initialColor the initial color of the traffic light
  37.      */
  38.     public TrafficLight(final OTSLine3D geometry, final Length height, final TrafficLightColor initialColor)
  39.     {
  40.         super(geometry, height);
  41.         this.trafficLightColor = initialColor;
  42.     }

  43.     /**
  44.      * @return the trafficLightColor
  45.      */
  46.     public final TrafficLightColor getTrafficLightColor()
  47.     {
  48.         return this.trafficLightColor;
  49.     }

  50.     /**
  51.      * @param trafficLightColor set the trafficLightColor
  52.      */
  53.     public final void setTrafficLightColor(final TrafficLightColor trafficLightColor)
  54.     {
  55.         this.trafficLightColor = trafficLightColor;
  56.     }

  57.     /**
  58.      * @param cse the cross section element, e.g. lane, where the traffic light is located
  59.      * @param position the relative position on the design line of the link for this traffic light
  60.      * @param initialColor the initial color of the traffic light
  61.      * @return a new CrossSectionElementBlock on the right position on the cse
  62.      * @throws OTSGeometryException in case the position is outside the CSE
  63.      */
  64.     public static TrafficLight createTrafficLight(final CrossSectionElement cse, final Length position,
  65.         final TrafficLightColor initialColor) throws OTSGeometryException
  66.     {
  67.         // return new TrafficLight(AbstractCSEObject.createRectangleOnCSE(cse, position, new Length(0.5,
  68.         // LengthUnit.METER), cse.getWidth(position).multiplyBy(0.8), new Length(0.5, LengthUnit.METER)), new
  69.         // Length(0.5, LengthUnit.METER),
  70.         // initialColor);
  71.         return new TrafficLight(AbstractCSEObject.createRectangleOnCSE(cse, position, new Length(0.5,
  72.             LengthUnit.METER), cse.getWidth(position).multiplyBy(0.8), new Length(0.5, LengthUnit.METER)),
  73.             new Length(0.5, LengthUnit.METER), initialColor);
  74.     }
  75. }